-
Cooper a publié un message
Désactiver les achats de produits qui n'ont pas de tag spécifique dans WooCommerce
Je souhaite modifier ce code
/* * Disable buying products from specific category and tag * * @author Misha Rudrastyh * @url https://rudrastyh.com/woocommerce/make-products-non-purchasable.html#specific-categories */ add_filter( 'woocommerce_is_purchasable', 'misha_catalog_mode_on_for_category', 10, 2 ); function misha_catalog_mode_on_for_category( $is_purchasable, $product ) { // Second – check product tags if( has_term( 'available', 'product_tag', $product->get_id() ) ) { $is_purchasable = true; } return $is_purchasable; }
i want to enable add to cart button only for the post has tag called available and make add to cart button hidden on rest of ther products on woocommerce
can anyone edit this code
thanks in advanced
i have tried to enable add to cart button on the selected products with tag available bu i couldn’t , actually used a plugin of woocommerce called hide price and add to cart button
rudrastyh.com
Rendre les produits non achetables dans WooCommerce
Comment désactiver complètement l'achat de produits sur votre boutique WooCommerce ou seulement les produits avec des ID spécifiques ou dans une certaine catégorie sans plugins.
-
Pour rendre tous les produits indisponibles sur WooCommerce sauf ceux avec la balise available, vous devez rendre is purchasable false avant de le rendre true uniquement si votre condition est remplie.
/*
* Désactiver l'achat de produits d'une catégorie ou d'une étiquette spécifique
*
* @auteur Misha Rudrastyh
* @url https://rudrastyh.com/woocommerce/make-products-non-purchasable.html#specific-categories
*/
add_filter( ‘woocommerce_is_purchasable’, ‘misha_catalog_mode_on_for_category’, 10, 2 );
function misha_catalog_mode_on_for_category( $is_purchasable, $product ) {
$is_purchasable = false;
// Second – check product tags
if( has_term( ‘available’, ‘product_tag’, $product->get_id() ) ) {
$is_purchasable = true;
}
return $is_purchasable;
}
-