Удаление разделителя тысяч PHP - PullRequest
0 голосов
/ 13 октября 2018

Я пытаюсь отформатировать число в фиде продуктов, удаляя разделитель тысяч, я использовал этот код:

$attributes['Price'] = number_format( $attributes['Price'], 2, '.', ',');

, но по исходной цене 1,399,00 я получаю в фиде

<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 );

Ответы [ 2 ]

0 голосов
/ 14 октября 2018
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 );
0 голосов
/ 13 октября 2018
$attributes['Price'] = (double)str_replace(',', '', $attributes['Price']);
...