Product Page: Need default Product Total Price = Unit Price x Minimum Quantity
-
Dear Forum,
I’m setting up an online print shop in WooCommerce and will allow customers to order business cards in multiples of 500 units. I want the Product Total Price to display on the product page and update as the user changes the Quantity. I’ve been able to achieve this using both a plugin and borrowed code, but for one small problem. The initial value for the Product Total Price = Product Unit Price. I need the default value to display Product Total Price = Product Unit Price x Minimum Quantity.
I can see why just the unit price is displayed initially, because of $product->get_price(). I just don’t know how to code for = [minimum quantity * get_price]. I’d kindly appreciate assistance.
Since the “WooCommerce Product Price x Quantity Preview” plugin is not up to date for my site I’ve instead installed the “WooCommerce Min Max Quantity & Step Control Global” plugin.
-Settings (Universal):
– -Minimum Quantity: 500
– -Maximum Quantity:
– -Quantity Step: 500I’ve then copied code to my theme’s functions.php file (see below) borrowed from https://stackoverflow.com/questions/35669568/woocommerce-display-total-price-when-quantity-selection-change.
The Product Total Price only displays correctly once the user changes the quantity from the default minimum value of 500.
The default Quantity = 500 units.
The unit price = $0.68 regardless of the quantity.
The default Product Total Price incorrectly displays the unit price i.e. $0.68 until the user changes the quantity.
Once the user changes the quantity (in increments of 500) then the correct Product Total Price displays i.e. = Quantity x Unit Price.Could someone please rectify the code such that the default Product Total Price = Unit Price x Minimum Quantity?
Thank you.
add_action( ‘woocommerce_single_product_summary’, ‘woocommerce_total_product_price’, 31 );
function woocommerce_total_product_price() {
global $woocommerce, $product;
// let’s setup our divs
echo sprintf(‘<div id=”product_total_price” style=”margin-bottom:20px;”>%s %s</div>’,__(‘Product Total AUD ex tax:’,’woocommerce’),'<span class=”price”>’. get_woocommerce_currency_symbol() .’ ‘ .$product->get_price().'</span>’);
?>
<script>
jQuery(function($){
var price = <?php echo $product->get_price(); ?>,
currency = ‘<?php echo get_woocommerce_currency_symbol(); ?>’;$(‘[name=quantity]’).change(function(){
if (!(this.value < 1)) {var product_total = parseFloat(price * this.value);
$(‘#product_total_price .price’).html( currency + product_total.toFixed(2));
}
});
});
</script>
<?php
}
- The topic ‘Product Page: Need default Product Total Price = Unit Price x Minimum Quantity’ is closed to new replies.