informatique:wordpress:case_a_cocher_personnalisees_pour_une_categorie_de_produits_specifique_dans_woocommerce
Table des matières
Case A Cocher Personnalisees Pour Une Categorie De Produits Specifique Dans Woocommerce
Date de création : 2022/03/28 15:33
Cette page a pour source partielle ou intégrale la page suivante:
Version standard
add_action('woocommerce_review_order_before_submit', 'add_pipletz_terms', 9 ); function add_pipletz_terms() { $special_cat = 'insurance'; // HERE set your special category name, slug or ID $bool = false; foreach ( WC()->cart->get_cart() as $cart_item ) { // compatibility with WC +3 $product_id = version_compare( WC_VERSION, '3.0', '<' ) ? $cart_item['data']->id : $cart_item['data']->get_id(); if ( has_term( $special_cat, 'product_cat', $product_id ) ){ $bool = true; break; // added this too } } if ( $bool ) { $link = 'https://businessbloomer.com/woocommerce-display-product-specific-tc-checkout/'; ?> <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 pipletz-terms" name="pipletz-terms" <?php checked( apply_filters( 'woocommerce_terms_is_checked_default', isset( $_POST['pipletz-terms'] ) ), true ); ?> id="pipletz-terms"> <span> <a href="<?php echo $link; ?>" target="_blank">I’ve read and accept the Pipletz product terms & conditions</a> </span> <span class="required">*</span> </label> </p> <?php } } // If customer does not agree to terms add_action('woocommerce_checkout_process', 'not_approved_pipletz_terms'); function not_approved_pipletz_terms() { $special_cat = 'insurance'; // HERE set your special category name, slug or ID $bool = false; // Checking again if the category is in one cart item foreach ( WC()->cart->get_cart() as $cart_item ) { // compatibility with WC +3 $product_id = version_compare( WC_VERSION, '3.0', '<' ) ? $cart_item['data']->id : $cart_item['data']->get_id(); if ( has_term( $special_cat, 'product_cat', $product_id ) ){ $bool = true; break; // added this too } } if ( empty( $_POST['pipletz-terms'] ) && $bool ) wc_add_notice( __( 'Please agree to the Pipletz product terms & conditions' ), 'error' ); }
Version Alcool
add_action('woocommerce_review_order_before_submit', 'add_alcohol_terms', 9); function add_alcohol_terms() { $special_cat = 'alcools'; // HERE set your special category name, slug or ID $bool = false; foreach (WC()->cart->get_cart() as $cart_item) { // compatibility with WC +3 $product_id = version_compare(WC_VERSION, '3.0', '<') ? $cart_item['data']->id : $cart_item['data']->get_id(); if (has_term($special_cat, 'product_cat', $product_id)) { $bool = true; break; // added this too } } if ($bool) { ?> <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 alcohol-terms" name="alcohol-terms" <?php checked(apply_filters('woocommerce_terms_is_checked_default', isset($_POST['alcohol-terms'])), true); ?> id="alcohol-terms"> <span>Je certifie avoir l'âge légal pour consommer de l’alcool</span> <span class="required">*</span><br>I certify that I am of legal age to consume alcohol<span class="required">*</span> </label> </p> <?php } } // If customer does not agree to terms add_action('woocommerce_checkout_process', 'not_approved_alcohol_terms'); function not_approved_alcohol_terms() { $special_cat = 'alcools'; // HERE set your special category name, slug or ID $bool = false; // Checking again if the category is in one cart item foreach (WC()->cart->get_cart() as $cart_item) { // compatibility with WC +3 $product_id = version_compare(WC_VERSION, '3.0', '<') ? $cart_item['data']->id : $cart_item['data']->get_id(); if (has_term($special_cat, 'product_cat', $product_id)) { $bool = true; break; // added this too } } if (empty($_POST['alcohol-terms']) && $bool) wc_add_notice(__('Veuillez accepter les termes et conditions de l\'alcool <br>Please agree to the alcohol terms & conditions'), 'error'); }
Version Alcool avec multi des langues
add_action('woocommerce_review_order_before_submit', 'add_alcohol_terms', 9); function add_alcohol_terms() { if (pll_current_language() == 'en') { $special_cat = 'alcohol'; } elseif (pll_current_language() == 'fr') { $special_cat = 'alcool'; }elseif (pll_current_language() == 'de') { $special_cat = 'alkohol'; } $bool = false; foreach (WC()->cart->get_cart() as $cart_item) { // compatibility with WC +3 $product_id = version_compare(WC_VERSION, '3.0', '<') ? $cart_item['data']->id : $cart_item['data']->get_id(); if (has_term($special_cat, 'product_tag', $product_id)) { $bool = true; break; // added this too } } if ($bool) { ?> <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 alcohol-terms" name="alcohol-terms" <?php checked(apply_filters('woocommerce_terms_is_checked_default', isset($_POST['alcohol-terms'])), true); ?> id="alcohol-terms"> <?php if (pll_current_language() == 'en') { ?><span>I certify that I am of legal age to consume alcohol.</span> <span class="required">*</span> <?php } elseif (pll_current_language() == 'fr') { ?><span>Je certifie avoir l'âge légal pour consommer de l’alcool.</span> <span class="required">*</span> <?php } elseif (pll_current_language() == 'de') { ?><span>Ich bestätige, dass ich das gesetzlich vorgeschriebene Alter für den Konsum von Alkohol habe.</span> <span class="required">*</span> <?php }; ?> </label> </p> <?php } } // If customer does not agree to terms add_action('woocommerce_checkout_process', 'not_approved_alcohol_terms'); function not_approved_alcohol_terms() { if (pll_current_language() == 'en') { $special_cat = 'alcohol'; } elseif (pll_current_language() == 'fr') { $special_cat = 'alcool'; }elseif (pll_current_language() == 'de') { $special_cat = 'alkohol'; } $bool = false; // Checking again if the category is in one cart item foreach (WC()->cart->get_cart() as $cart_item) { // compatibility with WC +3 $product_id = version_compare(WC_VERSION, '3.0', '<') ? $cart_item['data']->id : $cart_item['data']->get_id(); // verifie si la catégorie correspond à la catégorie spéciale if (has_term($special_cat, 'product_tag', $product_id)) { $bool = true; break; // added this too } } if (empty($_POST['alcohol-terms']) && $bool) if (pll_current_language() == 'en') { wc_add_notice(__('Please agree to the alcohol terms & conditions'), 'error'); } elseif (pll_current_language() == 'fr') { wc_add_notice(__('Veuillez accepter les termes et conditions de l\'alcool'), 'error'); } elseif (pll_current_language() == 'de') { wc_add_notice(__('Bitte akzeptieren Sie die Allgemeinen Geschäftsbedingungen für Alkohol'), 'error'); } }
Page dans la catégorie:
informatique/wordpress/case_a_cocher_personnalisees_pour_une_categorie_de_produits_specifique_dans_woocommerce.txt · Dernière modification : 2022/04/10 17:26 de 127.0.0.1