Customizting the "Place order" button on the Block Checkout #9337
Replies: 8 comments 1 reply
-
Hi @InpsydeNiklas thanks for the post, I have a few comments to make here:
const activePaymentMethod = useSelect( ( select ) => {
return select( 'wc/store/payment').getActivePaymentMethod();
} ); I don't believe we emit any events when this changes, however checking the data store again after a change will yield the new gateway's name.
Is this because you want to change what happens on the
We have two levels of validation actually, one on the client, and one on the server. If you take a look at this data store documentation. Using When posting to the server, the Store API checks on the expected vs. actual values of all fields and will not process the checkout if any are incorrect.
I don't fully understand this, could you share a little more information on this to help clarify?
What are "hosted fields"? Are these fields specified by PayPal? Do they need to be sent in the Checkout post request too? |
Beta Was this translation helpful? Give feedback.
-
Hi @opr, thanks for your input. Here is a bit more context: Our payment provider provides multiple different custom payment buttons in an iframe.
Which payment buttons our provider returns depends on factors like geolocation. Buyers only get presented with the payment buttons that are relevant to them and the ones they are not eligible for will not be displayed. But in that case, there would still be the regular "Place order" button which would not work for this gateway with the custom iframe button. We can make the "Place order" button trigger an error when clicked, but that's not an ideal user experience.
If this event is relevant or not depends on how the "Place order" button would be handled. Detecting the gateway changes is part of the approach for the shortcode Checkout page, but if there was something more simple like a
We must use these custom iframe buttons for the payment process, so ways to style the regular "Place order" button would not be sufficient. When the buyer clicks the custom iframe button, the form fields are validated and a popup window opens from where the payment process is completed. After confirming the payment in the popup window, the popup window closes, and the buyer is forwarded to the order-received page without any additional interaction on the Block Checkout page.
Thanks! As far as I can tell, triggering the validation with the custom iframe buttons should work fine but haven't tested it yet.
Hosted fields are essentially iframes rendered inside of regular form fields that can be styled with CSS. They are used by various payment providers (including PayPal) to provide merchants with more flexibility, e.g. to style their card fields to match their brand styling. I hope this additional context helps! |
Beta Was this translation helpful? Give feedback.
-
Hi thanks for the additional context, it's super helpful, and thanks for your patience waiting for my reply while I've been AFK. I am currently writing up a more technical discussion for this, but before I get too into it, I'm wondering why the following flow won't work for your use case?
const onPaymentSetupUnsubscribe = onPaymentSetup( async () => {
let isLoginComplete = false;
const setLoginComplete = () => {
isLoginComplete = true;
};
window.customNamespace.setLoginComplete = setLoginComplete;
await new Promise( ( resolve ) => {
window.open(
'/popup.html',
'_blank',
'width=600,height=600,popup=yes'
);
setInterval( () => {
if ( isLoginComplete ) {
resolve();
}
}, 1000 );
} );
} ); Welcome to the popup login page
<script>
const onLoginClick = () => {
window.opener.setLoginComplete();
window.close();
}
</script>
<button onClick="onLoginClick()">Log in</button>
This is just example code and is super crude, but in theory would this allow you to achieve what you want? If not, what are the barriers here, and why would replacing the place order button allow you to overcome them? |
Beta Was this translation helpful? Give feedback.
-
Hi @opr Thanks for your suggestions.
Unfortunately, this approach is not feasible because the custom iframe button's styling is controlled remotely by the payment provider. It's not just about styling the button for branding purposes either; the button dynamically updates its functionality based on the context for each website visitor individually. This button may display different labels or even additional menus depending on the payment methods the buyer has previously saved. Therefore, we have no choice but to use this specific custom iframe button instead of the regular "Place order" button. The custom iframe button can do everything the "Place order" button could, but not the other way around. The payment process works seamlessly with the custom iframe button in the Express Checkout section at the top of the page or, as shown in the first example screenshot, from the gateway description area. However, in the latter case, the existing "Place order" button creates a confusing user experience because it is technically incapable of initiating the payment process for each unique situation. The ideal solution would be to replace the "Place order" button with the custom iframe button, while the next best option would be to hide the regular button when our custom payment gateway is selected. Unfortunately, there doesn't seem to be a way to integrate the regular "Place order" button into the payment process without significantly compromising the user experience. |
Beta Was this translation helpful? Give feedback.
-
With these custom iframe buy buttons, how can you be sure the order is placed on the system before payment? In the old checkout modal this seems like you'd have a payment step after the order is placed i.e. the button would be rephrased as "continue to payment" and a next step would have the iframe and payment controls. We don't have something like this in blocks now, but is it needed? |
Beta Was this translation helpful? Give feedback.
-
With our custom payment gateway, the payment process is initiated before the WooCommerce order is created. This differs from the traditional flow, where an order is created first and then the customer is redirected to the payment provider's website.
Here's how our process works on the shortcode Checkout page:
So first, the payment process is initiated, then the WooCommerce order is created, and then payment will be completed only when we capture it in We've successfully implemented this payment process with the custom iframe buttons on the Block Cart and Block Express Checkout sections, using |
Beta Was this translation helpful? Give feedback.
-
@InpsydeNiklas is there anything blocking you from using the Express Payments area for your implementation? |
Beta Was this translation helpful? Give feedback.
-
Hi @InpsydeNiklas we're going to close this discussion and keep #9432 open to collect further feedback/updates, please post there if you have more to add. Thanks! |
Beta Was this translation helpful? Give feedback.
-
To fully integrate our custom payment gateway with the WooCommerce Blocks Checkout page, we must be able to:
Our biggest challenge is customizing the "Place order" button per gateway.
The ability to modify this button may be needed for certain payment providers to work similarly to the already established solutions on the shortcode Checkout page.
Beta Was this translation helpful? Give feedback.
All reactions