-
停用 WooCommerce 中沒有特定標籤的產品購買功能
各位,我想編輯這個程式碼
/* * 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
-
若要讓 WooCommerce 上所有的產品都無法購買,但標籤為 available 的產品除外,您需要先將 is purchasable 設為 false,然後才在符合條件時將它設為 true。
/*
* 禁止購買特定類別和標籤的產品
*
* @作者 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;
}
-