How To Change The Format Of Price In WooCommerce – In this post, we’ll see how we can change or override price format or display in WooCommerce shop. As we know we can do these types of custom changes using filters and actions with proper hook. So, we’ll use hooks provided by WooCommerce for this.
To update price display on shop page, we’ll use hook ‘woocommerce_get_price_html’. Let’s create an example plugin to perform this –
<?php /** * Plugin Name: WooCommerce Custom Price Format Change * Description: An example plugin to change price display in WooCommerce Shop * Author: Webkul * Author URI: https://webkul.com * Plugin URI: https://webkul.com * Text Domain: webkul */
And then in admin end, please activate same plugin.
Now, as plugin is activated so edit the main file and add function to change price display.
<?php /** * Plugin Name: WooCommerce Custom Price Format Change * Description: An example plugin to change price display in WooCommerce Shop * Author: Webkul * Author URI: https://webkul.com * Plugin URI: https://webkul.com * Text Domain: webkul */ function wk_change_price_display( $price ) { return $price . ' per item'; } add_action( 'woocommerce_get_price_html', 'wk_change_price_display' );
This action will update price in front end by appending ‘per item’ string. Please have a look –
The above hook updates the price display on shop, category search, etc and if you want same changes on cart as well then we need to add same function to one other hook as well named ‘woocommerce_cart_item_price’.
function wk_change_price_display( $price ) { return $price . ' per item'; } add_action( 'woocommerce_get_price_html', 'wk_change_price_display' ); add_action( 'woocommerce_cart_item_price', 'wk_change_price_display' );
This will change price display of product in cart page also.
Support
Still have any issue feel free to add a ticket and let us know your views to make the code better https://webkul.uvdesk.com/en/customer/create-ticket/
Thanks for Your Time! Have a Good Day!
function cw_change_product_price_display( $price ) {
$price .= ‘ At Each Item Product’;
return $price;
}
add_filter( ‘woocommerce_get_price_html’, ‘cw_change_product_price_display’ );
add_filter( ‘woocommerce_cart_item_price’, ‘cw_change_product_price_display’ );