php - 在 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;
}
有人可以帮我使用正确的语法吗?
解决方案
您不能在引号内使用 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() 函数格式化价格。
推荐阅读
- google-cloud-platform - 无法为 Cloud SQL 设置高可用性
- django - 使用 djangoORM 在视图集中使用 Q() 和 filter() 创建合并查询时出错
- ios - 是否可以从其父视图的边界中取消剪辑单个子视图?
- java - 生成的 SQL 中超出范围的不相关实体的 Hibernate JOIN
- python - 试图遍历我的文件夹中的每个 tif 图像,这是目录
- python - 在线程完成执行后执行函数
- android - 使用 Gson 解析后将嵌套的 JSON 数组插入 SQLite
- plc - 按索引返回字符串的一个字符的语法
- bash - 使用 shell 脚本的回文
- sql - 删除存储过程中的所有 NULL 值