Add the data-page-type attribute for JS SDK

This commit is contained in:
Narek Zakarian 2024-04-16 17:12:28 +04:00
parent ffe3a0b958
commit 0ece922427
No known key found for this signature in database
GPG key ID: 07AFD7E7A9C164A7

View file

@ -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 '';
}
}
/**