Show prices including VAT

This topic contains 4 replies, has 2 voices, and was last updated by andreasesp andreasesp 1 month, 3 weeks ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #38069
    andreasesp
    andreasesp
    Participant

    Hello, I’ve followed the steps on this site: https://documentation.ajaxsearchpro.com/advanced-options/advanced-title-and-description-fields to add regular price and sale price on products. But the prices that are showing is without VAT. How can I make them show including VAT?

    #38076
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Instead of the “_price” field, use the “_tax_price”, that should do the trick 🙂 I have corrected the documentation as well.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #38077
    andreasesp
    andreasesp
    Participant

    Thanks 😊 But is there an option for sale price with tax as well?

    #38093
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    That may need a custom code, but I could not find the proper method on WooCommerce documentation on how to get that price exactly. I can only assume it will work.

    Use the {_tax_sale_price} variable, and also the custom code below.

    Try adding this code to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.

    add_filter('asp_results', 'asp_results_custom_variable', 10, 1);
    function custom_asp_redirect_url($results) {
    	foreach ( $results as $k => &$r ) {
    		if ( $r->post_type == 'product' || $r->post_type == 'product_variation' ) {
    			$product = wc_get_product( $r->id );
    			$r->title = str_replace(
    				'{_tax_sale_price}',
    				wc_get_price_including_tax( $product, array( 'price' => $product->get_sale_price() ),
    				$r->title
    			);
    			$r->content = str_replace(
    				'{_tax_sale_price}',
    				wc_get_price_including_tax( $product, array( 'price' => $product->get_sale_price() ),
    				$r->content
    			);
    		}
    	}
    	
    	return $results;
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #38096
    andreasesp
    andreasesp
    Participant

    Thanks, I’ll try 😊

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.