【问题标题】:Add regular price before price in WooCommerce在 WooCommerce 中的价格之前添加正常价格
【发布时间】:2019-11-27 17:13:33
【问题描述】:

我正在为 WooCommerce 使用多币种插件。价格现在转换为 MKD 第纳尔。现在我想在 (MKD) 价格之前显示正常价格 (USD)。

这是我在 Function.php 中的代码

    add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' );
add_filter( 'woocommerce_cart_item_price', 'cw_change_product_price_display' );
function cw_change_product_price_display( $price ) {
    $text = 'echo $product->get_regular_price;';

    // returning the text before the price
    return $text . ' ' . $price;
}

有人可以帮我使用正确的语法吗?

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    您不能在引号内使用 echo,因为它被解释为普通文本字符串。

    所以你的函数可能看起来像:

    add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' );
    add_filter( 'woocommerce_cart_item_price', 'cw_change_product_price_display' );
    
    function cw_change_product_price_display( $price ) {
         global $product;
    
         // display regular price before the price
         return $product->get_regular_price . ' ' . $price;
    
    }
    

    您还可以使用 wc_price() 函数格式化价格。

    【讨论】:

      猜你喜欢
      • 2017-05-15
      • 2014-05-04
      • 2021-06-19
      • 1970-01-01
      • 1970-01-01
      • 2021-07-24
      • 2018-04-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多