| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class WC_Settings_Routeapp file. |
| 4 |
* |
| 5 |
* @package Routeapp\Admin |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
if ( ! class_exists( 'WC_Settings_Routeapp' ) ) : |
| 13 |
/** |
| 14 |
* Settings class |
| 15 |
* |
| 16 |
* @since 1.0.0 |
| 17 |
*/ |
| 18 |
class WC_Settings_Routeapp extends WC_Settings_Page { |
| 19 |
|
| 20 |
const PRINTIFY_SHIPPING_METHOD = 'printify_shipping'; |
| 21 |
const PRINTIFY_SHIPPING_STANDARD = 'printify_shipping_s'; |
| 22 |
const PRINTIFY_SHIPPING_EXPRESS = 'printify_shipping_e'; |
| 23 |
|
| 24 |
/** |
| 25 |
* Setup settings class |
| 26 |
* |
| 27 |
* @since 1.0 |
| 28 |
*/ |
| 29 |
public function __construct() { |
| 30 |
|
| 31 |
$this->id = 'routeapp'; |
| 32 |
$this->label = __( 'Route', 'routeapp' ); |
| 33 |
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 ); |
| 34 |
add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) ); |
| 35 |
add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) ); |
| 36 |
} |
| 37 |
|
| 38 |
public static function get_route_public_instance(){ |
| 39 |
global $routeapp_public; |
| 40 |
return $routeapp_public; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Get settings array |
| 45 |
* |
| 46 |
* @since 1.0.0 |
| 47 |
* @return array Array of settings |
| 48 |
*/ |
| 49 |
public function get_settings() { |
| 50 |
|
| 51 |
/** |
| 52 |
* Filter Plugin Settings |
| 53 |
* |
| 54 |
* @since 1.0.0 |
| 55 |
* @param array $settings Array of the plugin settings |
| 56 |
*/ |
| 57 |
$tax_classes = wc_get_product_tax_class_options(); |
| 58 |
|
| 59 |
$shipping_methods_array = []; |
| 60 |
$shipping_methods = WC()->shipping->get_shipping_methods(); |
| 61 |
foreach($shipping_methods as $shipping_method) { |
| 62 |
if($shipping_method->id === self::PRINTIFY_SHIPPING_METHOD){ |
| 63 |
$shipping_methods_array[self::PRINTIFY_SHIPPING_STANDARD] = $shipping_method->method_title . ' Standard'; |
| 64 |
$shipping_methods_array[self::PRINTIFY_SHIPPING_EXPRESS] = $shipping_method->method_title . ' Express'; |
| 65 |
continue; |
| 66 |
} |
| 67 |
$shipping_methods_array[$shipping_method->id] = $shipping_method->method_title; |
| 68 |
} |
| 69 |
|
| 70 |
$routeapp_public = self::get_route_public_instance(); |
| 71 |
$checkout_hooks = $routeapp_public->routeapp_get_checkout_hook_options(); |
| 72 |
|
| 73 |
$ownership_login = Route_Setup::get_dashboard_ownership_login_url(); |
| 74 |
$settings = apply_filters( 'routeapp_settings', array( |
| 75 |
array( |
| 76 |
'name' => __( 'Route', 'routeapp' ), |
| 77 |
'type' => 'title', |
| 78 |
'desc' => '', |
| 79 |
'id' => 'routeapp_route_insurance', |
| 80 |
), |
| 81 |
array( |
| 82 |
'name' => __( 'Public Token', 'routeapp' ), |
| 83 |
'type' => 'text', |
| 84 |
'desc' => '<p class="description">' . sprintf( |
| 85 |
/* translators: %s: Route Dashboard login URL with platformUrl (OTP callback). */ |
| 86 |
esc_html__( 'Missing tokens? %s to sign in at Route and link this store.', 'routeapp' ), |
| 87 |
'<a href="' . esc_url( $ownership_login ) . '" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Click here', 'routeapp' ) . '</a>' |
| 88 |
) . '</p>', |
| 89 |
'id' => 'routeapp_public_token', |
| 90 |
'class' => 'route-environment', |
| 91 |
), |
| 92 |
array( |
| 93 |
'name' => __( 'Secret Token', 'routeapp' ), |
| 94 |
'type' => 'text', |
| 95 |
'id' => 'routeapp_secret_token', |
| 96 |
'class' => 'route-environment', |
| 97 |
), |
| 98 |
array( |
| 99 |
'name' => __( 'Is Route Fee taxable', 'routeapp' ), |
| 100 |
'type' => 'checkbox', |
| 101 |
'desc' => __( 'When enabled, Route fee will be taxable', 'routeapp'), |
| 102 |
'id' => 'routeapp_route_fee_taxable', |
| 103 |
'default' => 'no' |
| 104 |
), |
| 105 |
array( |
| 106 |
'name' => __( 'Tax Class', 'routeapp' ), |
| 107 |
'type' => 'select', |
| 108 |
'id' => 'routeapp_taxable_class', |
| 109 |
'class' => 'route-environment', |
| 110 |
'options' => $tax_classes |
| 111 |
), |
| 112 |
array( |
| 113 |
'name' => __( 'Enable Route extra columns', 'routeapp' ), |
| 114 |
'type' => 'checkbox', |
| 115 |
'desc' => __( 'When enabled, add Route Charge and Route Protection columns to Orders page', 'routeapp'), |
| 116 |
'id' => 'routeapp_route_enable_extra_columns', |
| 117 |
'default' => 'yes' |
| 118 |
), |
| 119 |
array( |
| 120 |
'name' => __( 'Please select all Shipping Methods that are similar to "In Store Pickup"', 'routeapp' ), |
| 121 |
'type' => 'multiselect', |
| 122 |
'id' => 'routeapp_excluded_shipping_methods', |
| 123 |
'class' => 'route-environment', |
| 124 |
'options' => $shipping_methods_array |
| 125 |
), |
| 126 |
array( |
| 127 |
'name' => __( 'Please select all the order statuses that Route will use to sync orders', 'routeapp' ), |
| 128 |
'type' => 'multiselect', |
| 129 |
'id' => 'routeapp_included_order_statuses', |
| 130 |
'class' => 'route-environment', |
| 131 |
'options' => wc_get_order_statuses() |
| 132 |
), |
| 133 |
array( |
| 134 |
'name' => __( 'Please select all the order statuses that Route will use to cancel orders', 'routeapp' ), |
| 135 |
'type' => 'multiselect', |
| 136 |
'id' => 'routeapp_cancel_order_statuses', |
| 137 |
'class' => 'route-environment', |
| 138 |
'options' => wc_get_order_statuses() |
| 139 |
), |
| 140 |
array( |
| 141 |
'name' => __( 'External Tracking Provider', 'routeapp' ), |
| 142 |
'type' => 'select', |
| 143 |
'id' => 'routeapp_external_tracking_providers', |
| 144 |
'class' => 'route-environment', |
| 145 |
'desc' => __( 'Select a tracking provider used without a dedicated WooCommerce plugin', 'routeapp' ), |
| 146 |
'default' => '', |
| 147 |
'options' => array( |
| 148 |
'' => __( 'None', 'routeapp' ), |
| 149 |
'pirate_ship' => __( 'Pirate Ship', 'routeapp' ), |
| 150 |
) |
| 151 |
), |
| 152 |
array( |
| 153 |
'name' => __( 'Include order updates widget', 'routeapp' ), |
| 154 |
'type' => 'checkbox', |
| 155 |
'desc' => __( 'When enabled, Route\'s default order updates widget will be included', 'routeapp'), |
| 156 |
'id' => 'routeapp_route_show_order_updates', |
| 157 |
'default' => 'yes' |
| 158 |
), |
| 159 |
array( |
| 160 |
'name' => __( 'Choose the place where Route Widget will appear on classic checkout page', 'routeapp' ), |
| 161 |
'type' => 'select', |
| 162 |
'desc' => "<p class='description'>You can edit the place where the route widget will appear. You can check <a href='https://docs.woocommerce.com/wc-apidocs/hook-docs.html' target='_blank'>here</a> for further explanation about how hooks works.</p>", |
| 163 |
'id' => 'routeapp_checkout_hook', |
| 164 |
'class' => 'route-environment', |
| 165 |
'options' => $checkout_hooks, |
| 166 |
'default' => 'woocommerce_checkout_before_order_review' |
| 167 |
), |
| 168 |
array( |
| 169 |
'type' => 'sectionend', |
| 170 |
'id' => 'route_insurance' |
| 171 |
), |
| 172 |
) ); |
| 173 |
|
| 174 |
|
| 175 |
/** |
| 176 |
* Filter Routeapp Settings |
| 177 |
* |
| 178 |
* @since 1.0.0 |
| 179 |
* @param array $settings Array of the plugin settings |
| 180 |
*/ |
| 181 |
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings ); |
| 182 |
|
| 183 |
} |
| 184 |
|
| 185 |
/** |
| 186 |
* Output the settings |
| 187 |
* |
| 188 |
* @since 1.0 |
| 189 |
*/ |
| 190 |
public function output() { |
| 191 |
|
| 192 |
$settings = $this->get_settings(); |
| 193 |
WC_Admin_Settings::output_fields( $settings ); |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
/** |
| 198 |
* Save settings |
| 199 |
* |
| 200 |
* @since 1.0 |
| 201 |
*/ |
| 202 |
public function save() { |
| 203 |
|
| 204 |
$settings = $this->get_settings(); |
| 205 |
WC_Admin_Settings::save_fields( $settings ); |
| 206 |
} |
| 207 |
} |
| 208 |
endif; |
| 209 |
|