Home » Php » php – Change dot to comma

php – Change dot to comma

Posted by: admin February 25, 2020 Leave a comment

Questions:

I did a new field to prices on functions to woocommerce.
That field is printing on my database with DOT and i want to print with COMMA.

Wrong: R$ 40.00
Correct: R$ 40,00

function addSlubField() {
    global $post;
$args = array(
  'label' => 'Slub Price', // Text in Label
  'label' => __('Slub Price', 'woocommerce') ,
  'placeholder' => 'Slub Price',
  'class' => 'short',
  'style' => '',
  'wrapper_class' => '',
  'value'=>get_post_meta($post->ID,'slub_price',true),
  'id' => 'slub_price', // required
  'name' => 'slub_price', //name will set from id if empty
  'type' => 'number',
  'desc_tip' => '',
  'data_type' => '',
  'custom_attributes' => array('step'=>'0.01'), // array of attributes
  'description' => ''
);
woocommerce_wp_text_input( $args );
}
add_action( 'woocommerce_product_options_general_product_data', 'addSlubField',1);

add_action( 'woocommerce_process_product_meta', 'save_slub_field' );
function save_slub_field( $post_id ) {

  $custom_field_value = isset( $_POST['slub_price'] ) ? $_POST['slub_price'] : '';

  $product = wc_get_product( $post_id );
  $product->update_meta_data( 'slub_price', $custom_field_value );
  $product->save();
}
How to&Answers: