我正在尝试在商品Feed中设置数字格式,以删除千位分隔符,我使用了以下代码:
$attributes['Price'] = number_format( $attributes['Price'], 2, '.', ',');
但是对于1.399,00的原始价格,我在Feed中得到的是
<Price>1,40</Price>
我有点迷茫,请帮忙吗?
完整代码
function alter_feed_price_item_remove_thousand_seperator( $attributes,
$feed_id, $product_id ) {
global $product;
$product = wc_get_product( $product_id );
// show price without thousand separator
$attributes['price'] = number_format( $attributes['price'], 2, ',', '') . " EUR";
// price will look like 1234,57
// IMPORTANT! Always return the $attributes
return $attributes;}
add_filter( 'wppfm_feed_item_value', 'alter_feed_price_item_remove_thousand_seperator', 10, 3 );
答案 0 :(得分:0)
$attributes['Price'] = (double)str_replace(',', '', $attributes['Price']);
答案 1 :(得分:0)
function alter_feed_price_item_remove_thousand_seperator( $attributes, $feed_id, $product_id) {
global $product;
$product = wc_get_product( $product_id );
if ($attributes['Sale_Price'] >= 1 && $attributes['Sale_Price'] < 2) {
$attributes['Sale_Price'] = sprintf(($attributes['Sale_Price'])*1000). ",00";
}
if ($attributes['Sale_Price'] >= 2 && $attributes['Sale_Price'] < 3) {
$attributes['Sale_Price'] = sprintf(($attributes['Sale_Price'])*1000). ",00";
}
if ($attributes['Price'] > 1 && $attributes['Price'] < 2) {
$attributes['Price'] = sprintf(($attributes['Price'])*1000). ",00";
}
if ($attributes['Price'] > 2 && $attributes['Price'] < 3) {
$attributes['Price'] = sprintf(($attributes['Price'])*1000). ",00";
}
return $attributes;
}
add_filter( 'wppfm_feed_item_value', 'alter_feed_price_item_remove_thousand_seperator', 10, 3 );