WooCommerce checkout page with Returns and Refunds Policy checkbox. WooCommerce checkout page with Returns and Refunds Policy checkbox.

How Can I Add a Clickable Link to a Returns and Refunds Policy Checkbox in WooCommerce?

Adding a Custom “”Returns and Refunds Policy”” Checkbox to WooCommerce Checkout Page

You may find that you need to have customers explicitly agree to your website’s “”Returns and Refunds Policy”” before making a purchase through your WooCommerce-powered online store. Fortunately, WooCommerce gives you the ability to add custom checkboxes to your checkout page.

Step-by-Step Guide

Firstly, you’ll need to add code to the functions.php file in your child theme (or in a plugin) in your WordPress admin panel. The functions.php file is where you can add custom functionality to your WordPress website. Remember, if you’re not comfortable editing code, be sure to ask for help from someone experienced in editing PHP files, or consider using a WordPress customization plugin.

This code will add a link to a custom “”Returns and Refunds Policy”” checkbox, just below the Terms and Conditions checkbox on your WooCommerce checkout page. The checkbox will be required, meaning customers cannot complete their purchase without checking this box.

Below, you’ll find the code you need to add:

// Add a custom checkbox to checkout
add_action( ‘woocommerce_review_order_before_submit’, ‘add_custom_checkout_privacy_policy’, 9 );
function add_custom_checkout_privacy_policy() {
// Here define the privacy policy link page URL
$page_link = site_url(‘/privacy-policy/’);

$privacy_text = sprintf( __(""I have read and agree to the website %s"", 'woocommerce'), 
    '['. __(""returns and refunds policy"", 'woocommerce') . ']('. $page_link .')');

printf('


    <p class=""form-row privacy"">
        <input type=""checkbox"" class=""input-checkbox"" name=""privacy_policy"" %s required /> 
         <label for=""privacy_policy"">%s <span class=""required"">*</span></label>
    </p>

‘, checked( isset($_POST[‘privacy_policy’]), true, false ),
$privacy_text, esc_attr__( ‘required’, ‘woocommerce’ ) );
}

// Checkbox validation as it’s a required field
add_action( ‘woocommerce_checkout_process’, ‘validate_custom_checkout_privacy_policy’ );
function validate_custom_checkout_privacy_policy() {
if ( ! isset($_POST[‘privacy_policy’]) ) {
wc_add_notice(‘Please read and accept the returns and refunds policy to proceed with your order.’, ‘error’);
}
}

This piece of code does two things:

  1. Adds a checkbox with a link to your “”Returns and Refunds Policy””.
  2. Validates the checkbox to ensure it has been checked during the checkout process.

How Does This Code Work?

In the first part, the ‘addaction’ function hooks onto ‘woocommercerevieworderbeforesubmit’. This is where you want to add the checkbox on the checkout page. The ‘addcustomcheckoutprivacy_policy’ function then creates and formats your custom checkbox.

The $page_link is your “”Returns and Refunds Policy”” page URL. Be sure to edit it accordingly to reflect the correct URL.

The $privacy_text is the text that will be displayed next to the checkbox. It is formatted to include a link to your “”Returns and Refunds Policy”” page.

In the second part, another action is hooked onto ‘woocommercecheckoutprocess’, where the ‘validatecustomcheckoutprivacypolicy’ function checks whether the checkbox has been ticked. If not, an error message is displayed, informing the customer that they must read and accept the “”Returns and Refunds Policy”” to proceed with their order.

By incorporating these steps into your WordPress site, you’ll help ensure that your customers are aware and accepting of your return and refund protocols, increasing transparency and enhancing buyer confidence.