【问题标题】:WooCommerce conditional tag for particular product特定产品的 WooCommerce 条件标签
【发布时间】:2017-09-09 12:37:45
【问题描述】:

WooCommerce Conditional Tags页面提示我们可以找到产品页面何时运行,

但与 is_single 不同的是,它不接受任何参数来表示任何特定的产品名称或 slug。

假设我只想为特定产品运行脚本,

http://localhost/realtour/product/demo-tour-package/

我想在 init 操作挂钩上运行脚本并检查特定产品。我怎样才能做到这一点?

【问题讨论】:

  • 您需要在哪里或在什么脚本中定位特定产品?这个问题不清楚,因为它是......

标签: wordpress woocommerce


【解决方案1】:

is_product 只是is_singular('product') 的包装器

要检查特定产品,您需要检查 ID 或永久链接。

if (is_product()) {

    if (basename(get_permalink()) == 'demo-tour-package') {

        # ...
    }
}

【讨论】:

    猜你喜欢
    • 2020-02-14
    • 2018-04-23
    • 2018-01-30
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-20
    • 1970-01-01
    相关资源
    最近更新 更多