Title: Variated Price Query
Last modified: August 31, 2016

---

# Variated Price Query

 *  Resolved [Jamie Gill](https://wordpress.org/support/users/patchgill/)
 * (@patchgill)
 * [10 years ago](https://wordpress.org/support/topic/variated-price-query/)
 * Wonder if someone could point me in the right direction of a hook for the new
   way variation price is pulled in :-
 * {{{ data.variation.price_html }}}
 * I am currently manipulating the simple price to add on £15 to the product if 
   a cookie is set at a certain value which works and display fine is there a hook
   or way to add values to the variated prices.
 *     ```
       $this->total_price = $product->sale_price + $this->additional_price;
       $this->old_total_price = $product->regular_price + $this->additional_price;
   
       echo '<p class="price"><del><span class="amount">'.wc_price($this->old_total_price).'</span></del> <ins><span class="amount">'.wc_price($this->total_price).'</span></ins></p>';
       echo '<meta itemprop="price" content="'.$this->total_price.'" />';
       ```
   
 * So this is the code Im using to add to the simple price and it works fine.
 * I cannot seem to find a template file controlling this the closest I can get 
   is on the above which I cannot do much with.
 * Any help will be appreciated.
 * J
 * [https://wordpress.org/plugins/woocommerce/](https://wordpress.org/plugins/woocommerce/)

Viewing 13 replies - 1 through 13 (of 13 total)

 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years ago](https://wordpress.org/support/topic/variated-price-query/#post-7369264)
 * This display you’re adding won’t affect the item in the cart, are you aware of
   this?
 *  Thread Starter [Jamie Gill](https://wordpress.org/support/users/patchgill/)
 * (@patchgill)
 * [10 years ago](https://wordpress.org/support/topic/variated-price-query/#post-7369266)
 * Hi Mike,
 * Thanks for the response. Yes I have this setup already working fine on simple
   and variated product using :-
 * add_action( ‘woocommerce_before_calculate_totals’, array($this, ‘add_custom_price’));
 * Its now just on the product single pages to display the price with the additional
   charge.
 * Cheers
    J
 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years ago](https://wordpress.org/support/topic/variated-price-query/#post-7369268)
 * What about using something more lower level, like [https://github.com/woothemes/woocommerce/blob/master/includes/abstracts/abstract-wc-product.php#L834](https://github.com/woothemes/woocommerce/blob/master/includes/abstracts/abstract-wc-product.php#L834)
 *  Thread Starter [Jamie Gill](https://wordpress.org/support/users/patchgill/)
 * (@patchgill)
 * [10 years ago](https://wordpress.org/support/topic/variated-price-query/#post-7369310)
 * Thanks Mike I shall give it a look over and see what I can do with it.
 *  Thread Starter [Jamie Gill](https://wordpress.org/support/users/patchgill/)
 * (@patchgill)
 * [10 years ago](https://wordpress.org/support/topic/variated-price-query/#post-7369415)
 * Hi Mike,
 * Trust your well I have had a play with the woocommerce_get_price filter and this
   seem to work well for adding an additional price.
 * The only issue I am having here is formatting the output as return $price just
   returns the bare bones price.
 * Also it removes the regular price if it is a sale price nd just displays the 
   sale price. So say I was trying to return :-
 * `echo '<p class="price"><del><span class="amount">'.wc_price($this->old_total_price).'
   </span></del> <ins><span class="amount">'.wc_price($this->total_price).'</span
   ></ins></p>';`
 * Is this possible through the filter?
 * Cheers
    Jamie
 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years ago](https://wordpress.org/support/topic/variated-price-query/#post-7369416)
 * In the code above you could use get_post_meta to get the original, unaltered 
   price.
 *  Thread Starter [Jamie Gill](https://wordpress.org/support/users/patchgill/)
 * (@patchgill)
 * [10 years ago](https://wordpress.org/support/topic/variated-price-query/#post-7369417)
 * Sorry I dont think I am explaining myself correctly, here are some examples I
   have tried
 *     ```
       $price = '<del>'. ($product->regular_price + $this->additional_price) . '</del><ins>' . ($product->sale_price + $this->additional_price) . '</ins>'; 
   
       return $price;
   
       Results = Free! (not sure why assume the formatting is upsetting this?)
       ```
   
 *     ```
       $price = ($product->regular_price + $this->additional_price) . ' ' . ($product->sale_price + $this->additional_price);
   
       return $price;
   
       Results = Regular Price + Addition price (returning value but only one and the wrong value)
       ```
   
 *     ```
       $price = ($product->sale_price + $this->additional_price);
   
       return $price;
   
       Results = Sale Price + Addition price (returning value but the correct value)
       ```
   
 * Ideally I was after the same formatting Woo does as the first result I was trying
   above. Obviously I may be asking for alot here and on simple price I can get 
   it spot on its just the variation prices as they change.
 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years ago](https://wordpress.org/support/topic/variated-price-query/#post-7369418)
 * I’m not sure what you’re doing now :p If you’re using the adjust price filter
   I mentioned earlier, that will affect the actual prices.
 * Then you can use the get_price_html filters, which variations use too, to prepend
   with an original price?
 *  Thread Starter [Jamie Gill](https://wordpress.org/support/users/patchgill/)
 * (@patchgill)
 * [10 years ago](https://wordpress.org/support/topic/variated-price-query/#post-7369420)
 * In a nutshell my client has postcode specific prices per products he ships from
   9 different bases so dependant on where the product is shipped from depends on
   how much this costs. Thing is he wants to display this at products level as he
   gets alot of people dropping at cart when they see how much delivery is so I 
   cant use just shipping zones. He wants to be able to add postcode/prices to shipping
   areas and then on each product just assign the relevant shipping area to the 
   product.
 * So my idea was to create a custom post type for shipping areas create an area
   and just have a repeater field that has Postcode and Price. On the product page
   we have an input box ready to catch the client postcode and set it as a cookie.
 * Then on each product I get the cookie and get the area ID from whats set to the
   product to get the postcodes/prices set. Match the postcode in the area to whichever
   repeater is closest and apply the cost so say BD10 0DH is set and in the shipping
   area BD has a price of 15 I want to add 15 to the product price in woocommerce.
 * Works great in cart and on single pages and variations (before changed) its when
   the variation is changed it brings in the normal price not adding the additional.
 * I maybe going a really daft way about it but it seems to work great at the minute
   minus the issue I have. The filter you mentioned above is perfect for everything
   minus when I change variation it defaults to the standard prices without the 
   additional price tried for testing :-
 *     ```
       public function get_final_price($price, $product) {
               $price = 15;
       	return $price;
       }
       add_filter('woocommerce_get_price_html', array($this, 'get_final_price'), 10, 2);
       ```
   
 * This sets the variation price at the start to 15 which is correct but when I 
   change variation it brings in the regular pricing, should all the prices return
   15 here? This is just for testing to see if the filter did what I wanted it to
   do.
 * Apologies for the long winded post just thought it might help you see what I 
   am trying to achieve.
 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years ago](https://wordpress.org/support/topic/variated-price-query/#post-7369422)
 * > when I change variation it defaults to the standard prices without the additional
   price tried for testing
 * Assuming you’re using the adjust price filter I mentioned, which is the better
   way, are you sure you’re not just targeting the wrong IDs? Variations have their
   own IDs.
 *  Thread Starter [Jamie Gill](https://wordpress.org/support/users/patchgill/)
 * (@patchgill)
 * [10 years ago](https://wordpress.org/support/topic/variated-price-query/#post-7369424)
 * Ah I was using one and then the other not both, the HTML price worked great for
   the initial variation price and simple products. Ive then used the initial filter
   you mentioned and on variation change this displays the raw price with additional
   added
 * Raw Filter
 *     ```
       public function get_raw_price($price, $product) {
   
       	$price = ($price + $this->additional_price);
       	return $price;
   
       }
       ```
   
 * Html Filter
 *     ```
       public function get_html_price($price, $product) {
   
       		if ($product->is_type( 'variable' )) {
   
       			$price = '<p class="price"><del><span class="amount">'.wc_price(($product->min_variation_regular_price + $this->additional_price)).'</span>–<span class="amount">'.wc_price(($product->max_variation_regular_price + $this->additional_price)).'</span></del> <ins><span class="amount">'.wc_price(($product->min_variation_price + $this->additional_price)).'</span>–<span class="amount">'.wc_price(($product->max_variation_price + $this->additional_price)).'</span></ins></p>';
       			return $price;
   
       		} else {
   
       			if ($product->sale_price > 0) {
       				$price = '<p class="price"><del><span class="amount">'. wc_price(($product->regular_price  + $this->additional_price)) . '</span></del><ins><span class="amount">' . wc_price(($product->sale_price + $this->additional_price)) . '</span></ins></p>';
       				return $price;
       			} else {
       				$price = '<p class="price"><span class="amount">'. wc_price(($product->regular_price + $this->additional_price)) . '</span></p>';
       				return $price;
       			}
   
       		}
   
           }
       ```
   
 * Not sure if this is the correct way to do this but it seems to work?
 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years ago](https://wordpress.org/support/topic/variated-price-query/#post-7369425)
 * Looks ok to me.
 *  Thread Starter [Jamie Gill](https://wordpress.org/support/users/patchgill/)
 * (@patchgill)
 * [10 years ago](https://wordpress.org/support/topic/variated-price-query/#post-7369427)
 * Thanks for the help on this Mike much appreciated all seems to be in working 
   order now top man.

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Variated Price Query’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 13 replies
 * 2 participants
 * Last reply from: [Jamie Gill](https://wordpress.org/support/users/patchgill/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/variated-price-query/#post-7369427)
 * Status: resolved