I have a WooCommerce store and am using the 'Advanced Dynamic Pricing for Woocommerce' plugin. I need to use this plugin because I have discount structures set up
Percentage discounts have been applied to all products in store. The original price is crossed out with the new price next to it.
enter image description here
I want to display a suffix next to the new price that says 'inc VAT' to indicate that the price is inclusive of VAT.
I have tried this code which seems to work on products that don't have discounts applied but not on discounted products.
add_filter( 'woocommerce_get_price_html', 'custom_price_suffix', 100, 2 );
function custom_price_suffix( $price, $product ){
$price = $price . 'inc VAT' ;
return apply_filters( 'woocommerce_get_price', $price );}
Anyone know how I can achieve this?
The generated HTML code looks like this:
<div class="woosg-price">
<div class="woosg-price-ori">
<del>
<span class="woocommerce-Price-amount amount">
<span class="woocommerce-Price-currencySymbol">£</span>262.00</span>
</del>
<ins><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-
currencySymbol">£</span>117.90</span></ins>
</div>
<div class="woosg-price-new"></div>
</div>
You can use woocommerce_get_price_suffix dedicated hook, targeting on sale products like:
add_filter( 'woocommerce_get_price_suffix', 'custom_price_suffix', 999, 4 );
function custom_price_suffix( $html, $product, $price, $qty ){
if ( $product->is_on_sale() ) {
return ' ' . __('inc VAT', 'woocommerce');
}
return $html;
}
or maybe this instead (because of Advanced Dynamic Pricing for Woocommerce plugin):
add_filter( 'woocommerce_get_price_html', 'custom_price_suffix', 999, 2 );
function custom_price_suffix( $price_html, $product ){
if ( $product->is_on_sale() ) {
$price_html .= ' ' . __('inc VAT', 'woocommerce');
}
return $price_html;
}
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
Related:
Show Price Suffix only on all WooCommerce Product loops
Show a price suffix only on all WooCommerce single products
You Can add Suffix using the below filter.
add_filter( 'woocommerce_get_price_suffix', 'swt_add_price_suffix', 99, 4 );
function swt_add_price_suffix( $html, $product, $price, $qty ){
$html .= ' inc VAT';
return $html;
}
Or You can use below code as well.
add_filter( 'woocommerce_get_price_html', 'swt_add_price_suffix', 99, 2 );
function swt_add_price_suffix( $price, $product ){
$price = $price.' inc VAT';
return $price;
}
You can add suffix from the WooCommerce settings using the below steps.
Goto WooCommerce -> Settings -> General.
Mark checked "Enable tax rates and calculations" checkbox.
Open the Tax Tab.
Add the suffix text in "Price display suffix" text field.
Save the settings.
Related
I need to add a suffix text to the price of a woocommerce product from a specific category while on WooCommerce cart.
Here is my code:
add_filter( 'woocommerce_cart_item_price', 'filter_woocommerce_cart_item_price', 10, 3 );
add_filter( 'woocommerce_cart_item_subtotal', 'filter_woocommerce_cart_item_price', 10, 3 );
function filter_woocommerce_cart_item_price( $wc, $cart_item, $cart_item_key ) {
if(!in_array('67',$cart_item['data']->get_category_ids()))
{
return $wc;
}
else{
return $wc . ' Monthly';
}
};
The problem is it only works on simple products. Doesn't seem to affect the prices of variable products (I tested on 3 different sites).
Any idea what I'm missing?
To make it work for product variations items in cart too, use instead the following:
add_filter( 'woocommerce_cart_item_price', 'cart_item_amounts_prefix', 10, 3 );
add_filter( 'woocommerce_cart_item_subtotal', 'cart_item_amounts_prefix', 10, 3 );
function cart_item_amounts_prefix( $amount, $cart_item, $cart_item_key ) {
if( has_term( array(67), 'product_cat', $cart_item['product_id'] ) ){
$amount .= ' ' . __("Monthly", "woocommerce");
}
return $amount;
}
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
in Woocommerce when you choose to display prices during checkout inclusive VAT, Woocommerce then adds a .tax_label after the td.product-subtotal, and a .includes_tax after the total. For customers from countries with 0% VAT, nothing is displayed, I need the tax_label and includes_tax to be displayed though as “excl. VAT”. So in the td.product-subtotal cell there should be the subtotal price with the added "excl. VAT" and in the order-total.td there should be the total price also with the added "excl.VAT".
add_filter( 'woocommerce_cart_hide_zero_taxes', '__return_false' );
Above filter does not do what I want because it does not add "excl.VAT" to the td.product-subtotal.
If you're talking about the cart subtotal there is a filter for that woocommerce_cart_subtotal.
<?php
add_filter( 'woocommerce_cart_subtotal', 'filter_woocommerce_cart_subtotal', 10, 3 );
function filter_woocommerce_cart_subtotal( $cart_subtotal, $compound, $instance ) {
if( ! empty( $cart_subtotal ) ) {
return $cart_subtotal . ' - excl. VAT';
};
}; ?>
Untested but should be working.
I am trying to add a custom icon after the product price in Woocommerce for a specific product category on shop page. So I would like to add an icon of a "fast delivery truck" after the price on all products from "FAST SHIPPING" product category.
I would like it to display that like in wish.com web site, like in this screenshot:
This is what I've tried:
add_filter( 'woocommerce_price_html', 'prepend_append_icon_to_price', 10, 2 );
function prepend_append_icon_to_price( $price, $instance ) {
if(is_product_category( 'fast-shipping')){
$icon = ' <i class="fas fa-shipping-fast"></i> ';
$price = $icon . $price . $icon;
}
return $price;
}
But It doesn't display anything after the price.
Any help would be much appreciated.
You are using the wrong hook since Woocommerce 3 and there are some errors in your code.
To display an icon after the price on the right for "fast-shipping" product category, two cases:
1) On all Woocommerce archive pages:
add_filter( 'woocommerce_get_price_html', 'prepend_append_icon_to_price', 10, 2 );
function prepend_append_icon_to_price( $price, $product ) {
if( has_term( 'fast-shipping', 'product_cat', $product->get_id() ) && ! is_product() ){
$price .= '<span style="float:right"><i class="fas fa-shipping-fast"></i></span> ';
}
return $price;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
2) On a specific Woocommerce product category archive pages:
add_filter( 'woocommerce_get_price_html', 'append_icon_after_product_price', 10, 2 );
function append_icon_after_product_price( $price, $product ) {
if( is_product_category( 'fast-shipping' ) ){
$price .= '<span style="float:right"><i class="fas fa-shipping-fast"></i></span> ';
}
return $price;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
Use css before or after belong to the price tag :
fa-shipping-fast:before{
content: url(.....);
width : ....;
height : ....;
....
}
I thought this would have been easy, but I am stuck. All I am trying to do is add the word each after the variation price on a product page. The solution I have found adds it on the category page and in two places on the product page.
The code is:
/* Adds a text Each - after price */
function change_product_price( $price ) {
$price .= ' each';
return $price;
}
add_filter( 'woocommerce_get_price_html', 'change_product_price' );
From the picture above, I only need the each added to the price above the add to cart button, but not the other pacles like the crossed out section in the photo above.
Thank you for any guidance you can provide.
The following code will add a suffix to the product variations price:
add_filter('woocommerce_available_variation', 'variation_price_custom_suffix', 10, 3 );
function variation_price_custom_suffix( $variation_data, $product, $variation ) {
$variation_data['price_html'] .= ' <span class="price-suffix">' . __("each", "woocommerce") . '</span>';
return $variation_data;
}
Code goes in function.php file of your active child theme (active theme). Tested and works.
I need to change the price of my products in my store, with a 10% discount, if my customer is from some specific place, so, I wrote this code:
add_filter('woocommerce_price_html', 'my_price_edit');
function my_price_edit() {
$product = new WC_Product( get_the_ID() );
$price = $product->price;
echo $price * 0.9;
}
Ok, it works! But when in the checkout the price are normals without the 10% discount!
Does have some hook for change the price of the products in the checkout area or some different code to change correctly in the both (in the product page and checkout)?
New in Woocommerce too.
Your question looks really similiar to this one.
Adding Custom price with woocomerce product price in Cart & Checkout
I think you need to use the woocommerce_cart_item_subtotal hook to change the price in the cart directly (not exactly as a parameter)
I made a slightly modification to the code (changed price formula). I think that may help you.
add_filter( 'woocommerce_get_discounted_price', 'calculate_discounted_price', 10, 2 );
// Display the line total price
add_filter( 'woocommerce_cart_item_subtotal', 'display_discounted_price', 10, 2 );
function calculate_discounted_price( $price, $values ) {
// You have all your data on $values;
$price = $price*.09;
return $price;
}
// wc_price => format the price with your own currency
function display_discounted_price( $values, $item ) {
return wc_price( $item[ 'line_total' ] );
}