mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Merge pull request #2224 from woocommerce/PCP-3062-fastlane-detect-checkout-page-type
AXO: Add warnings in Fastlane settings if the user isn't using classic checkout (3062)
This commit is contained in:
commit
97eae9b6db
6 changed files with 244 additions and 0 deletions
|
@ -9,6 +9,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace WooCommerce\PayPalCommerce\Axo;
|
namespace WooCommerce\PayPalCommerce\Axo;
|
||||||
|
|
||||||
|
use WooCommerce\PayPalCommerce\Axo\Helper\NoticeRenderer;
|
||||||
use WooCommerce\PayPalCommerce\Axo\Helper\PropertiesDictionary;
|
use WooCommerce\PayPalCommerce\Axo\Helper\PropertiesDictionary;
|
||||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||||
|
@ -82,6 +83,7 @@ return array(
|
||||||
->rule()
|
->rule()
|
||||||
->condition_element( 'axo_enabled', '1' )
|
->condition_element( 'axo_enabled', '1' )
|
||||||
->action_visible( 'axo_gateway_title' )
|
->action_visible( 'axo_gateway_title' )
|
||||||
|
->action_visible( 'axo_checkout_config_notice' )
|
||||||
->action_visible( 'axo_privacy' )
|
->action_visible( 'axo_privacy' )
|
||||||
->action_visible( 'axo_name_on_card' )
|
->action_visible( 'axo_name_on_card' )
|
||||||
->action_visible( 'axo_style_heading' )
|
->action_visible( 'axo_style_heading' )
|
||||||
|
@ -112,6 +114,18 @@ return array(
|
||||||
),
|
),
|
||||||
'classes' => array( 'ppcp-valign-label-middle', 'ppcp-align-label-center' ),
|
'classes' => array( 'ppcp-valign-label-middle', 'ppcp-align-label-center' ),
|
||||||
),
|
),
|
||||||
|
'axo_checkout_config_notice' => array(
|
||||||
|
'heading' => '',
|
||||||
|
'html' => $container->get( 'axo.checkout-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(
|
'axo_gateway_title' => array(
|
||||||
'title' => __( 'Gateway Title', 'woocommerce-paypal-payments' ),
|
'title' => __( 'Gateway Title', 'woocommerce-paypal-payments' ),
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
|
|
|
@ -13,6 +13,7 @@ use WooCommerce\PayPalCommerce\Axo\Assets\AxoManager;
|
||||||
use WooCommerce\PayPalCommerce\Axo\Gateway\AxoGateway;
|
use WooCommerce\PayPalCommerce\Axo\Gateway\AxoGateway;
|
||||||
use WooCommerce\PayPalCommerce\Axo\Helper\ApmApplies;
|
use WooCommerce\PayPalCommerce\Axo\Helper\ApmApplies;
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Helper\CartCheckoutDetector;
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
|
||||||
|
@ -149,4 +150,47 @@ return array(
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'axo.checkout-config-notice' => static function ( ContainerInterface $container ) : string {
|
||||||
|
$checkout_page_link = esc_url( get_edit_post_link( wc_get_page_id( 'checkout' ) ) ?? '' );
|
||||||
|
$block_checkout_docs_link = __(
|
||||||
|
'https://woocommerce.com/document/cart-checkout-blocks-status/#reverting-to-the-cart-and-checkout-shortcodes',
|
||||||
|
'woocommerce-paypal-payments'
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( CartCheckoutDetector::has_elementor_checkout() ) {
|
||||||
|
$notice_content = sprintf(
|
||||||
|
/* translators: %1$s: URL to the Checkout edit page. %2$s: URL to the block checkout docs. */
|
||||||
|
__(
|
||||||
|
'<span class="highlight">Warning:</span> The <a href="%1$s">Checkout page</a> of your store currently uses the <code>Elementor Checkout widget</code>. To enable Fastlane and accelerate payments, the page must include either the <code>Classic Checkout</code> or the <code>[woocommerce_checkout]</code> shortcode. See <a href="%2$s">this page</a> for instructions on how to switch to the classic layout.',
|
||||||
|
'woocommerce-paypal-payments'
|
||||||
|
),
|
||||||
|
esc_url( $checkout_page_link ),
|
||||||
|
esc_url( $block_checkout_docs_link )
|
||||||
|
);
|
||||||
|
} elseif ( CartCheckoutDetector::has_block_checkout() ) {
|
||||||
|
$notice_content = sprintf(
|
||||||
|
/* translators: %1$s: URL to the Checkout edit page. %2$s: URL to the block checkout docs. */
|
||||||
|
__(
|
||||||
|
'<span class="highlight">Warning:</span> The <a href="%1$s">Checkout page</a> of your store currently uses the WooCommerce <code>Checkout</code> block. To enable Fastlane and accelerate payments, the page must include either the <code>Classic Checkout</code> or the <code>[woocommerce_checkout]</code> shortcode. See <a href="%2$s">this page</a> for instructions on how to switch to the classic layout.',
|
||||||
|
'woocommerce-paypal-payments'
|
||||||
|
),
|
||||||
|
esc_url( $checkout_page_link ),
|
||||||
|
esc_url( $block_checkout_docs_link )
|
||||||
|
);
|
||||||
|
} elseif ( ! CartCheckoutDetector::has_classic_checkout() ) {
|
||||||
|
$notice_content = sprintf(
|
||||||
|
/* translators: %1$s: URL to the Checkout edit page. %2$s: URL to the block checkout docs. */
|
||||||
|
__(
|
||||||
|
'<span class="highlight">Warning:</span> The <a href="%1$s">Checkout page</a> of your store does not seem to be properly configured or uses an incompatible <code>third-party Checkout</code> solution. To enable Fastlane and accelerate payments, the page must include either the <code>Classic Checkout</code> or the <code>[woocommerce_checkout]</code> shortcode. See <a href="%2$s">this page</a> for instructions on how to switch to the classic layout.',
|
||||||
|
'woocommerce-paypal-payments'
|
||||||
|
),
|
||||||
|
esc_url( $checkout_page_link ),
|
||||||
|
esc_url( $block_checkout_docs_link )
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return '<div class="ppcp-notice ppcp-notice-warning"><p>' . $notice_content . '</p></div>';
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -56,6 +56,25 @@ $background-ident-color: #fbfbfb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ppcp-notice {
|
||||||
|
background: #fff;
|
||||||
|
border: 1px solid #c3c4c7;
|
||||||
|
border-left-width: 4px;
|
||||||
|
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
|
||||||
|
margin: 5px 15px 2px;
|
||||||
|
padding: 1px 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ppcp-notice-warning {
|
||||||
|
border-left-color: #dba617;
|
||||||
|
|
||||||
|
.highlight {
|
||||||
|
background: transparent;
|
||||||
|
color: #dba617;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Box indented fields.
|
// Box indented fields.
|
||||||
@media screen and (min-width: 800px) {
|
@media screen and (min-width: 800px) {
|
||||||
.ppcp-settings-field {
|
.ppcp-settings-field {
|
||||||
|
@ -77,6 +96,18 @@ $background-ident-color: #fbfbfb;
|
||||||
|
|
||||||
th, &.ppcp-settings-field-heading td {
|
th, &.ppcp-settings-field-heading td {
|
||||||
padding-left: 40px;
|
padding-left: 40px;
|
||||||
|
padding-right: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ppcp-notice {
|
||||||
|
margin-left: 40px;
|
||||||
|
margin-right: 10px;
|
||||||
|
padding: 1px 12px;
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin: .5em 0;
|
||||||
|
padding: 2px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
th, td {
|
th, td {
|
||||||
|
|
129
modules/ppcp-wc-gateway/src/Helper/CartCheckoutDetector.php
Normal file
129
modules/ppcp-wc-gateway/src/Helper/CartCheckoutDetector.php
Normal file
|
@ -0,0 +1,129 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Helper to detect what cart and checkout configuration is being used.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\WcGateway\Helper
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\WcGateway\Helper;
|
||||||
|
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class CartCheckoutDetector
|
||||||
|
*/
|
||||||
|
class CartCheckoutDetector {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of Elementor widgets if they exist for a specific page.
|
||||||
|
*
|
||||||
|
* @param int $page_id The ID of the page.
|
||||||
|
*
|
||||||
|
* @return array List of widget types if any exist, otherwise an empty array.
|
||||||
|
*/
|
||||||
|
private static function get_elementor_widgets( $page_id ): array {
|
||||||
|
$elementor_data = get_post_meta( $page_id, '_elementor_data' );
|
||||||
|
|
||||||
|
if ( isset( $elementor_data[0] ) ) {
|
||||||
|
// Parse the Elementor json and find all widgets for a specific page.
|
||||||
|
$reg_exp = '/"widgetType":"([^"]*)/i';
|
||||||
|
$output_array = array();
|
||||||
|
|
||||||
|
if ( is_array( $elementor_data[0] ) ) {
|
||||||
|
$elementor_data[0] = wp_json_encode( $elementor_data[0] );
|
||||||
|
}
|
||||||
|
|
||||||
|
preg_match_all( $reg_exp, $elementor_data[0], $output_array, PREG_SET_ORDER );
|
||||||
|
|
||||||
|
$widgets_list = array();
|
||||||
|
|
||||||
|
foreach ( $output_array as $found ) {
|
||||||
|
if ( ! isset( $found[1] ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$widget_key = $found[1];
|
||||||
|
|
||||||
|
$widgets_list[] = $widget_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $widgets_list;
|
||||||
|
}
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the Checkout page is using Elementor.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function has_elementor_checkout(): bool {
|
||||||
|
// Check if Elementor is installed and activated
|
||||||
|
if ( did_action( 'elementor/loaded' ) ) {
|
||||||
|
$elementor_widgets = self::get_elementor_widgets( wc_get_page_id( 'checkout' ) );
|
||||||
|
|
||||||
|
if ( $elementor_widgets ) {
|
||||||
|
return in_array( 'woocommerce-checkout-page', $elementor_widgets, true );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the Cart page is using Elementor.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function has_elementor_cart(): bool {
|
||||||
|
$elementor_widgets = self::get_elementor_widgets( wc_get_page_id( 'cart' ) );
|
||||||
|
|
||||||
|
if ( $elementor_widgets ) {
|
||||||
|
return in_array( 'woocommerce-cart-page', $elementor_widgets, true );
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the Checkout page is using the block checkout.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function has_block_checkout(): bool {
|
||||||
|
$checkout_page_id = wc_get_page_id( 'checkout' );
|
||||||
|
return $checkout_page_id && has_block( 'woocommerce/checkout', $checkout_page_id );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the Cart page is using the block cart.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function has_block_cart(): bool {
|
||||||
|
$cart_page_id = wc_get_page_id( 'cart' );
|
||||||
|
return $cart_page_id && has_block( 'woocommerce/cart', $cart_page_id );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the Checkout page is using the classic checkout.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function has_classic_checkout(): bool {
|
||||||
|
$checkout_page_id = wc_get_page_id( 'checkout' );
|
||||||
|
return $checkout_page_id && has_block( 'woocommerce/classic-shortcode', $checkout_page_id );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the Cart page is using the classic cart.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function has_classic_cart(): bool {
|
||||||
|
$cart_page_id = wc_get_page_id( 'cart' );
|
||||||
|
return $cart_page_id && has_block( 'woocommerce/classic-shortcode', $cart_page_id );
|
||||||
|
}
|
||||||
|
}
|
|
@ -268,6 +268,31 @@ class SettingsRenderer {
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the html field.
|
||||||
|
*
|
||||||
|
* @param string $field The current field HTML.
|
||||||
|
* @param string $key The current key.
|
||||||
|
* @param array $config The configuration array.
|
||||||
|
* @param string $value The current value.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function render_html( $field, $key, $config, $value ): string {
|
||||||
|
|
||||||
|
if ( 'ppcp-html' !== $config['type'] ) {
|
||||||
|
return $field;
|
||||||
|
}
|
||||||
|
|
||||||
|
$html = sprintf(
|
||||||
|
'<div class="wc-settings-html %s">%s</div>',
|
||||||
|
esc_attr( implode( ' ', $config['classes'] ) ),
|
||||||
|
$config['html']
|
||||||
|
);
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the table row.
|
* Renders the table row.
|
||||||
*
|
*
|
||||||
|
|
|
@ -627,6 +627,7 @@ class WCGatewayModule implements ModuleInterface {
|
||||||
$field = $renderer->render_password( $field, $key, $args, $value );
|
$field = $renderer->render_password( $field, $key, $args, $value );
|
||||||
$field = $renderer->render_heading( $field, $key, $args, $value );
|
$field = $renderer->render_heading( $field, $key, $args, $value );
|
||||||
$field = $renderer->render_table( $field, $key, $args, $value );
|
$field = $renderer->render_table( $field, $key, $args, $value );
|
||||||
|
$field = $renderer->render_html( $field, $key, $args, $value );
|
||||||
return $field;
|
return $field;
|
||||||
},
|
},
|
||||||
10,
|
10,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue