【问题标题】:WooCommerce: Product price suffix based on product categoryWooCommerce:基于产品类别的产品价格后缀
【发布时间】:2021-05-19 13:18:29
【问题描述】:

在我的 WooCommerce 网站上,我设置了每半米出售的面料,下面的代码一切正常:

function conditional_price_suffix( $price, $product ) {

    $product_id = $product->is_type('variation') ? $product->get_parent_id() : $product->get_id();

    $product_categories = array('half-metre');

    if( has_product_categories( $product_categories, $product_id ) )
        $price .= ' ' . __('per ½ metre');

    return $price;
}

但是,我如何操作代码以添加另一个选项 per “ Quarter-metre” 并输出 “per ¼ metre” 作为后缀。

有什么帮助吗?

【问题讨论】:

    标签: php wordpress woocommerce product suffix


    【解决方案1】:

    可能是这样的

    function conditional_price_suffix( $price, $product ) {
        $product_id = $product->is_type('variation') ? $product->get_parent_id() : $product->get_id();
        $product_categories = array('half-metre');
        $product_categories2 = array('quarter-metre');
        if( has_product_categories( $product_categories, $product_id ) ) {
            $price .= ' ' . __('per ½ metre');
        } elseif( has_product_categories( $product_categories2, $product_id ) ) {
            $price .= ' ' . __('per ¼ metre');
        }
        return $price;
    }
    

    【讨论】:

      猜你喜欢
      • 2019-04-25
      • 1970-01-01
      • 2021-07-22
      • 1970-01-01
      • 2019-02-12
      • 2019-12-25
      • 2021-08-01
      • 1970-01-01
      • 2019-07-09
      相关资源
      最近更新 更多