You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在woocommerce_product_meta_start函数中排除指定产品ID

实现方法

你只需要在原有函数的逻辑最开头加入产品ID校验规则即可,操作如下:

  • 先通过global $product获取当前单品页的产品对象
  • 定义你需要排除的2个产品ID数组,将示例中的123、456替换为你实际要排除的产品ID
  • 判断当前产品ID如果属于排除数组,直接终止函数执行,不会输出后续的自定义内容

修改后的完整代码

add_action( 'woocommerce_product_meta_start', 'content_after_addtocart_button' );
function content_after_addtocart_button() {
    // 全局获取当前产品对象
    global $product;
    // 替换为你实际需要排除的2个产品ID
    $exclude_product_ids = [123, 456];
    
    // 属于排除列表的产品直接终止执行
    if ( in_array( $product->get_id(), $exclude_product_ids ) ) {
        return;
    }

    echo '<div class="additional-info"><p><a href="tel:+1-623-931-9965"><span id="et-info-phone">623-931-9965</span></a></p><p>Call us for questions, custom finishes, or to place an order.</p></div><div class="product-summary-image"><a href="https://mcpartsflexpay.com/smt-motorcycle-flexpay/?__hstc=88695364.a91afb3082b76bb991834c6a2202ee7b.1610739322192.1610739322192.1610739322192.1&amp;__hssc=88695364.4.1610739322192&amp;__hsfp=3981434298" target="_blank"><img src="https://www.smtmachining.com/wp-content/uploads/2021/01/FlexPay_Motorcycle-Parts_Financing-CTA.jpg" alt="FlexPay Custom Motorcycle Parts Financing"></a></div>';
}

内容的提问来源于stack exchange,提问作者krskaggs13

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.23 22:15:03