1
votes

On my WooCommerce shop, I'm showing my prices ex VAT. Now I also want to show the price inc VAT. Therefore, I have set up the following code:

    // Add price inc VAT to products loop
    function wbgoe_show_price_inc_VAT()
    {
        global $product;
        ?>
<span class="price">
    <?php echo wc_price(wc_get_price_including_tax($product)) . " <small class='woocommerce-price-suffix'>(" . __('inc. BTW', 'tendotools') . ")</small>"; ?>
</span>
<?php }

add_action('woocommerce_after_shop_loop_item_title', 'wbgoe_show_price_inc_VAT');


// Add price inc VAT to single product
function wbgoe_show_price_inc_VAT_sp()
{
    global $product; ?>
<p class="price">
    <?php echo wc_price(wc_get_price_including_tax($product)) . " <small class='woocommerce-price-suffix'>(" . __("inc. BTW", "tendotools") . ")</small>"; ?>
</p>
<?php }

add_action('woocommerce_single_product_summary', 'wbgoe_show_price_inc_VAT_sp');

My issue is that for variable products, the price is showing only the lowest price instead of the price variation as well. https://prnt.sc/q526ls

What is the proper code to print the price variation inc VAT?

1

1 Answers

1
votes

you could use something like that

// Add price inc VAT to products loop
function wbgoe_show_price_inc_VAT() {
    global $product;
    ?>
    <span class="price">
        <?php
        if ( $product->is_type( 'variable' ) ) {
            echo wc_price(wc_get_price_including_tax($product, array('price' => $product->get_variation_price( 'min' )))) . __(" – ", "tendotools"); 
            echo wc_price(wc_get_price_including_tax($product, array('price' => $product->get_variation_price( 'max' )))) . " <small class='woocommerce-price-suffix'>(" . __("inc. BTW", "tendotools") . ")</small>";          
        } else {
            echo wc_price(wc_get_price_including_tax($product)) . " <small class='woocommerce-price-suffix'>(" . __('inc. BTW', 'tendotools') . ")</small>";
        }
        ?>
    </span>
    <?php
}
add_action('woocommerce_after_shop_loop_item_title', 'wbgoe_show_price_inc_VAT', 10, 0);

// Add price inc VAT to single product
function wbgoe_show_price_inc_VAT_sp($array, $int = null ) {    
    global $product;
    ?>
    <p class="price">
        <?php
        if ( $product->is_type( 'variable' ) ) {
            echo wc_price(wc_get_price_including_tax($product, array('price' => $product->get_variation_price( 'min' )))) . __(" – ", "tendotools"); 
            echo wc_price(wc_get_price_including_tax($product, array('price' => $product->get_variation_price( 'max' )))) . " <small class='woocommerce-price-suffix'>(" . __("inc. BTW", "tendotools") . ")</small>"; 
        } else {
            echo wc_price(wc_get_price_including_tax($product)) . " <small class='woocommerce-price-suffix'>(" . __('inc. BTW', 'tendotools') . ")</small>";            
        }
        ?>
    </p>
    <?php
}
add_action('woocommerce_single_product_summary', 'wbgoe_show_price_inc_VAT_sp', 10, 2);