Change Product Prices Via A Hook In Woocommerce 3+

Business By Jonathan384

Jonathan384 Cake Central Cake Decorator Profile
Jonathan384 Posted 11 Jun 2021 , 11:24am
post #1 of 1

IN WooCommerce, I need to multiply all product prices by a number. So I have used the following (via a plugin):

add_filter('woocommerce_get_regular_price', array( $this, 'my_custom_price'), 99); add_filter('woocommerce_get_price', array( $this, 'my_custom_price'), 99);

function my_custom_price( $original_price ) { global $post, $woocommerce;

//Logic for calculating the new price here $new_price = $original_price * 2;

//Return the new price (this is the price that will be used everywhere in the store) return $new_price; }

But, that doesn't work for variation products. I have tried the following hooks with no luck:

add_filter('woocommerce_get_variation_regular_price', array( $this, 'my_custom_price'), 99); add_filter('woocommerce_get_variation_price', array( $this, 'my_custom_price'), 99);

The only one that works half way is this one:

add_filter('woocommerce_variation_prices_price', array( $this, 'my_custom_price'), 99);

But that just changed the overall price, not the selected variation price. See the image below, price is BsF. 200 and the overall price is right, 200 x 2 = 400, but the variation price when selected still shows 200:

Note: I need it to actually change, so display html hooks wont work.

Variation Price

Is there anything I'm missing, or something wrong?

0 replies

Quote by @%username% on %date%

%body%