根据我原来帖子的答案使用时遇到格式不正确的数值wc_priceWooCommerce 挂钩 https://stackoverflow.com/questions/66084833/a-non-well-formed-numeric-value-encountered-while-using-wc-price-woocommerce-hoo,我现在尝试向该函数添加其他货币,最后将它们全部输出。
我决定使用四列的 DIV 部分,其中 CSS 使其具有响应能力。
.exchanged-price{
float: left;
width: 25%;
padding: 15px;
}
.exchange-rate-wrapper:after{
content: "";
display: table;
clear: both;
}
@media screen and (max-width: 900px){
.exchanged-price{
width: 50%;
}}
@media screen and (max-width: 600px){
.exchanged-price{
width: 100%;
}}
然后我删除了该功能的使用,认为我不需要它。
这是新的代码,这给了我以下错误:
Parse error: syntax error, unexpected 'return' (T_RETURN)
这是新代码:
add_filter( 'wc_price', 'filter_wc_price', 10, 5 );
function filter_wc_price( $return, $price, $args, $unformatted_price, $original_price = null ) {
// EUR
$conversion_rate_eur = (float) 1.25;
$symbol_eur = 'EUR';
$currency_symbol_eur = get_woocommerce_currency_symbol( $symbol_eur );
$euro_price = (float) $price * $conversion_rate_eur;
// return number_format( $euro_price, 2, '.', '' );
// US dollar
$conversion_rate_us = (float) 0.85;
$symbol_us = 'US';
$currency_symbol_us = get_woocommerce_currency_symbol( $symbol_us );
$us_price = (float) $price * $conversion_rate_us;
// return number_format( $us_price, 2, '.', '' );
// GP brittish pound
$conversion_rate_gbp = (float) 1.35;
$symbol_gbp = 'GBP';
$currency_symbol_gbp = get_woocommerce_currency_symbol( $symbol_gbp );
$us_price = (float) $price * $conversion_rate_us;
// return number_format( $us_price, 2, '.', '' );
$exchange_rate_section = '
<div class="exchange-rate-wrapper">
<div class="exchanged-price">
<h2>' return number_format( $euro_price, 2, '.', '' ); '</h2>
</div>
<div class="exchanged-price">
<h2>'return number_format( $us_price, 2, '.', '' ); '</h2>
</div>
<div class="exchanged-price">
<h2>'return number_format( $gbp_price, 2, '.', '' ); '</h2>
</div>
<div class="exchanged-price">
<h2></h2>
</div>
</div>';
return $return . '<br>' . $exchange_rate_section;
}