Merge pull request #625 from woocommerce/PCP-660-mini-cart-smart-buttons-visible-with-subscription-product

Move the subscription product in cart existence and the vaulting enabled check into the callbacks.
This commit is contained in:
Emili Castells 2022-05-17 11:05:18 +02:00 committed by GitHub
commit c6cc94f5ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -221,16 +221,15 @@ class SmartButton implements SmartButtonInterface {
* @throws \WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException When a setting was not found. * @throws \WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException When a setting was not found.
*/ */
public function render_wrapper(): bool { 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' ) ) { if ( $this->settings->has( 'enabled' ) && $this->settings->get( 'enabled' ) ) {
$this->render_button_wrapper_registrar(); $this->render_button_wrapper_registrar();
$this->render_message_wrapper_registrar(); $this->render_message_wrapper_registrar();
} }
if ( ! $this->can_save_vault_token() && $this->has_subscriptions() ) {
return false;
}
if ( if (
$this->settings->has( 'dcc_enabled' ) $this->settings->has( 'dcc_enabled' )
&& $this->settings->get( 'dcc_enabled' ) && $this->settings->get( 'dcc_enabled' )
@ -433,6 +432,10 @@ class SmartButton implements SmartButtonInterface {
add_action( add_action(
$this->mini_cart_button_renderer_hook(), $this->mini_cart_button_renderer_hook(),
function () { function () {
if ( ! $this->can_save_vault_token() && $this->has_subscriptions() ) {
return;
}
if ( $this->is_cart_price_total_zero() || $this->is_free_trial_cart() ) { if ( $this->is_cart_price_total_zero() || $this->is_free_trial_cart() ) {
return; return;
} }
@ -515,6 +518,11 @@ class SmartButton implements SmartButtonInterface {
* Renders the HTML for the buttons. * Renders the HTML for the buttons.
*/ */
public function button_renderer() { public function button_renderer() {
if ( ! $this->can_save_vault_token() && $this->has_subscriptions() ) {
return;
}
$product = wc_get_product(); $product = wc_get_product();
if ( if (
@ -540,6 +548,10 @@ class SmartButton implements SmartButtonInterface {
* Renders the HTML for the credit messaging. * Renders the HTML for the credit messaging.
*/ */
public function message_renderer() { public function message_renderer() {
if ( ! $this->can_save_vault_token() && $this->has_subscriptions() ) {
return false;
}
$product = wc_get_product(); $product = wc_get_product();
if ( if (