Skip to content

Commit c1fc945

Browse files
authored
Move checkout field to top when Link enabled (#2380)
Move checkout field to top when Link enabled
1 parent 71b5845 commit c1fc945

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

assets/css/stripe-link.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.stripe-gateway-checkout-email-field {
2+
position: relative;
3+
}
4+
5+
.stripe-gateway-checkout-email-field button.stripe-gateway-stripelink-modal-trigger {
6+
display: none;
7+
position: absolute;
8+
right: 5px;
9+
width: 64px;
10+
height: 40px;
11+
background: no-repeat
12+
url( '../../client/payment-method-icons/link/icon.svg' );
13+
background-color: none;
14+
cursor: pointer;
15+
border: none;
16+
}

includes/payment-methods/class-wc-stripe-upe-payment-gateway.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ public function payment_scripts() {
260260

261261
wp_enqueue_script( 'wc-stripe-upe-classic' );
262262
wp_enqueue_style( 'wc-stripe-upe-classic' );
263+
264+
wp_register_style( 'stripelink_styles', plugins_url( 'assets/css/stripe-link.css', WC_STRIPE_MAIN_FILE ), [], WC_STRIPE_VERSION );
265+
wp_enqueue_style( 'stripelink_styles' );
263266
}
264267

265268
/**

woocommerce-gateway-stripe.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ public function init() {
242242
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), [ $this, 'plugin_action_links' ] );
243243
add_filter( 'plugin_row_meta', [ $this, 'plugin_row_meta' ], 10, 2 );
244244

245+
// Update the email field position.
246+
add_filter( 'woocommerce_billing_fields', [ $this, 'checkout_update_email_field_priority' ], 50 );
247+
245248
// Modify emails emails.
246249
add_filter( 'woocommerce_email_classes', [ $this, 'add_emails' ], 20 );
247250

@@ -647,6 +650,35 @@ public function get_main_stripe_gateway() {
647650

648651
return $this->stripe_gateway;
649652
}
653+
654+
/**
655+
* Move the email field to the top of the Checkout page.
656+
*
657+
* @param array $fields WooCommerce checkout fields.
658+
*
659+
* @return array WooCommerce checkout fields.
660+
*/
661+
public function checkout_update_email_field_priority( $fields ) {
662+
$is_link_enabled = in_array(
663+
WC_Stripe_UPE_Payment_Method_Link::STRIPE_ID,
664+
$this->stripe_gateway->get_upe_enabled_payment_method_ids(),
665+
true
666+
);
667+
668+
if ( $is_link_enabled ) {
669+
// Update the field priority.
670+
$fields['billing_email']['priority'] = 1;
671+
672+
// Add extra `wcpay-checkout-email-field` class.
673+
$fields['billing_email']['class'][] = 'stripe-gateway-checkout-email-field';
674+
675+
// Append StripeLink modal trigger button for logged in users.
676+
$fields['billing_email']['label'] = $fields['billing_email']['label']
677+
. ' <button class="stripe-gateway-stripelink-modal-trigger"></button>';
678+
}
679+
680+
return $fields;
681+
}
650682
}
651683

652684
$plugin = WC_Stripe::get_instance();

0 commit comments

Comments
 (0)