From c4f5d7a139d7e871f9bb048667dd6e1df3554d9d Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 2 May 2022 17:48:14 +0400 Subject: [PATCH] Move the subscription cart check into the callbacks. The subscription product in cart existence and the vaulting enabled check should be called inside the button renderer hook callback so that the mini-cart ajax refresh will take it into the consideration. --- .../ppcp-button/src/Assets/SmartButton.php | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index 1161f75d1..44fab492a 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -220,16 +220,15 @@ class SmartButton implements SmartButtonInterface { * @throws \WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException When a setting was not found. */ public function render_wrapper(): bool { - - if ( ! $this->can_save_vault_token() && $this->has_subscriptions() ) { - return false; - } - if ( $this->settings->has( 'enabled' ) && $this->settings->get( 'enabled' ) ) { $this->render_button_wrapper_registrar(); $this->render_message_wrapper_registrar(); } + if ( ! $this->can_save_vault_token() && $this->has_subscriptions() ) { + return false; + } + if ( $this->settings->has( 'dcc_enabled' ) && $this->settings->get( 'dcc_enabled' ) @@ -432,6 +431,10 @@ class SmartButton implements SmartButtonInterface { add_action( $this->mini_cart_button_renderer_hook(), function () { + if ( ! $this->can_save_vault_token() && $this->has_subscriptions() ) { + return; + } + if ( $this->is_cart_price_total_zero() || $this->is_free_trial_cart() ) { return; } @@ -521,6 +524,11 @@ class SmartButton implements SmartButtonInterface { * Renders the HTML for the buttons. */ public function button_renderer() { + + if ( ! $this->can_save_vault_token() && $this->has_subscriptions() ) { + return; + } + $product = wc_get_product(); if ( ! is_checkout() && is_a( $product, \WC_Product::class ) @@ -548,6 +556,9 @@ class SmartButton implements SmartButtonInterface { * Renders the HTML for the credit messaging. */ public function message_renderer() { + if ( ! $this->can_save_vault_token() && $this->has_subscriptions() ) { + return false; + } echo '
'; }