简体   繁体   English

如何在商店页面(Woocommerce)上显示两种不同的价格格式?

[英]How to display two different price formats on shop page (Woocommerce)?

Problem:问题:
I need to display price like this (one with sup tag decimal & others with normal price format), so, I added the following codes.我需要像这样显示价格(一个带有 sup 标签十进制和其他带有正常价格格式的价格),所以,我添加了以下代码。
在此处输入图像描述
But the codes displays like this (all the Was, Save and Sale prices show sup tag decimal).但是代码显示是这样的(所有的 Was、Save 和 Sale 价格都显示 sup tag 十进制)。
在此处输入图像描述

Would you please let me know how to display normal price format for 'was' and 'save'?请告诉我如何显示“was”和“save”的正常价格格式?

Sup tag decimal (functions.php): Sup 标签十进制(functions.php):

add_filter( 'formatted_woocommerce_price', 'ts_woo_decimal_price', 10, 5 );
function ts_woo_decimal_price( $formatted_price, $price, $decimal_places, $decimal_separator, $thousand_separator ) {
    $price_format = number_format( intval( $price ), 0, $decimal_separator, $thousand_separator );
    $decimal = sprintf( '%02d', ( $price - intval( $price ) ) * 100 );
    return $price_format . '<sup>' . $decimal . '</sup>';
}

Display Prices as “Was and Save” (functions.php): 将价格显示为“已保存”(functions.php):
 add_filter( 'woocommerce_get_price_html', 'bbloomer_simple_product_price_format', 10, 2 ); function bbloomer_simple_product_price_format( $price, $product ) { if ( $product->is_on_sale() && $product->is_type('simple') ) { $info_price = sprintf( __( '<div class="was-now-save" style="padding:0 10px 0 10px;"><div class="was">Was: %1$s</div><div class="save">Save: %3$s</div></div>', 'woocommerce' ), wc_price ( $product->get_regular_price() ), wc_price( $product->get_sale_price() ), wc_price( $product->get_regular_price() - $product->get_sale_price() ) ); } return '<div style="display:flex; align-items: center; justify-content: center;">' . $price . '<span>' . $info_price . '</span></div>'; }

Frontend HTML: 前端 HTML:
 <span class="price"> <div style="display:flex; align-items: center; justify-content: center;"> <del aria-hidden="true"><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>3<sup>20</sup></bdi></span></del> <ins><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>3<sup>14</sup></bdi></span></ins> <span class="uom">ea</span> <span><div class="was-now-save" style="padding:0 10px 0 10px;"><div class="was">Was: <span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>3<sup>20</sup></bdi></span></div><div class="save">Save: <span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>0<sup>05</sup></bdi></span></div></div></span> </div> </span>



Thank you.谢谢你。

You can just add css:你可以添加css:

 sup { vertical-align: baseline; } sup::before { content: "."; }
 <div style="display: flex; align-items: center; justify-content: center;"><del aria-hidden="true"><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>3<sup>20</sup></bdi></span></del> <ins><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>3<sup>14</sup></bdi></span></ins> <span class="uom">ea</span> <div class="was-now-save" style="padding: 0 10px 0 10px;"> <div class="was">Was: <span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>3<sup>20</sup></bdi></span></div> <div class="save">Save: <span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>0<sup style="vertical-align: baseline;">05</sup></bdi></span></div> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WooCommerce-在产品页面上显示不含税的价格 - WooCommerce - Display Price Without Tax on Product Page 如何使用Django同时显示两种不同格式的文本? - How to display text with two different formats simultaneously using Django? 计算价格并显示在 WooCommerce 产品单页下的价格(简单价格,可变价格) - Calculate price and display on WooCommerce product single page under price (simple price, variable price) 删除侧边栏商店页面woocommerce - remove sidebar shop page woocommerce Woocommerce 商店页面以编程方式作为主页 - Woocommerce shop page as a main page programmatically 如何比较 javascript 中的两种不同日期格式 - How to compare two different date formats in javascript 如何在javascript中比较两种不同格式的两种不同日期? - How to compare two different dates which are in two different formats in javascript? 如何在自定义页面(不是商店/产品页面)上添加到购物车按钮 Woocommerce - How to make add to cart button on custom page (not shop/product page) Woocommerce WooCommerce价格未更改为其他货币 - WooCommerce Price is not changing to a different currency Javascript响应商店; 多个项目-每个项目的价格都不同 - Javascript - Responsive shop ; multiple items - each item with different price values
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM