54
A freelance client sells two distinct products on the same website: a membership and an online course. Two different audiences, different formats and… different Terms & Conditions.
The goal was therefore to display the “Terms & Conditions” checkbox on the Checkout page based on the product in the cart. Once again, we’re going to use Conditional Logic. With that, the snippet is pretty easy to code!
PHP Snippet: Terms & Conditions by Product – WooCommerce Checkout
/**
* @snippet Terms & Conditions by Product - WooCommerce Checkout
* @how-to Get tutoraspire.com FREE
* @author Tutor Aspire
* @testedwith WooCommerce 3.6.5
* @donate $9 https://tutoraspire.com
*/
add_action( 'woocommerce_review_order_before_submit', 'tutoraspire_add_checkout_per_product_terms', 9 );
function tutoraspire_add_checkout_per_product_terms() {
// Show Terms 1
$product_id_1 = 522;
$product_cart_id_1 = WC()->cart->generate_cart_id( $product_id_1 );
$in_cart_1 = WC()->cart->find_product_in_cart( $product_cart_id_1 );
if ( $in_cart_1 ) {
?>
cart->generate_cart_id( $product_id_2 );
$in_cart_2 = WC()->cart->find_product_in_cart( $product_cart_id_2 );
if ( $in_cart_2 ) {
?>