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
ShippingHooksFactory.php
51 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Multicurrency\Shipping; |
| 4 | |
| 5 | use WCML\StandAlone\IStandAloneAction; |
| 6 | use WCML\Utilities\AdminUrl; |
| 7 | |
| 8 | class ShippingHooksFactory implements \IWPML_Deferred_Action_Loader, \IWPML_Backend_Action_Loader, \IWPML_Frontend_Action_Loader, IStandAloneAction { |
| 9 | |
| 10 | public function get_load_action() { |
| 11 | return 'init'; |
| 12 | } |
| 13 | |
| 14 | public function create() { |
| 15 | global $woocommerce_wpml; |
| 16 | $hooks = []; |
| 17 | |
| 18 | if ( wcml_is_multi_currency_on() |
| 19 | && $this->hasAdditionalCurrencyDefined() |
| 20 | ) { |
| 21 | if ( $this->isShippingPageRequest() || $this->isAjaxOnShippingPageRequest() ) { |
| 22 | $hooks[] = new AdminHooks( $woocommerce_wpml->get_multi_currency() ); |
| 23 | } else { |
| 24 | $hooks[] = new FrontEndHooks( $woocommerce_wpml->get_multi_currency() ); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | return $hooks; |
| 29 | } |
| 30 | |
| 31 | private function hasAdditionalCurrencyDefined() { |
| 32 | global $woocommerce_wpml; |
| 33 | |
| 34 | $available_currencies = $woocommerce_wpml->get_multi_currency()->get_currency_codes(); |
| 35 | |
| 36 | return is_array( $available_currencies ) && count( $available_currencies ) > 1; |
| 37 | } |
| 38 | |
| 39 | private function isShippingPageRequest() { |
| 40 | return isset( $_GET['page'], $_GET['tab'] ) && AdminUrl::PAGE_WOO_SETTINGS === $_GET['page'] && 'shipping' === $_GET['tab'] |
| 41 | || isset( $_GET['action'] ) && 'woocommerce_shipping_zone_methods_save_settings' === $_GET['action']; |
| 42 | } |
| 43 | |
| 44 | private function isAjaxOnShippingPageRequest() { |
| 45 | $getData = wpml_collect( $_GET ); |
| 46 | $shippingActions = [ 'woocommerce_shipping_zone_add_method', 'woocommerce_shipping_zone_methods_save_changes' ]; |
| 47 | |
| 48 | return wp_doing_ajax() && wpml_collect( $shippingActions )->containsStrict( $getData->get( 'action' ) ); |
| 49 | } |
| 50 | } |
| 51 |