New option to configure BN-Code

Configurable via a wp-config constant, or a new wp-filter.
This commit is contained in:
Philipp Stracker 2024-07-02 16:10:10 +02:00
parent 34245a852b
commit 6efcaa5630
No known key found for this signature in database
7 changed files with 57 additions and 12 deletions

View file

@ -818,7 +818,14 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
*/
do_action( "ppcp_before_{$location_hook}_message_wrapper" );
$messages_placeholder = '<div class="ppcp-messages" data-partner-attribution-id="Woo_PPCP"></div>';
/**
* The BN code.
*
* @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE
*/
$bn_code = PPCP_PAYPAL_BN_CODE;
$messages_placeholder = '<div class="ppcp-messages" data-partner-attribution-id="' . esc_attr( $bn_code ) . '"></div>';
if ( is_array( $block_params ) && ( $block_params['blockName'] ?? false ) ) {
$this->render_after_block(
@ -1538,7 +1545,15 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
private function bn_code_for_context( string $context ): string {
$codes = $this->bn_codes();
return ( isset( $codes[ $context ] ) ) ? $codes[ $context ] : 'Woo_PPCP';
/**
* The BN code.
*
* @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE
*/
$bn_code = PPCP_PAYPAL_BN_CODE;
return ( isset( $codes[ $context ] ) ) ? $codes[ $context ] : $bn_code;
}
/**
@ -1546,13 +1561,19 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
*
* @return array
*/
private function bn_codes(): array {
private function bn_codes() : array {
/**
* The BN code.
*
* @psalm-suppress UndefinedConstant -- PPCP_PAYPAL_BN_CODE
*/
$bn_code = PPCP_PAYPAL_BN_CODE;
return array(
'checkout' => 'Woo_PPCP',
'cart' => 'Woo_PPCP',
'mini-cart' => 'Woo_PPCP',
'product' => 'Woo_PPCP',
'checkout' => $bn_code,
'cart' => $bn_code,
'mini-cart' => $bn_code,
'product' => $bn_code,
);
}