Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflict with EasyShip Plugin: Shipping Methods Not Displayed #2845

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions modules/ppcp-axo-block/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
$container->get( 'onboarding.environment' ),
$container->get( 'wcgateway.url' ),
$container->get( 'axo.payment_method_selected_map' ),
$container->get( 'axo.supported-country-card-type-matrix' ),
$container->get( 'axo.shipping-wc-enabled-locations' )
$container->get( 'axo.supported-country-card-type-matrix' )
);
},
);
14 changes: 2 additions & 12 deletions modules/ppcp-axo-block/src/AxoBlockPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
*/
private $supported_country_card_type_matrix;

/**
* The list of WooCommerce enabled shipping locations.
*
* @var array
*/
private array $enabled_shipping_locations;

/**
* AdvancedCardPaymentMethod constructor.
*
Expand All @@ -113,7 +106,6 @@ class AxoBlockPaymentMethod extends AbstractPaymentMethodType {
* @param string $wcgateway_module_url The WcGateway module URL.
* @param array $payment_method_selected_map Mapping of payment methods to the PayPal Insights 'payment_method_selected' types.
* @param array $supported_country_card_type_matrix The supported country card type matrix for Axo.
* @param array $enabled_shipping_locations The list of WooCommerce enabled shipping locations.
*/
public function __construct(
string $module_url,
Expand All @@ -125,8 +117,7 @@ public function __construct(
Environment $environment,
string $wcgateway_module_url,
array $payment_method_selected_map,
array $supported_country_card_type_matrix,
array $enabled_shipping_locations
array $supported_country_card_type_matrix
) {
$this->name = AxoGateway::ID;
$this->module_url = $module_url;
Expand All @@ -139,7 +130,6 @@ public function __construct(
$this->wcgateway_module_url = $wcgateway_module_url;
$this->payment_method_selected_map = $payment_method_selected_map;
$this->supported_country_card_type_matrix = $supported_country_card_type_matrix;
$this->enabled_shipping_locations = $enabled_shipping_locations;
}
/**
* {@inheritDoc}
Expand Down Expand Up @@ -237,7 +227,7 @@ private function script_data() : array {
),
'allowed_cards' => $this->supported_country_card_type_matrix,
'disable_cards' => $this->settings->has( 'disable_cards' ) ? (array) $this->settings->get( 'disable_cards' ) : array(),
'enabled_shipping_locations' => $this->enabled_shipping_locations,
'enabled_shipping_locations' => apply_filters( 'woocommerce_paypal_payments_axo_shipping_wc_enabled_locations', array() ),
'style_options' => array(
'root' => array(
'backgroundColor' => $this->settings->has( 'axo_style_root_bg_color' ) ? $this->settings->get( 'axo_style_root_bg_color' ) : '',
Expand Down
23 changes: 5 additions & 18 deletions modules/ppcp-axo/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@
$container->get( 'api.shop.currency.getter' ),
$container->get( 'woocommerce.logger.woocommerce' ),
$container->get( 'wcgateway.url' ),
$container->get( 'axo.supported-country-card-type-matrix' ),
$container->get( 'axo.shipping-wc-enabled-locations' )
$container->get( 'axo.supported-country-card-type-matrix' )
);
},

Expand Down Expand Up @@ -329,33 +328,23 @@ function ( array $plugin ): string {
);
},

'axo.shipping-wc-enabled-locations' => static function ( ContainerInterface $container ): array {
'axo.shipping-wc-enabled-locations' => static function ( ContainerInterface $container ) {
$default_zone = new \WC_Shipping_Zone( 0 );

$is_method_enabled = fn( \WC_Shipping_Method $method): bool => $method->enabled === 'yes';

$is_default_zone_enabled = ! empty(
array_filter(
$default_zone->get_shipping_methods(),
$is_method_enabled
)
);

if ( $is_default_zone_enabled ) {
if ( ! empty( $default_zone->get_shipping_methods( true ) ) ) {
return array();
}

$shipping_zones = \WC_Shipping_Zones::get_zones();

$get_zone_locations = fn( \WC_Shipping_Zone $zone): array =>
! empty( array_filter( $zone->get_shipping_methods(), $is_method_enabled ) )
! empty( $zone->get_shipping_methods( true ) )
? array_map(
fn( object $location): string => $location->code,
$zone->get_zone_locations()
)
: array();

$enabled_locations = array_unique(
return array_unique(
array_merge(
...array_map(
$get_zone_locations,
Expand All @@ -367,7 +356,5 @@ function ( array $plugin ): string {
)
)
);

return $enabled_locations;
},
);
13 changes: 2 additions & 11 deletions modules/ppcp-axo/src/Assets/AxoManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@ class AxoManager {
* @var array
*/
private array $supported_country_card_type_matrix;
/**
* The list of WooCommerce enabled shipping locations.
*
* @var array
*/
private array $enabled_shipping_locations;

/**
* AxoManager constructor.
Expand All @@ -120,7 +114,6 @@ class AxoManager {
* @param LoggerInterface $logger The logger.
* @param string $wcgateway_module_url The WcGateway module URL.
* @param array $supported_country_card_type_matrix The supported country card type matrix for Axo.
* @param array $enabled_shipping_locations The list of WooCommerce enabled shipping locations.
*/
public function __construct(
string $module_url,
Expand All @@ -133,8 +126,7 @@ public function __construct(
CurrencyGetter $currency,
LoggerInterface $logger,
string $wcgateway_module_url,
array $supported_country_card_type_matrix,
array $enabled_shipping_locations
array $supported_country_card_type_matrix
) {

$this->module_url = $module_url;
Expand All @@ -147,7 +139,6 @@ public function __construct(
$this->currency = $currency;
$this->logger = $logger;
$this->wcgateway_module_url = $wcgateway_module_url;
$this->enabled_shipping_locations = $enabled_shipping_locations;
$this->supported_country_card_type_matrix = $supported_country_card_type_matrix;
}

Expand Down Expand Up @@ -203,7 +194,7 @@ private function script_data(): array {
return $data; } )( $this->insights_data ),
'allowed_cards' => $this->supported_country_card_type_matrix,
'disable_cards' => $this->settings->has( 'disable_cards' ) ? (array) $this->settings->get( 'disable_cards' ) : array(),
'enabled_shipping_locations' => $this->enabled_shipping_locations,
'enabled_shipping_locations' => apply_filters( 'woocommerce_paypal_payments_axo_shipping_wc_enabled_locations', array() ),
'style_options' => array(
'root' => array(
'backgroundColor' => $this->settings->has( 'axo_style_root_bg_color' ) ? $this->settings->get( 'axo_style_root_bg_color' ) : '',
Expand Down
10 changes: 10 additions & 0 deletions modules/ppcp-axo/src/AxoModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ static function () use ( $c, $manager, $module ) {
}
);

/**
* Late loading locations because of trouble with some shipping plugins
*/
add_filter(
'woocommerce_paypal_payments_axo_shipping_wc_enabled_locations',
function ( array $locations ) use ( $c ): array {
return array_merge( $locations, $c->get( 'axo.shipping-wc-enabled-locations' ) );
}
);

/**
* Param types removed to avoid third-party issues.
*
Expand Down
Loading