I am working on a plugin for woocommerce and came across the hook "woocommerce_variation_price_html" which allows you to hook into the variation prices drop down on single products. So created a quick function to test and have a play:
add_action( 'woocommerce_variation_price_html' , 'wholesale_variation_price' );
function wholesale_variation_price($term){
return '';
}
The above works nicely and removes all data. However i am trying to add custom meta_data to replace the default values.
So i then did the following:
add_action( 'woocommerce_variation_price_html' , 'wholesale_variation_price' );
function wholesale_variation_price($term){
$var_price = get_post_meta( get_the_id(), '_my_price', true );
return $var_price;
}
This for some reason does not work? Has anyone had any experience working with this hook in woocommerce? There is not much documentation on that hook anywhere.
Any help would be greatly appreciated!
I used this to modify the variation prices to show the price for each variation product excluding tax before and including tax after :)
By looking at WooCommerce source code, I see that
woocommerce_variation_price_html
is a filter, not an action. I don't know how you managed to get your sample code to work like that... weird.Try this:
As already indicated that you can read here about filters for html. Maybe you have Sale price set for variation? Then in link you can see that there are total of 4 filters. For: price, sale price, free and no price.
This code works
Also this one works too. This allows you to modify whole variation. Read in code here
Screenshots:
First example
Second example
Works like magic!
P.S. you can see prices like this in screenshots because I have design that show them like that.
EDIT 2016-09-10
Version 2.6+
As woocommerce_price is deprecated in 2.6 then use wc_price for newer versions.