WooCommerce: Alter Payment Gateway Instructions on the Thankyou page

Are you looking to learn the basics of WooCommerce development?
My book "Learning WooCommerce Development by Example" will teach you what you need in a fast and friendly way!

The WooCommerce thank you page displays default instructions¬† for a payment type, here’s an image showing the text that is displayed when an order has been paid using the “Cash on delivery” payment method.

the default payment instructions for the cash on delivery payment gateway

If you’re looking to change or remove this text it can be done without changing any code, if you want to dynamically change the text (to reference an order number or something similar) then that can be done via a code snippet.

In this article we’ll take a look at how to change the text via the admin interface and via a code snippet.

Changing the Instructions via the Admin Interface

If you go to the WooCommerce menu on the left hand side of the Admin screen and choose the “Settings” option then the “Payments” tab you will be shown a list of all the Payment gateways currently set-up for the store.

Click the “Manage” button for the payment method that you want to change the instructions for

click the mange button for the relevant payment method

You should then be taken to a screen that includes a number of text fields, change the “Instructions” field to your desired value and click the “Save Changes” button.

change the instructions field

The new instructions should then start showing on the thank you page when the relevant payment method has been used to make a purchase.

the new instructions showing on the thank you page

Changing the Instructions with a Code Snippet

In most cases changing the instructions via the Admin Interface will probably get you what you want, but let’s imagine¬† a case where we want to display some instructions that tell the customer to quote the order number when making payment. It would be nice if we could include the actual order number in the instructions. Here’s how to do it.

In order to add the text we’ll hook into the woocommerce_thankyou_<payment method> action, if you’d like more details about this I’ve written about the action in an article about the WooCommerce thank you hook.

We’ll use the “cash on delivery” payment method as an example, so the hook we’ll use will be woocommerce_thankyou_cod as “cod” is the id of the “cash on delivery” payment method. You can find out more details of how to find the id for a payment method here.

Here’s the code we’ll use

function hwn_add_payment_instructions_with_order_id($order_id) {
    $gateways = WC()->payment_gateways->payment_gateways(); // gateway instance
    $gateways['cod']->instructions = "Pay with cash upon delivery, please quote the order number " . $order_id . " when you make your payment.";
}

add_action( 'woocommerce_thankyou_cod', 'hwn_add_payment_instructions_with_order_id', 1 );

The last line of the code hooks the hwn_add_payment_instructions_with_order_id function to the woocommerce_thankyou_cod action, the code in the hwn_add_payment_instructions_with_order_id function performs the following steps

  • Uses the global WC() object to access the payment_gateways object then the payment_gateways() function to return a list of all the payment gateways available, the list is stored in the $gateways variable
  • The code then uses the “cod” key to reference the cash on demand payment gateway object, it then changes the instructions property to a dynamic message that contains the order passed into the¬† woocommerce_thankyou_cod action by the code that fired the action.

Once the code has been added to a WooCommerce site then the message will be displayed, as shown in the screenshot below.

payment instructions that include the order id

Final Thoughts

If you’ve made it to the end of this article the you should have discovered two ways to change the instructions for a payment type on the WooCommerce thank you screen. If you have any questions or pointers then please don’t hesitate to leave them in the comments section.

Leave a Comment