From 0ece9224275cb0a287893749f14de10eebfd63de Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Tue, 16 Apr 2024 17:12:28 +0400 Subject: [PATCH] Add the `data-page-type` attribute for JS SDK --- .../ppcp-button/src/Assets/SmartButton.php | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index d795d4950..1de795450 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -1428,9 +1428,45 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages * @return array */ private function attributes(): array { - return array( + $attributes = array( 'data-partner-attribution-id' => $this->bn_code_for_context( $this->context() ), ); + + $page_type_attribute = $this->page_type_attribute(); + if ( $page_type_attribute ) { + $attributes['data-page-type'] = $page_type_attribute; + } + + return $attributes; + } + + /** + * Retrieves the value for page type attribute(data-page-type) used for the JS SDK. + * + * @return string + */ + protected function page_type_attribute(): string { + if ( is_search() ) { + return 'search-results'; + } + + switch ( $this->location() ) { + case 'product': + return 'product-details'; + case 'shop': + return 'product-listing'; + case 'home': + return 'mini-cart'; + case 'cart-block': + case 'cart': + return 'cart'; + case 'checkout-block': + case 'checkout': + case 'pay-now': + return 'checkout'; + default: + return ''; + } } /**