Read More
Menu Close

    How To Change The Format Of Price In WooCommerce

    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.

    How To Change The Format Of Price In WooCommerce

    Now, as plugin is activated so edit the main file and add function to change price display.

    Start your headless eCommerce
    now.
    Read More
    <?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 –

    How To Change The Format Of Price In WooCommerce

     

    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.

    How To Change The Format Of Price In WooCommerce

     

    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!

    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    2 comments

  • Alvina
    Hey Varun, I am getting an error while running this code to change the pricing on display. I have seen the code here https://www.cloudways.com/blog/change-woocommerce-price-display/ and just do some necessary modifications. Can you please help me to resolve the issue?

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

    • Varun Kumar (Moderator)
      Hi,

      As you have copied the code from the website you mentioned so single quotes copied are wrong.

      You can use the code displayed in this blog.

      Thanks

  • Back to Top

    Table of Content