Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Save and Display Terms Acceptance in WooCommerce Orders?

If a store has set the terms and conditions as shown below in the page setup, then the checkout page will have a compulsory checkbox of ‘Terms and conditions’. So that customers must accept this option before they complete the purchase.

How to Save and Display Terms Acceptance in WooCommerce Orders? - Tyche Softwares

However, by default, WooCommerce doesn’t store any information related to whether a customer has accepted the terms and conditions. This leads you to have no proof of which customer has accepted and who doesn’t. In order to avoid such potential legal issues, you must store the terms acceptance status in the order metadata and display it in the admin panel, emails, and invoices. In this post, we’ll learn how to save and display the acceptance of the terms in the WooCommerce Orders Page.

Solution: Save and Display Terms Acceptance in WooCommerce Orders

The code below will save the order metadata once the customer agrees to the terms and acceptance at checkout. This consent will be displayed at various spots, such as in the WooCommerce admin order details, in the WooCommerce order emails, and in the customer’s My Account order details page.

add_action('woocommerce_checkout_update_order_meta', 'ts_save_terms_consent_to_order', 10, 1);
function ts_save_terms_consent_to_order($order_id) {
    if (!empty($_POST['terms'])) { // Ensure the checkbox is checked
        $order = wc_get_order($order_id);
        $customer_name = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name();
        $consent_text = sprintf('%s accepted the Terms and Conditions on %s',
            $customer_name,
            current_time('Y-m-d H:i:s')
        );

        // Force save using WooCommerce order meta methods
        $order->update_meta_data('_terms_consent', $consent_text);
        $order->save(); // Ensure data is stored
    }
}

// Display Terms & Conditions consent in WooCommerce Admin Order Details
add_action('woocommerce_admin_order_data_after_billing_address', 'ts_display_terms_consent_in_admin');
function ts_display_terms_consent_in_admin($order) {
    $consent_text = get_post_meta($order->get_id(), '_terms_consent', true);
    if ($consent_text) {
        echo '<p><strong>Terms Consent:</strong> ' . esc_html($consent_text) . '</p>';
    }
}

// Display Terms & Conditions consent in WooCommerce Order Emails
add_action('woocommerce_email_after_order_table', 'ts_add_terms_consent_to_emails', 10, 4);
function ts_add_terms_consent_to_emails($order, $sent_to_admin, $plain_text, $email) {
    $consent_text = get_post_meta($order->get_id(), '_terms_consent', true);
    if ($consent_text) {
        if ($plain_text) {
            echo "\nTerms Consent: " . $consent_text . "\n";
        } else {
            echo '<p><strong>Terms Consent:</strong> ' . esc_html($consent_text) . '</p>';
        }
    }
}

// Display Terms & Conditions consent in Customer's Account Order Details
add_action('woocommerce_order_details_after_order_table', 'ts_display_terms_consent_in_account');
function ts_display_terms_consent_in_account($order) {
    $consent_text = get_post_meta($order->get_id(), '_terms_consent', true);
    if ($consent_text) {
        echo '<p><strong>Terms Consent:</strong> ' . esc_html($consent_text) . '</p>';
    }
}

Output

When the customer accepts the terms on the checkout page, the order metadata is saved and displayed at multiple spots. This includes the details that are displayed at WooCommerce admin panel, order confirmation emails, and in the customer’s order details in their My account, as shown in the images below.

How to Save and Display Terms Acceptance in WooCommerce Orders? - Tyche Softwares
WooCommerce admin panel


How to Save and Display Terms Acceptance in WooCommerce Orders? - Tyche Softwares
Order confirmation email
How to Save and Display Terms Acceptance in WooCommerce Orders? - Tyche Softwares
Order details

Now that we’ve covered saving the terms acceptance metadata, you might also want to explore how to add a custom date field in checkout blocks. This can be useful if you need to capture additional delivery details during checkout and display them in relevant order sections.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x