AXO: Add warning when shipping config is not compatible

This commit is contained in:
Daniel Dudzic 2024-07-17 19:06:40 +02:00
parent 2bf6e5e8cf
commit 0d7b557fa8
No known key found for this signature in database
GPG key ID: 31B40D33E3465483
4 changed files with 41 additions and 17 deletions

View file

@ -126,6 +126,18 @@ return array(
'requirements' => array( 'dcc', 'axo' ),
'gateway' => array( 'dcc', 'axo' ),
),
'axo_shipping_config_notice' => array(
'heading' => '',
'html' => $container->get( 'axo.shipping-config-notice' ),
'type' => 'ppcp-html',
'classes' => array( 'ppcp-field-indent' ),
'class' => array(),
'screens' => array(
State::STATE_ONBOARDED,
),
'requirements' => array( 'dcc', 'axo' ),
'gateway' => array( 'dcc', 'axo' ),
),
'axo_gateway_title' => array(
'title' => __( 'Gateway Title', 'woocommerce-paypal-payments' ),
'type' => 'text',

View file

@ -25,7 +25,7 @@ return array(
$apm_applies = $container->get( 'axo.helpers.apm-applies' );
assert( $apm_applies instanceof ApmApplies );
return $apm_applies->for_country_currency() && $apm_applies->for_settings();
return $apm_applies->for_country_currency();
},
'axo.helpers.apm-applies' => static function ( ContainerInterface $container ) : ApmApplies {
@ -202,7 +202,6 @@ return array(
return '<div class="ppcp-notice ppcp-notice-error"><p>' . $notice_content . '</p></div>';
},
'axo.smart-button-location-notice' => static function ( ContainerInterface $container ) : string {
$settings = $container->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );
@ -230,6 +229,24 @@ return array(
return '<div class="ppcp-notice ppcp-notice-warning"><p>' . $notice_content . '</p></div>';
},
'axo.shipping-config-notice' => static function ( ContainerInterface $container ) : string {
$shipping_settings_link = admin_url( 'admin.php?page=wc-settings&tab=shipping&section=options' );
if ( wc_shipping_enabled() && wc_ship_to_billing_address_only() ) {
$notice_content = sprintf(
/* translators: %1$s: URL to the Shipping destination settings page. */
__(
'<span class="highlight">Warning:</span> The <a href="%1$s">Shipping destination</a> of your store is currently configured to <code>Force shipping to the customer billing address</code>. To enable Fastlane and accelerate payments, the shipping destination must be configured either to <code>Default to customer shipping address</code> or <code>Default to customer billing address</code> so buyers can set separate billing and shipping details.',
'woocommerce-paypal-payments'
),
esc_url( $shipping_settings_link )
);
} else {
return '';
}
return '<div class="ppcp-notice ppcp-notice-error"><p>' . $notice_content . '</p></div>';
},
'axo.endpoint.frontend-logger' => static function ( ContainerInterface $container ): FrontendLoggerEndpoint {
return new FrontendLoggerEndpoint(
$container->get( 'button.request-data' ),

View file

@ -341,6 +341,7 @@ class AxoModule implements ModuleInterface {
return ! is_user_logged_in()
&& CartCheckoutDetector::has_classic_checkout()
&& $this->is_compatible_shipping_config()
&& $is_axo_enabled
&& $is_dcc_enabled
&& ! $this->is_excluded_endpoint();
@ -396,4 +397,13 @@ class AxoModule implements ModuleInterface {
// Exclude the Order Pay endpoint.
return is_wc_endpoint_url( 'order-pay' );
}
/**
* Condition to evaluate if the shipping configuration is compatible.
*
* @return bool
*/
private function is_compatible_shipping_config(): bool {
return ! wc_shipping_enabled() || ( wc_shipping_enabled() && ! wc_ship_to_billing_address_only() );
}
}

View file

@ -64,19 +64,4 @@ class ApmApplies {
}
return in_array( $this->currency, $this->allowed_country_currency_matrix[ $this->country ], true );
}
/**
* Returns whether the settings are compatible with AXO.
*
* @return bool
*/
public function for_settings(): bool {
if ( get_option( 'woocommerce_ship_to_destination' ) === 'billing_only' ) { // Force shipping to the customer billing address.
return false;
}
return true;
}
}