Skip to content

Commit 9fb5bec

Browse files
committed
feat: add separate titles for Apple Pay and Google Pay with conditional display
- Add apple_pay_title and google_pay_title settings fields - Conditionally display Apple Pay or Google Pay title based on device detection - Add test mode suffix to both titles when enabled - Update blocks and classic checkout implementations - Clarify title field descriptions for users (main title used for emails/admin only) - Fully backward compatible with existing installations
1 parent a825329 commit 9fb5bec

File tree

5 files changed

+77
-14
lines changed

5 files changed

+77
-14
lines changed

assets/js/components/monei-apple-google-component.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ export const createAppleGoogleLabel = ( moneiData ) => {
1313
let logo = googleEnabled ? moneiData.logoGoogle : false;
1414
logo = isApple && appleEnabled ? moneiData.logoApple : logo;
1515

16-
const title = moneiData.title || '';
16+
// Use specific title based on device
17+
const title = isApple
18+
? moneiData.applePayTitle || ''
19+
: moneiData.googlePayTitle || '';
20+
1721
const shouldShowLogo =
1822
( isApple && moneiData?.logoApple ) ||
1923
( ! isApple && moneiData?.logoGoogle );

assets/js/monei-apple-google-classic.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,28 @@
229229
*/
230230
update_apple_google_label() {
231231
const isApple = window.ApplePaySession?.canMakePayments();
232+
const label = document.querySelector(
233+
'label[for="payment_method_monei_apple_google"]'
234+
);
235+
if ( ! label ) {
236+
return;
237+
}
238+
232239
if ( isApple ) {
233-
const label = document.querySelector(
234-
'label[for="payment_method_monei_apple_google"]'
235-
);
236-
if ( label ) {
237-
label.childNodes[ 0 ].nodeValue = 'Apple Pay ';
238-
const icon = label.querySelector( 'img' );
239-
if ( icon ) {
240-
icon.src = wc_monei_apple_google_params.appleLogo;
241-
icon.alt = 'Apple Pay';
242-
}
240+
// Use Apple Pay title
241+
const appleTitle =
242+
wc_monei_apple_google_params.applePayTitle || 'Apple Pay';
243+
label.childNodes[ 0 ].nodeValue = appleTitle + ' ';
244+
const icon = label.querySelector( 'img' );
245+
if ( icon ) {
246+
icon.src = wc_monei_apple_google_params.appleLogo;
247+
icon.alt = 'Apple Pay';
243248
}
249+
} else {
250+
// Use Google Pay title
251+
const googleTitle =
252+
wc_monei_apple_google_params.googlePayTitle || 'Google Pay';
253+
label.childNodes[ 0 ].nodeValue = googleTitle + ' ';
244254
}
245255
},
246256
};

includes/admin/monei-apple-google-settings.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,24 @@
3434
'title' => array(
3535
'title' => __( 'Title', 'monei' ),
3636
'type' => 'text',
37-
'description' => __( 'The payment method title a user sees during checkout.', 'monei' ),
37+
'description' => __( 'Generic payment method name shown in order emails, order history, and admin areas. Not displayed on checkout (checkout shows Apple Pay or Google Pay based on device).', 'monei' ),
3838
'default' => __( 'Apple Pay / Google Pay', 'monei' ),
3939
'desc_tip' => true,
4040
),
41+
'apple_pay_title' => array(
42+
'title' => __( 'Apple Pay Title', 'monei' ),
43+
'type' => 'text',
44+
'description' => __( 'Title shown on checkout page for Apple devices (iPhone, iPad, Mac with Safari).', 'monei' ),
45+
'default' => __( 'Apple Pay', 'monei' ),
46+
'desc_tip' => true,
47+
),
48+
'google_pay_title' => array(
49+
'title' => __( 'Google Pay Title', 'monei' ),
50+
'type' => 'text',
51+
'description' => __( 'Title shown on checkout page for non-Apple devices (Android, Chrome, etc).', 'monei' ),
52+
'default' => __( 'Google Pay', 'monei' ),
53+
'desc_tip' => true,
54+
),
4155
'hide_title' => array(
4256
'title' => __( 'Hide Title', 'monei' ),
4357
'type' => 'checkbox',

src/Gateways/Blocks/MoneiAppleGoogleBlocksSupport.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,25 @@ public function get_payment_method_data() {
9797
$logoApple = WC_Monei()->plugin_url() . '/public/images/apple-logo.svg';
9898
$logoGoogle = WC_Monei()->plugin_url() . '/public/images/google-logo.svg';
9999
$payment_request_style = $this->get_setting( 'payment_request_style' ) ?? '{"height": "42"}';
100-
$data = array(
101-
'title' => $this->gateway->title,
100+
101+
// Get separate titles with fallback to defaults
102+
$apple_pay_title = $this->get_setting( 'apple_pay_title' );
103+
$google_pay_title = $this->get_setting( 'google_pay_title' );
104+
105+
// Use specific titles if set, otherwise fall back to defaults
106+
$apple_pay_title = ! empty( $apple_pay_title ) ? $apple_pay_title : __( 'Apple Pay', 'monei' );
107+
$google_pay_title = ! empty( $google_pay_title ) ? $google_pay_title : __( 'Google Pay', 'monei' );
108+
109+
// Add test mode suffix if enabled
110+
if ( $this->gateway->getTestmode() ) {
111+
$test_suffix = ' (' . __( 'Test Mode', 'monei' ) . ')';
112+
$apple_pay_title .= $test_suffix;
113+
$google_pay_title .= $test_suffix;
114+
}
115+
116+
$data = array(
117+
'applePayTitle' => $apple_pay_title,
118+
'googlePayTitle' => $google_pay_title,
102119
'description' => $this->gateway->description === ' ' ? '' : $this->gateway->description,
103120
'logoGoogle' => $isGoogleEnabled ? $logoGoogle : false,
104121
'logoApple' => $isAppleEnabled ? $logoApple : false,

src/Gateways/PaymentMethods/WCGatewayMoneiAppleGoogle.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,22 @@ public function monei_scripts() {
203203
// Determine the total amount to be passed
204204
$total = $this->determineTheTotalAmountToBePassed();
205205
$payment_request_style = $this->get_option( 'payment_request_style', '{"height": "50px"}' );
206+
207+
// Get separate titles with fallback to defaults
208+
$apple_pay_title = $this->get_option( 'apple_pay_title', __( 'Apple Pay', 'monei' ) );
209+
$google_pay_title = $this->get_option( 'google_pay_title', __( 'Google Pay', 'monei' ) );
210+
211+
// Use specific titles if set, otherwise fall back to defaults
212+
$apple_pay_title = ! empty( $apple_pay_title ) ? $apple_pay_title : __( 'Apple Pay', 'monei' );
213+
$google_pay_title = ! empty( $google_pay_title ) ? $google_pay_title : __( 'Google Pay', 'monei' );
214+
215+
// Add test mode suffix if enabled
216+
if ( $this->testmode ) {
217+
$test_suffix = ' (' . __( 'Test Mode', 'monei' ) . ')';
218+
$apple_pay_title .= $test_suffix;
219+
$google_pay_title .= $test_suffix;
220+
}
221+
206222
wp_localize_script(
207223
'woocommerce_monei_apple_google',
208224
'wc_monei_apple_google_params',
@@ -212,6 +228,8 @@ public function monei_scripts() {
212228
'total' => monei_price_format( $total ),
213229
'currency' => get_woocommerce_currency(),
214230
'appleLogo' => WC_Monei()->image_url( 'apple-logo.svg' ),
231+
'applePayTitle' => $apple_pay_title,
232+
'googlePayTitle' => $google_pay_title,
215233
'paymentRequestStyle' => json_decode( $payment_request_style ),
216234
)
217235
);

0 commit comments

Comments
 (0)