Skip to content

Commit

Permalink
Merge pull request #1894 from woocommerce/PCP-2387-support-for-classi…
Browse files Browse the repository at this point in the history
…c-checkout-block

Support for Classic Checkout Block (2387)
  • Loading branch information
Dinamiko authored Dec 14, 2023
2 parents ea23d09 + 52f3f38 commit 6491146
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions modules/ppcp-button/src/Assets/SmartButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ public function __construct(
* @return bool
*/
public function render_wrapper(): bool {
$this->init_context();

if ( $this->settings->has( 'enabled' ) && $this->settings->get( 'enabled' ) ) {
$this->render_button_wrapper_registrar();
$this->render_message_wrapper_registrar();
Expand Down
33 changes: 33 additions & 0 deletions modules/ppcp-button/src/Helper/ContextTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,39 @@
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;

trait ContextTrait {
/**
* Initializes context preconditions like is_cart() and is_checkout().
*
* @return void
*/
protected function init_context(): void {
if ( ! apply_filters( 'woocommerce_paypal_payments_block_classic_compat', true ) ) {
return;
}

/**
* Activate is_checkout() on woocommerce/classic-shortcode checkout blocks.
*
* @psalm-suppress MissingClosureParamType
*/
add_filter(
'woocommerce_is_checkout',
function ( $is_checkout ) {
if ( $is_checkout ) {
return $is_checkout;
}
return has_block( 'woocommerce/classic-shortcode {"shortcode":"checkout"}' );
}
);

// Activate is_cart() on woocommerce/classic-shortcode cart blocks.
if ( ! is_cart() && is_callable( 'wc_maybe_define_constant' ) ) {
if ( has_block( 'woocommerce/classic-shortcode' ) && ! has_block( 'woocommerce/classic-shortcode {"shortcode":"checkout"}' ) ) {
wc_maybe_define_constant( 'WOOCOMMERCE_CART', true );
}
}
}

/**
* Checks WC is_checkout() + WC checkout ajax requests.
*/
Expand Down

0 comments on commit 6491146

Please sign in to comment.