Overriding variation pricing
-
Hello, i am trying to override woocommerce pricing via functions.php. I am able to do it just fine with simple products, but getting variations to work is proving difficult. Specifically I need to find out what variation I am currently selecting. The following code works for simple products:
function get_price() { return apply_filters( 'woocommerce_get_price', $this->price, $this );} add_filter('woocommerce_get_price', 'return_custom_price', $product, 2); function return_custom_price($price, $product) { global $post, $woocommerce; $post_id = $product->id; if($product->product_type == 'simple') { $price="1.00"; } if($product->product_type == 'variable') { $price="2.00"; } return $price;
This works as expected, the price is 1.00 if it is a simple product, and 2.00 if the product is a varation, but all the variations are 2.00. I need to be able to get the selected varation id and specify a price. I can detect if the product is a variation but dont know how to get the actual varation id if that makes any sense. Any suggestions?
- The topic ‘Overriding variation pricing’ is closed to new replies.