admin管理员组文章数量:1122846
/*
* Disable buying products from specific category and tag
*
* @author Misha Rudrastyh
* @url .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 products with tag called available
and make add to cart button hidden on rest of the products on WooCommerce.
I have tried to enable add to cart button on the selected products with tag available but it doesn't disable other products.
/*
* 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 products with tag called available
and make add to cart button hidden on rest of the products on WooCommerce.
I have tried to enable add to cart button on the selected products with tag available but it doesn't disable other products.
Share Improve this question edited 1 hour ago CPlus 4,56441 gold badges30 silver badges70 bronze badges asked Dec 25, 2024 at 16:36 Eiman MaghfouriEiman Maghfouri 213 bronze badges1 Answer
Reset to default 1To make all products unavailable on WooCommerce except those with the tag available, you need to make is purchasable false before you make it true only if your condition is met.
/*
* 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 ) {
$is_purchasable = false;
// Second – check product tags
if( has_term( 'available', 'product_tag', $product->get_id() ) ) {
$is_purchasable = true;
}
return $is_purchasable;
}
本文标签: phpDisable products purchases that don39t have specific tags in WooCommerceStack Overflow
版权声明:本文标题:php - Disable products purchases that don't have specific tags in WooCommerce - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736287406a1927872.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论