WooCommerce: Deposit Payment @ Order Pay Page

In WooCommerce, the order pay page is a specific webpage a customer lands on to complete payment for an order. It’s typically used for manual orders.

When a store admin creates an order in the WooCommerce backend, the system generates a unique URL for the order pay page. This link can then be shared with the customer via email or other means, allowing them to submit payment.

The question is – what if we want the customer to pay a deposit / first installment / partial payment on the Order Pay page (say the order total is $999, and you want them to pay $111 only)?

Well, we could use a URL parameter – if that’s present and the value is lower than the order total, we can “filter” the order total and let the customer pay whatever amount. Let’s see how it’s done!

As you can see, the order total is $997 but I managed to force the payment due to $111, thanks to the snippet below and a URL parameter. This is the “Order Pay” page for a pending WooCommerce order.

PHP Snippet: Force Deposit Payment @ WooCommerce Order Pay Page

Order Pay page URLs look like e.g. https://example.com/checkout/order-pay/123456/?pay_for_order=true&key=wc_order_Lertgern4556454DFG4a – as you can see, it already comes with URL parameters!

All we need to do now is add one more parameter – for example “dep” or whatever you wish – followed by an amount that must be less than the order total ($999 in our example): &dep=111

Final URL will be https://example.com/checkout/order-pay/123456/?pay_for_order=true&key=wc_order_Lertgern4556454DFG4a&dep=111

Now that we have “dep” and its “111” value in the URL, we can use the snippet below to alter the order total on the go:

/**
 * @snippet       Deposit Payment @ WooCommerce Order Pay
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 8
 * @community     https://businessbloomer.com/club/
 */

add_filter( 'woocommerce_order_get_total', 'bbloomer_order_pay_deposit', 9999, 2 );

function bbloomer_order_pay_deposit( $total, $order ) {
	if ( is_checkout_pay_page() && isset( $_GET['dep'] ) ) {
		return (int) $_GET['dep'];
	}
	return $total;
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *