BlockEditing
2 weeks ago
Convert
2 weeks ago
Duplicate
2 weeks ago
Management
2 weeks ago
Timestamps
2 weeks ago
Tracker
2 weeks ago
views
2 weeks ago
CommonMethodSettings.php
2 weeks ago
FreeShippingCalculator.php
2 weeks ago
FreeShippingThresholdRuleValidator.php
2 weeks ago
MethodDescription.php
2 weeks ago
MethodLogo.php
2 weeks ago
MethodLogoCheckoutBlocksAssets.php
2 weeks ago
MethodLogoSettingsField.php
2 weeks ago
MethodSettings.php
2 weeks ago
MethodTitle.php
2 weeks ago
RateCalculator.php
2 weeks ago
RateCalculatorFactory.php
2 weeks ago
SettingsDisplayPreparer.php
2 weeks ago
SettingsProcessor.php
2 weeks ago
SingleMethodSettings.php
2 weeks ago
FreeShippingCalculator.php
84 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class FreeShippingCalculator |
| 4 | * |
| 5 | * @package WPDesk\FS\TableRate\ShippingMethod |
| 6 | */ |
| 7 | |
| 8 | namespace WPDesk\FS\TableRate\ShippingMethod; |
| 9 | |
| 10 | use FSVendor\WPDesk\FS\TableRate\Settings\MethodSettings; |
| 11 | use FSVendor\WPDesk\FS\TableRate\Settings\MethodSettingsFactory; |
| 12 | use WPDesk_Flexible_Shipping; |
| 13 | |
| 14 | /** |
| 15 | * Can calculate free shipping. |
| 16 | */ |
| 17 | class FreeShippingCalculator { |
| 18 | |
| 19 | /** |
| 20 | * @param MethodSettings $shipping_method . |
| 21 | * @param float $cart_contents_cost . |
| 22 | * |
| 23 | * @return bool |
| 24 | */ |
| 25 | public function is_free_shipping( MethodSettings $shipping_method, $cart_contents_cost ) { |
| 26 | /** |
| 27 | * Can provide free shipping callback. |
| 28 | * For internal use. |
| 29 | * |
| 30 | * @internal |
| 31 | */ |
| 32 | $free_shipping_calculation_callback = apply_filters( |
| 33 | 'flexible-shipping/shipping-method/free-shipping-callback', |
| 34 | array( $this, 'is_free_shipping_callback' ), |
| 35 | $shipping_method->get_raw_settings() |
| 36 | ); |
| 37 | |
| 38 | $is_free_shipping = $free_shipping_calculation_callback( $shipping_method->get_raw_settings(), $cart_contents_cost ); |
| 39 | |
| 40 | $is_free_shipping = apply_filters_deprecated( |
| 41 | 'flexible_shipping_is_free_shipping', |
| 42 | array( $is_free_shipping, $shipping_method->get_raw_settings(), $cart_contents_cost ), |
| 43 | '4.0.0', |
| 44 | 'flexible-shipping/shipping-method/is-free-shipping' |
| 45 | ); |
| 46 | |
| 47 | /** |
| 48 | * Can modify free shipping. |
| 49 | * |
| 50 | * @param bool $is_free_shipping Current is_free_shipping value based on method settings. |
| 51 | * @param array $shipping_method Flexible shipping method settings. |
| 52 | * @param float $cart_contents_cost Shipping contents cost. |
| 53 | * |
| 54 | * @return bool |
| 55 | */ |
| 56 | return apply_filters( 'flexible-shipping/shipping-method/is-free-shipping', $is_free_shipping, $shipping_method->get_raw_settings(), $cart_contents_cost ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Is free shipping? |
| 61 | * |
| 62 | * @param array $shipping_method_settings . |
| 63 | * @param float $cart_contents_cost . |
| 64 | * |
| 65 | * @return bool |
| 66 | */ |
| 67 | public function is_free_shipping_callback( $shipping_method_settings, $cart_contents_cost ) { |
| 68 | $shipping_method = MethodSettingsFactory::create_from_array( $shipping_method_settings ); |
| 69 | $is_free_shipping = false; |
| 70 | $free_shipping = $shipping_method->get_free_shipping(); |
| 71 | if ( isset( $free_shipping ) && '' !== $free_shipping ) { |
| 72 | $free_shipping = (float) trim( $free_shipping ); |
| 73 | if ( is_numeric( $free_shipping ) ) { |
| 74 | if ( (float) apply_filters( 'flexible_shipping_value_in_currency', $free_shipping ) <= (float) $cart_contents_cost ) { |
| 75 | $is_free_shipping = true; |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | return $is_free_shipping; |
| 81 | } |
| 82 | |
| 83 | } |
| 84 |