0
对不起,我有点新手在PHP,但我想知道如果有人能够指出我在正确的方向。我创建了一个完美的功能。它仅用于woocommerce并仅用于某个类别,删除“添加到购物车”按钮并替换为指向另一个页面的链接。这个类别中有一种产品需要忽略该功能。工作代码是:php代码 - woocommerce忽略产品
function fishing_buttons(){
// die early if we aren't on a product
if (! is_product()) return;
$product = get_product();
if (has_term('fishing', 'product_cat')){
// removing the purchase buttons
remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
remove_action('woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30);
remove_action('woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30);
remove_action('woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30);
remove_action('woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30);
// adding our own custom text
add_action('woocommerce_after_shop_loop_item', 'fishing_priceguide');
add_action('woocommerce_single_product_summary', 'fishing_priceguide', 30);
add_action('woocommerce_simple_add_to_cart', 'fishing_priceguide', 30);
add_action('woocommerce_grouped_add_to_cart', 'fishing_priceguide', 30);
add_action('woocommerce_variable_add_to_cart', 'fishing_priceguide', 30);
add_action('woocommerce_external_add_to_cart', 'fishing_priceguide', 30);} // fishing_buttons
add_action('wp', 'fishing_buttons');
/**
* Our custom button
*/
function fishing_priceguide(){
echo do_shortcode('[pl_button type="fish" link="http://localhost:8888/fish/fishing-price-guide/"]View our price guide[/pl_button]');
} // fishing_priceguide
产品ID是1268,我想忽略(即保持添加到购物车按钮)。 if语句中是否可以包含'和'条件?我试过 if (has_term('fishing', 'product_cat') && product_id != '1268'){
但是还没有成功
完美。这对我来说是诀窍。谢谢 –