Add text before pay buttons in WooCommerce; snippet

Add text before pay buttons in WooCommerce; snippet

Snippet for adding text before pay buttons on WooCommerce cart (useful for adding terms & conditions messaging).

add_action( 'woocommerce_review_order_after_submit', 'aus120_privacy_message_below_checkout_button' );
function aus120_privacy_message_below_checkout_button() {
   echo '<p>By placing this order, you agree to our <a href="/terms-of-service/" target=_blank">Terms of Service</a>.</p>';
}

The important part is:

woocommerce_review_order_after_submit

This declares where you want the text to appear.

In use at gorillaprinting.com, wheatpasteposters.com, printinglosangeles.com, apaththatfits.com & winenliquor.com.

Here's a breakdown of how it works:

  1. The add_action function is used to hook a custom function (aus120_privacy_message_below_checkout_button) onto a specific action point in WordPress. In this case, the action point is 'woocommerce_review_order_after_submit', which is fired after the "Place Order" button on the WooCommerce checkout page is displayed.

  2. The custom function aus120_privacy_message_below_checkout_button() is defined to output some HTML content using the echo statement. This content is a paragraph (<p>) containing a message and a link to the website's Terms of Service. The link is generated using an anchor (<a>) tag with an href attribute pointing to the "/terms-of-service/" page. The target=_blank attribute is used to open the link in a new browser tab.

When a user views the checkout page on a WooCommerce store, this code will add a paragraph below the "Place Order" button.