mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 09:08:09 +08:00
Add the data-page-type
attribute for JS SDK
This commit is contained in:
parent
ffe3a0b958
commit
0ece922427
1 changed files with 37 additions and 1 deletions
|
@ -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 '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue