WooCommerce Pro Tip: Adding Text to Product Prices

Sdílet
Vložit
  • čas přidán 5. 09. 2024
  • In this tutorial, you will learn how to add text to the price of your WooCommerce products. This simple but powerful customization will give your store a unique touch and make your prices stand out from the crowd. You'll see how easy it is to add text to your product prices without using a plugin , and how this simple tweak can make a big difference in the overall look and feel of your store. Whether you're a beginner or an experienced WooCommerce user, this video will show you how to take your store to the next level with custom text in prices. So sit back, relax, and let's get started!
    Code:
    // add text to price
    function Miguel_Add_Text_To_Product( $price ) {
    if ($price != ''){
    $price .= ' includes VAT';
    return $price;
    }
    }
    add_filter( 'woocommerce_get_price_html', 'Miguel_Add_Text_To_Product' );
    add_filter( 'woocommerce_cart_item_price', 'Miguel_Add_Text_To_Product' );
    ----------------------------------------------------------
    My Affiliate Links:
    ----------------------------------------------------------
    The Best Hosting Company Around , Save over 75% in the first year :
    🔘 SiteGround : tinyurl.com/2u...
    Elementor Pro:
    🔘 be.elementor.c...
    Elementor Hosting:
    Save up to 75% with this link:
    🔘 be.elementor.c...

Komentáře • 21

  • @GabrielMenashe
    @GabrielMenashe Před 4 měsíci

    Thanks!

  • @oziomavictoryolisa8280
    @oziomavictoryolisa8280 Před rokem +1

    next time pls add the code its difficult to see the screen also pls can you do a tutorial on how to add commas to text input for prices automatically. Lovely tutorial enjoyed it

  • @snowin5797
    @snowin5797 Před rokem

    Thanks mate!

  • @aadarshacrai
    @aadarshacrai Před 5 měsíci

    Hello Miguel Awesome Content, But can you please show us , how to display Save Price(Original Price - Sale Price) in a text block?

    • @the_mig
      @the_mig  Před 5 měsíci

      Will get back to you on that , have to test it properly for potential bugs

    • @the_mig
      @the_mig  Před 5 měsíci

      This seems to work on my side, test it out on yours :

    • @the_mig
      @the_mig  Před 5 měsíci

      add_filter( 'woocommerce_get_price_html', 'change_displayed_sale_price_html', 10, 2 );
      function change_displayed_sale_price_html( $price, $product ) {
      // Only on sale products on frontend and excluding min/max price on variable products
      if( $product->is_on_sale() && ! is_admin() && ! $product->is_type('variable')){
      // Get product prices
      $regular_price = (float) $product->get_regular_price(); // Regular price
      $sale_price = (float) $product->get_price(); // Active price (the "Sale price" when on-sale)
      // "Saving price" calculation and formatting
      $saving_price = wc_price( $regular_price - $sale_price );
      // Append to the formated html price
      $price .= sprintf( __('Save: %s', 'woocommerce' ), $saving_price );
      }
      return $price;
      }

  • @orental5996
    @orental5996 Před 3 měsíci

    how can I change the color of the text?

  • @NextrickProfile
    @NextrickProfile Před 10 měsíci

    Hi Miguel, is this possible to do for a specific category? I would like to do this not for the whole team but for a specific product category.

    • @the_mig
      @the_mig  Před 10 měsíci

      Try this and add the category stuff into the line that defines what to look for
      // Add text to price for specific product categories
      function Miguel_Add_Text_To_Product( $price, $product ) {
      // Define an array of category slugs where you want to add the text
      $target_categories = array('category-slug-1', 'category-slug-2');
      // Check if the product belongs to one of the target categories
      $product_categories = wp_get_post_terms( $product->get_id(), 'product_cat', array( 'fields' => 'slugs' ) );
      if (array_intersect($target_categories, $product_categories)) {
      if (!empty($price)) {
      $price .= ' includes VAT';
      }
      }
      return $price;
      }
      add_filter( 'woocommerce_get_price_html', 'Miguel_Add_Text_To_Product', 10, 2 );
      add_filter( 'woocommerce_cart_item_price', 'Miguel_Add_Text_To_Product', 10, 2 );

  • @RFS619
    @RFS619 Před rokem

    Thanks for the Video
    Same way Is there a way to display Text only on Single Product Page ???

    • @the_mig
      @the_mig  Před rokem

      Yes there is, if its just the product and NOT the Store then I'm Assuming it must not apply to related or upsells either right?
      If so then here it is :)

    • @the_mig
      @the_mig  Před rokem +1

      function Miguel_Add_Text_To_Price( $price, $product ) {
      global $woocommerce_loop;
      if ( is_product() && $woocommerce_loop['name'] !== 'related' && $woocommerce_loop['name'] !== 'up-sells' ) {
      $price .= ' incl. tax';
      }
      //return $price;
      return apply_filters( 'woocommerce_get_price', $price );
      }
      add_filter( 'woocommerce_get_price_html', 'Miguel_Add_Text_To_Price', 10, 2 );

    • @RFS619
      @RFS619 Před rokem

      @@the_mig Works very well Thanks a lot your genius and ur best best-Helping person..... and 2 more queries is there a chance to reduce the font size actually Price and the Text (incl. tax) are both in the same font size but I wanted the Text (incl. tax) size to be smaller the smallest actually and can Text (incl. tax) display in Cart Page where total price display it will help me a lot if answer me.

    • @RFS619
      @RFS619 Před rokem

      @@the_mig Works very well Thanks a lot your genius and ur best best-Helping person.....

    • @the_mig
      @the_mig  Před rokem +2

      @@RFS619 Smaller Text, replace the old function with this one :
      function Miguel_Add_Text_To_Price( $price, $product ) {
      global $woocommerce_loop;
      if ( is_product() && $woocommerce_loop['name'] !== 'related' && $woocommerce_loop['name'] !== 'up-sells' ) {
      $price .= ' incl. tax ;
      }

      //return $price;
      return apply_filters( 'woocommerce_get_price', $price );
      }
      add_filter( 'woocommerce_get_price_html', 'Miguel_Add_Text_To_Price', 10, 2 );