AdminHooks.php
1 week ago
DefaultConversion.php
1 week ago
FlatRateShipping.php
5 years ago
FreeShipping.php
1 week ago
FrontEndHooks.php
1 week ago
LocalPickup.php
5 years ago
ShippingClasses.php
1 week ago
ShippingClassesMode.php
1 week ago
ShippingHooksFactory.php
1 week ago
ShippingMode.php
1 week ago
ShippingModeBase.php
1 week ago
ShippingModeProvider.php
1 week ago
UnsupportedShipping.php
1 week ago
VariableCost.php
1 week ago
FreeShipping.php
65 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Multicurrency\Shipping; |
| 4 | |
| 5 | class FreeShipping implements ShippingMode { |
| 6 | use ShippingModeBase; |
| 7 | use DefaultConversion; |
| 8 | |
| 9 | public function getFieldTitle( $currencyCode ): string { |
| 10 | if ( ! is_string( $currencyCode ) ) { |
| 11 | $currencyCode = ''; |
| 12 | } |
| 13 | |
| 14 | /* translators: %s is the currency code */ |
| 15 | return sprintf( esc_html_x( 'Minimal order amount in %s', |
| 16 | 'The label for the field with minimal order amount in additional currency. The currency symbol will be added in place of %s specifier.', |
| 17 | 'woocommerce-multilingual' ), $currencyCode ); |
| 18 | } |
| 19 | |
| 20 | public function getFieldDescription( $currencyCode ): ?string { |
| 21 | if ( ! is_string( $currencyCode ) ) { |
| 22 | $currencyCode = ''; |
| 23 | } |
| 24 | |
| 25 | /* translators: %s is the currency code */ |
| 26 | return sprintf( esc_html_x( 'The minimal order amount if customer choose %s as a purchase currency.', |
| 27 | 'The description for the field with minimal order amount in additional currency. The currency symbol will be added in place of %s specifier.', |
| 28 | 'woocommerce-multilingual' ), $currencyCode ); |
| 29 | } |
| 30 | |
| 31 | public function getMethodId() { |
| 32 | return 'free_shipping'; |
| 33 | } |
| 34 | |
| 35 | private function getMinimalOrderAmountKey( $currencyCode ) { |
| 36 | return sprintf( 'min_amount_%s', $currencyCode ); |
| 37 | } |
| 38 | |
| 39 | public function getSettingsFormKey( $currencyCode ) { |
| 40 | return $this->getMinimalOrderAmountKey( $currencyCode ); |
| 41 | } |
| 42 | |
| 43 | public function getMinimalOrderAmountValue( $amount, $shipping, $currency ) { |
| 44 | if ( $this->isManualPricingEnabled( $shipping ) ) { |
| 45 | $key = $this->getMinimalOrderAmountKey( $currency ); |
| 46 | if ( ! empty( $shipping[ $key ] ) ) { |
| 47 | $amount = $shipping[ $key ]; |
| 48 | } else { |
| 49 | $amount = $this->getValueFromDefaultCurrency( $amount, $shipping, $key, $currency ); |
| 50 | } |
| 51 | } |
| 52 | return $amount; |
| 53 | } |
| 54 | |
| 55 | public function getShippingCostValue( $rate, $currency ) { |
| 56 | if ( ! isset( $rate->cost ) ) { |
| 57 | $rate->cost = 0; |
| 58 | } |
| 59 | return $rate->cost; |
| 60 | } |
| 61 | |
| 62 | public function isManualPricingEnabled( $instance ) { |
| 63 | return is_array( $instance ) && isset( $instance['wcml_shipping_costs'] ) && 'manual' === $instance['wcml_shipping_costs']; |
| 64 | } |
| 65 | } |