WooCommerce Subscriptions Terms and Conditions

0.0/5
<?php
/**
 * @snippet       Terms & Conditions by Product - WooCommerce Checkout
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @sourcecode    https://businessbloomer.com/?p=72828
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.3.1
 */
  
add_action( 'woocommerce_review_order_before_submit', 'bbloomer_add_checkout_per_product_terms', 9 );
   
function bbloomer_add_checkout_per_product_terms() {
 
// Show Terms 1
$product_id_1 = 10686;
$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 ) {
      
?>
  
<div class="woocommerce-terms-and-conditions-wrapper">

<label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
<input type="checkbox" class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox" name="terms-1" <?php checked( apply_filters( 'woocommerce_terms_is_checked_default', isset( $_POST['terms-1'] ) ), true ); ?> id="terms"> <span>Souhlasím s podmínkami opakovaných plateb</span> <span class="required">*</span>
</label>
<input type="hidden" name="terms-1-field" value="true">
</div>
  
<?php
 
}
 
// Show Terms 2
$product_id_2 = 2152;
$product_cart_id_2 = WC()->cart->generate_cart_id( $product_id_2 );
$in_cart_2 = WC()->cart->find_product_in_cart( $product_cart_id_2 );
 
if ( $in_cart_2 ) {
      
?>
 
<p class="form-row terms wc-terms-and-conditions">
<label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
<input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" name="terms-2" <?php checked( apply_filters( 'woocommerce_terms_is_checked_default', isset( $_POST['terms-2'] ) ), true ); ?> id="terms-2"> <span>I agree to <a href="____" target="_blank">terms-2</a></span> <span class="required">*</span>
</label>
<input type="hidden" name="terms-2-field" value="true">
</p>
  
<?php
 
}
?>

<div class="woocommerce-terms-and-conditions-wrapper">

<label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
<input type="checkbox" class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox" name="terms-3" <?php checked( apply_filters( 'woocommerce_terms_is_checked_default', isset( $_POST['terms-3'] ) ), true ); ?> id="terms"> <span>Je mi více než 18 let</span> <span class="required">*</span>
</label>
<input type="hidden" name="terms-3-field" value="true">
</div>

<?php
  
 
}
  
// Show notice if customer does not tick either terms
 
add_action( 'woocommerce_checkout_process', 'bbloomer_not_approved_terms_1' );
add_action( 'woocommerce_checkout_process', 'bbloomer_not_approved_terms_2' );
add_action( 'woocommerce_checkout_process', 'bbloomer_not_approved_terms_3' );
  
function bbloomer_not_approved_terms_1() {
    if ( $_POST['terms-1-field'] == true ) {
        if ( empty( $_POST['terms-1'] ) ) {
            wc_add_notice( __( 'Je třeba souhlasit s podmínkami opakovaných plateb!' ), 'error' );          
        }
    }
}
 
function bbloomer_not_approved_terms_2() {
    if ( $_POST['terms-2-field'] == true ) {
        if ( empty( $_POST['terms-2'] ) ) {
            wc_add_notice( __( 'Please agree to terms-2' ), 'error' );          
        }
    }
}

function bbloomer_not_approved_terms_3() {
    if ( $_POST['terms-3-field'] == true ) {
        if ( empty( $_POST['terms-3'] ) ) {
            wc_add_notice( __( 'Je vám více než 18 let?' ), 'error' );          
        }
    }
}

Comments and reviews

{{ reviewsTotal }} Review
{{ reviewsTotal }} Reviews
{{ options.labels.newReviewButton }}
{{ userData.canReview.message }}

Description

This snippet was fetched automatically from WPDistro.cz projects.

Author

Tags

This snippet is untagged