From 46c22c03e02beb2cfb10f7178f15bfd8c568764a Mon Sep 17 00:00:00 2001 From: Alex P Date: Tue, 17 Oct 2023 10:00:20 +0300 Subject: [PATCH] Improve message placement value --- .../ppcp-button/src/Assets/SmartButton.php | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index e298c1d1c..17f2e249b 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -703,23 +703,47 @@ class SmartButton implements SmartButtonInterface { * The values for the credit messaging. * * @return array - * @throws NotFoundException When a setting was not found. */ private function message_values(): array { if ( ! $this->settings_status->is_pay_later_messaging_enabled() ) { return array(); } - $placement = is_checkout() ? 'payment' : ( is_cart() ? 'cart' : 'product' ); - $product = wc_get_product(); - $amount = ( is_a( $product, WC_Product::class ) ) ? wc_get_price_including_tax( $product ) : 0; + $location = $this->location(); + + switch ( $location ) { + case 'checkout': + case 'checkout-block': + case 'pay-now': + $placement = 'payment'; + break; + case 'cart': + case 'cart-block': + $placement = 'cart'; + break; + case 'product': + $placement = 'product'; + break; + case 'shop': + $placement = 'product-list'; + break; + case 'home': + $placement = 'home'; + break; + default: + $placement = 'payment'; + break; + } + + $product = wc_get_product(); + $amount = ( is_a( $product, WC_Product::class ) ) ? wc_get_price_including_tax( $product ) : 0; if ( is_checkout() || is_cart() ) { $amount = WC()->cart->get_total( 'raw' ); } $styling_per_location = $this->settings->has( 'pay_later_enable_styling_per_messaging_location' ) && $this->settings->get( 'pay_later_enable_styling_per_messaging_location' ); - $location = $styling_per_location ? $this->location() : 'general'; + $location = $styling_per_location ? $location : 'general'; $setting_name_prefix = "pay_later_{$location}_message"; $layout = $this->settings->has( "{$setting_name_prefix}_layout" ) ? $this->settings->get( "{$setting_name_prefix}_layout" ) : 'text';