首页 > 解决方案 > 在 WooCommerce 中的价格之前添加正常价格

问题描述

我正在为 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;
}

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

标签: phpwordpresswoocommerce

解决方案


您不能在引号内使用 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() 函数格式化价格。


推荐阅读