1. Home
  2. Knowledge Base
  3. WooCommerce Product Add-Ons Ultimate
  4. Advanced Topics for Add-Ons Ultimate
  5. Cart and Order
  6. Display number field value in price format in cart

Display number field value in price format in cart

If you want to display the value entered by the user in a number field in price format, you can use this snippet:

<?php
/**
* Display the value of a specific field as a price
* Update the field_id to match your own field ID
*/
function demo_display_value_as_price( $value, $item ) {
if( $item['field_id'] == '1047' && $item['type'] == 'number' ) {
$value = wc_price( $value );
}
return $value;
}
add_filter( 'pewc_filter_item_value_in_cart', 'demo_display_value_as_price', 10, 2 );

Was this article helpful?

Related Articles