PluginProbe ʕ •ᴥ•ʔ
Weight Based Shipping Table Rate for WooCommerce – Flexible Shipping / 6.10.0
Weight Based Shipping Table Rate for WooCommerce – Flexible Shipping v6.10.0
6.10.0 6.9.1 6.9.0 6.8.1 6.8.0 6.7.4 6.7.3 6.7.2 6.7.0 4.21.7 4.22.0 4.22.1 4.23.0 4.23.1 4.23.2 4.23.3 4.24.0 4.24.1 4.24.10 4.24.11 4.24.12 4.24.13 4.24.14 4.24.15 4.24.16 4.24.17 4.24.18 4.24.19 4.24.2 4.24.4 4.24.6 4.24.7 4.24.8 4.24.9 4.25.0 4.25.1 4.25.2 4.25.4 4.25.5 4.25.6 4.25.7 4.25.8 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 4.8.0 4.8.1 4.8.3 4.8.4 4.8.5 4.9.0 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.0.9 5.1.0 5.1.1 5.1.2 5.1.3 5.2.0 5.3.0 5.3.1 5.3.3 5.3.4 5.3.5 6.0.0 6.1.0 6.1.1 6.1.2 6.2.0 6.2.1 6.2.2 6.2.3 6.2.4 6.3.0 trunk 6.4.0 1.4 6.4.1 1.4.1 6.4.2 1.5 6.4.3 1.6 6.4.5 1.6.1 6.5.0 1.6.2 6.5.1 1.7 6.5.2 1.8 6.5.3 1.9 6.5.4 1.9.1 6.5.5 1.9.10 6.5.6 1.9.11 6.5.7 1.9.12 6.5.8 1.9.2 6.6.0 1.9.3 6.6.1 1.9.4 6.6.2 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0 2.0.1 2.1 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.6 3.0.7 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.10.0 3.11.0 3.11.1 3.11.2 3.11.3 3.11.4 3.12.0 3.13.0 3.14.0 3.14.1 3.14.2 3.14.3 3.14.4 3.15.0 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.2.0 3.3.1 3.3.10 3.3.11 3.3.12 3.3.13 3.3.14 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.8.0 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.9 4.0.0 4.0.1 4.0.10 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.11.0 4.11.1 4.11.2 4.11.3 4.11.4 4.11.5 4.11.6 4.11.7 4.11.8 4.11.9 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.14.0 4.14.1 4.14.2 4.15.0 4.16.0 4.16.1 4.16.2 4.17.0 4.18.0 4.18.1 4.18.2 4.18.3 4.18.4 4.18.5 4.18.6 4.19.0 4.19.1 4.2.0 4.20.0 4.20.1 4.20.2 4.20.3 4.21.0 4.21.1 4.21.2 4.21.3 4.21.4 4.21.5
flexible-shipping / src / WPDesk / FS / TableRate / ShippingMethod / CommonMethodSettings.php
flexible-shipping / src / WPDesk / FS / TableRate / ShippingMethod Last commit date
BlockEditing 3 days ago Convert 3 days ago Duplicate 3 days ago Management 3 days ago Timestamps 3 days ago Tracker 3 days ago views 3 days ago CommonMethodSettings.php 3 days ago FreeShippingCalculator.php 3 days ago FreeShippingThresholdRuleValidator.php 3 days ago MethodDescription.php 3 days ago MethodLogo.php 3 days ago MethodLogoCheckoutBlocksAssets.php 3 days ago MethodLogoSettingsField.php 3 days ago MethodSettings.php 3 days ago MethodTitle.php 3 days ago RateCalculator.php 3 days ago RateCalculatorFactory.php 3 days ago SettingsDisplayPreparer.php 3 days ago SettingsProcessor.php 3 days ago SingleMethodSettings.php 3 days ago
CommonMethodSettings.php
301 lines
1 <?php
2 /**
3 * Class CommonMethodSettings
4 *
5 * @package WPDesk\FS\TableRate\ShippingMethod
6 */
7
8 namespace WPDesk\FS\TableRate\ShippingMethod;
9
10 use FSVendor\WPDesk\FS\TableRate\CalculationMethodOptions;
11 use FSVendor\WPDesk\FS\TableRate\Settings\CartCalculationOptions;
12 use WPDesk\FS\TableRate\DefaultRulesSettings;
13 use WPDesk\FS\TableRate\RulesSettingsField;
14 use WPDesk_Flexible_Shipping;
15
16 /**
17 * Common shipping method settings.
18 */
19 class CommonMethodSettings implements MethodSettings {
20
21 const METHOD_TITLE = 'method_title';
22 const METHOD_DESCRIPTION = 'method_description';
23 const METHOD_LOGO_ID = 'method_logo_id';
24 const METHOD_RULES = 'method_rules';
25 const METHOD_FREE_SHIPPING = 'method_free_shipping';
26 const CART_CALCULATION = 'cart_calculation';
27
28 const SETTING_METHOD_CALCULATION_METHOD = 'method_calculation_method';
29 const METHOD_DEFAULT = 'method_default';
30
31 const METHOD_FREE_SHIPPING_REQUIRES_UPSELLING = 'method_free_shipping_requires_upselling';
32
33 /**
34 * @param array $method_settings .
35 * @param bool $with_integration_settings Append integration settings.
36 *
37 * @return array
38 */
39 public function get_settings_fields( array $method_settings, $with_integration_settings ) {
40 if ( ! isset( $method_settings['method_free_shipping_label'] ) ) {
41 $method_settings['method_free_shipping_label'] = __( 'Free', 'flexible-shipping' );
42 }
43
44 if ( empty( $method_settings['method_integration'] ) ) {
45 $method_settings['method_integration'] = '';
46 }
47
48 $method_free_shipping = '';
49 if ( isset( $method_settings['method_free_shipping'] ) && '' !== $method_settings['method_free_shipping'] ) {
50 $method_free_shipping = floatval( $method_settings['method_free_shipping'] );
51 }
52
53 $settings = [];
54
55 $settings['method_enabled'] = [
56 'title' => __( 'Enable/Disable', 'flexible-shipping' ),
57 'type' => 'checkbox',
58 'default' => $this->get_value_from_settings( $method_settings, 'method_enabled', 'yes' ),
59 'label' => __( 'Enable this shipment method', 'flexible-shipping' ),
60 ];
61
62 $settings[ self::METHOD_TITLE ] = [
63 'title' => __( 'Method Title', 'flexible-shipping' ),
64 'type' => 'text',
65 'description' => __( 'This controls the title which the user sees during checkout.', 'flexible-shipping' ),
66 'desc_tip' => true,
67 'default' => $this->get_value_from_settings( $method_settings, self::METHOD_TITLE, 'Flexible Shipping' ),
68 'custom_attributes' => [ 'required' => true ],
69 ];
70
71 $settings[ self::METHOD_DESCRIPTION ] = [
72 'title' => __( 'Method Description', 'flexible-shipping' ),
73 'type' => 'text',
74 'description' => __( 'This controls method description which the user sees during checkout.', 'flexible-shipping' ),
75 'desc_tip' => true,
76 'default' => $this->get_value_from_settings( $method_settings, self::METHOD_DESCRIPTION, '' ),
77 ];
78
79 $settings[ self::METHOD_LOGO_ID ] = [
80 'title' => __( 'Method Logo', 'flexible-shipping' ),
81 'type' => MethodLogoSettingsField::FIELD_TYPE,
82 'description' => __( 'Choose an image from the media library to display after the shipping method description in checkout.', 'flexible-shipping' ),
83 'desc_tip' => true,
84 'default' => $this->get_value_from_settings( $method_settings, self::METHOD_LOGO_ID, 0 ),
85 'sanitize_callback' => 'absint',
86 self::METHOD_TITLE => $this->get_value_from_settings( $method_settings, self::METHOD_TITLE, 'Flexible Shipping' ),
87 ];
88
89 $settings[ self::METHOD_FREE_SHIPPING ] = [
90 'title' => __( 'Free shipping threshold', 'flexible-shipping' ),
91 'type' => 'price',
92 'default' => $method_free_shipping,
93 'description' => sprintf(
94 // Translators: bolds.
95 __( 'Enter a minimum threshold value which once reached will result in granting your customers the free shipping. It will be applied, as long as this shipping method will be available and its configured shipping cost calculation conditions are met. Example: If the %1$sFree shipping threshold%2$s is set to $200, and your price-based shipping cost calculation rules end at $199.99, you need to configure one more rule - %1$sWhen: Price - is from $200 - cost is $0%2$s to cover the range above the %1$sFree shipping threshold%2$s value.', 'flexible-shipping' ),
96 '<strong>',
97 '</strong>'
98 ),
99 'desc_tip' => true,
100 ];
101
102 $settings['method_free_shipping_label'] = [
103 'title' => __( 'Free Shipping Label', 'flexible-shipping' ),
104 'type' => 'text',
105 'default' => $this->get_value_from_settings( $method_settings, 'method_free_shipping_label', '' ),
106 'description' => __( 'Enter the text for the additional shipping method\'s label which will be displayed once the free shipping is triggered or calculated.', 'flexible-shipping' ),
107 'desc_tip' => true,
108 ];
109
110 $description = sprintf( //phpcs:ignore.
111 __( 'Learn %1$show to customize the displayed notice &rarr;%2$s', 'flexible-shipping' ), //phpcs:ignore.
112 sprintf( //phpcs:ignore.
113 '<a href="%s" target="_blank">', //phpcs:ignore.
114 esc_url( get_user_locale() === 'pl_PL' ? 'https://octol.io/fs-free-notice-pl' : 'https://octol.io/fs-free-notice' ) //phpcs:ignore.
115 ), //phpcs:ignore.
116 '</a>' //phpcs:ignore.
117 ) . '<br /><br />' . __( 'Please mind that if you use any additional plugins to split the shipment into packages, the \'Left to free shipping notice\' will not be displayed.', 'flexible-shipping' ); //phpcs:ignore.
118
119 $settings[ WPDesk_Flexible_Shipping::SETTING_METHOD_FREE_SHIPPING_NOTICE ] = [
120 'title' => __( '\'Left for free shipping\' notice (LFFS)', 'flexible-shipping' ),
121 'type' => 'checkbox',
122 'default' => $this->get_value_from_settings( $method_settings, WPDesk_Flexible_Shipping::SETTING_METHOD_FREE_SHIPPING_NOTICE, 'no' ),
123 'label' => __( 'Display the notice with the amount left for free shipping', 'flexible-shipping' ),
124 'description' => $description,
125 ];
126
127 $settings[ self::SETTING_METHOD_CALCULATION_METHOD ] = [
128 'title' => __( 'Rules Calculation', 'flexible-shipping' ),
129 'type' => 'select',
130 'description' => __( 'Select how rules will be calculated. If you choose "sum" the rules order is important.', 'flexible-shipping' ),
131 'default' => $this->get_value_from_settings( $method_settings, self::SETTING_METHOD_CALCULATION_METHOD, '' ),
132 'desc_tip' => true,
133 'options' => ( new CalculationMethodOptions() )->get_options(),
134 ];
135
136 $settings[ self::CART_CALCULATION ] = [
137 'title' => __( 'Cart Calculation', 'flexible-shipping' ),
138 'type' => 'select',
139 'default' => $this->get_value_from_settings( $method_settings, self::CART_CALCULATION, isset( $method_settings[ self::METHOD_DESCRIPTION ] ) ? CartCalculationOptions::CART : CartCalculationOptions::PACKAGE ),
140 'options' => ( new CartCalculationOptions() )->get_options(),
141 'description' => __( 'Choose Package value to exclude virtual products from rules calculation.', 'flexible-shipping' ),
142 'desc_tip' => true,
143 ];
144
145 $settings['method_visibility'] = [
146 'title' => __( 'Visibility', 'flexible-shipping' ),
147 'type' => 'checkbox',
148 'default' => $this->get_value_from_settings( $method_settings, 'method_visibility', 'no' ),
149 'label' => __( 'Show only for logged in users', 'flexible-shipping' ),
150 ];
151
152 $settings[ self::METHOD_DEFAULT ] = [
153 'title' => __( 'Default', 'flexible-shipping' ),
154 'type' => 'checkbox',
155 'default' => $this->get_value_from_settings( $method_settings, self::METHOD_DEFAULT, 'no' ),
156 'label' => __( 'Check the box to set this option as the default selected choice on the cart page.', 'flexible-shipping' ),
157 ];
158
159 $settings['method_debug_mode'] = [
160 'title' => __( 'FS Debug Mode', 'flexible-shipping' ),
161 'type' => 'checkbox',
162 'default' => $this->get_value_from_settings( $method_settings, 'method_debug_mode', 'no' ),
163 'label' => __( 'Enable FS Debug Mode', 'flexible-shipping' ),
164 'description' => sprintf(
165 // Translators: documentation link.
166 __( 'Enable FS debug mode to verify the shipping methods\' configuration, check which one was used and how the shipping cost was calculated as well as identify any possible mistakes. %1$sLearn more how the Debug Mode works →%2$s', 'flexible-shipping' ),
167 '<a href="' . ( 'pl_PL' !== get_user_locale() ? 'https://octol.io/fs-debug-mode' : 'https://octol.io/fs-debug-mode-pl' ) . '" target="_blank">',
168 '</a>'
169 ),
170 ];
171
172 if ( $with_integration_settings ) {
173 $settings = $this->append_integration_settings_if_present( $settings, $method_settings );
174 }
175
176 $settings[ self::METHOD_RULES ] = [
177 'title' => __( 'Shipping Cost Calculation Rules', 'flexible-shipping' ),
178 'type' => RulesSettingsField::FIELD_TYPE,
179 'default' => $this->get_value_from_settings( $method_settings, self::METHOD_RULES, ( new DefaultRulesSettings() )->get_normalized_settings() ),
180 self::METHOD_TITLE => $this->get_value_from_settings( $method_settings, self::METHOD_TITLE, __( 'Flexible Shipping', 'flexible-shipping' ) ),
181 ];
182
183 $settings[] = [
184 'type' => 'title',
185 'id' => 'flexible_shipping_method_settings_end',
186 'default' => '',
187 ];
188
189 // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
190 return apply_filters( 'flexible-shipping/settings/common-method-settings', $settings );
191 }
192
193 /**
194 * @param array $settings .
195 * @param array $method_settings .
196 *
197 * @return array
198 */
199 private function append_integration_settings_if_present( array $settings, $method_settings ) {
200 $integrations_options = apply_filters( 'flexible_shipping_integration_options', [ '' => __( 'None', 'flexible-shipping' ) ] );
201
202 if ( 1 < count( $integrations_options ) ) {
203 $settings['title_shipping_integration'] = [
204 'title' => __( 'Shipping Integration', 'flexible-shipping' ),
205 'type' => 'title',
206 'default' => '',
207 ];
208 $settings['method_integration'] = [
209 'title' => __( 'Integration', 'flexible-shipping' ),
210 'type' => 'select',
211 'desc_tip' => false,
212 'options' => $integrations_options,
213 'default' => $this->get_value_from_settings( $method_settings, 'method_integration' ),
214 ];
215 }
216
217 $filtered_settings = apply_filters( 'flexible_shipping_method_settings', $settings, $method_settings );
218
219 $settings = [];
220
221 foreach ( $filtered_settings as $settings_key => $settings_value ) {
222 if ( 'method_enabled' === $settings_key ) {
223 $settings['title_general_settings'] = [
224 'title' => __( 'General Settings', 'flexible-shipping' ),
225 'type' => 'title',
226 'default' => '',
227 ];
228 }
229
230 if ( 'method_free_shipping_requires' === $settings_key || ( 'method_free_shipping' === $settings_key && ! isset( $settings['method_free_shipping_requires'] ) ) ) {
231 $free_shipping_docs_url = get_user_locale() === 'pl_PL' ? 'https://octol.io/fs-free-shipping-coming-from-the-rules-pl' : 'https://octol.io/fs-free-shipping-coming-from-the-rules';
232 $settings['title_free_shipping'] = [
233 'title' => __( 'Free Shipping', 'flexible-shipping' ),
234 'type' => 'title',
235 'description' => sprintf(
236 // Translators: strong and link.
237 __( 'Specify when the free shipping should be available to your customers. You can use the %1$sFree shipping threshold%2$s option below or/and you can also set up the free shipping resulting directly from the Flexible Shipping cost calculation rules. %3$sLearn how to configure the free shipping coming from the cost calculation rules &rarr;%4$s', 'flexible-shipping' ),
238 '<strong>',
239 '</strong>',
240 '<a href="' . $free_shipping_docs_url . '" target="_blank">',
241 '</a>'
242 ),
243 'default' => '',
244 ];
245 if ( ! defined( 'FLEXIBLE_SHIPPING_PRO_VERSION' ) ) {
246 $compare_versions_link = get_user_locale() === 'pl_PL' ? 'https://octol.io/free-shipping-requires-fs-free-pro-comparison-pl' : 'https://octol.io/free-shipping-requires-fs-free-pro-comparison';
247 $settings[ self::METHOD_FREE_SHIPPING_REQUIRES_UPSELLING ] = [
248 'title' => __( 'Free Shipping Requires', 'flexible-shipping' ),
249 'type' => 'select',
250 'options' => [
251 'order_amount' => __( 'Minimum order value', 'flexible-shipping' ),
252 'item_quantity' => __( 'Minimum item quantity (PRO)', 'flexible-shipping' ),
253 'coupon' => __( 'Free shipping coupon (PRO)', 'flexible-shipping' ),
254 'order_amount_or_coupon' => __( 'Free shipping coupon or minimum order amount (PRO) ', 'flexible-shipping' ),
255 'order_amount_and_coupon' => __( 'Free shipping coupon and minimum order amount (PRO)', 'flexible-shipping' ),
256 ],
257 'description' => sprintf(
258 // Translators: link.
259 __( 'Compare the %1$sdifferences between Flexible Shipping FREE and PRO &rarr;%2$s', 'flexible-shipping' ),
260 '<a href="' . $compare_versions_link . '" target="_blank">',
261 '</a>'
262 ),
263 'desc_tip' => 'Define the condition which must be met for the free shipping to be granted.',
264 ];
265 }
266 }
267
268 if ( 'method_max_cost' === $settings_key || ( self::SETTING_METHOD_CALCULATION_METHOD === $settings_key && ! isset( $settings['method_max_cost'] ) ) ) {
269 $settings['title_cost_calculation'] = [
270 'title' => __( 'Cost Calculation', 'flexible-shipping' ),
271 'type' => 'title',
272 'default' => '',
273 ];
274 }
275
276 if ( 'method_visibility' === $settings_key ) {
277 $settings['title_advanced_options'] = [
278 'title' => __( 'Advanced Options', 'flexible-shipping' ),
279 'type' => 'title',
280 'default' => '',
281 ];
282 }
283
284 $settings[ $settings_key ] = $settings_value;
285 }
286
287 return $settings;
288 }
289
290 /**
291 * @param array $settings .
292 * @param string $field_name .
293 * @param string|array $default .
294 *
295 * @return string
296 */
297 private function get_value_from_settings( array $settings, $field_name, $default = '' ) {
298 return isset( $settings[ $field_name ] ) ? $settings[ $field_name ] : $default;
299 }
300 }
301