Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add Total Price Calculation to your WooCommerce Product Page with AJAX https://alexanderdejong.com/wordpress/wp-tutorial/add-total-price-calculation-woocommerce-product-page-ajax/
add_action( 'woocommerce_single_product_summary', 'woocommerce_total_product_price', 25 );
function woocommerce_total_product_price() {
global $woocommerce, $product;
// let's setup our divs
echo sprintf('<div id="product_total_price" style="font-size: 16px; font-weight: 200;">%s %s</div>',__('Total Price (incl 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(0));
}
});
});
</script>
<?php
}
@rodrigompaz

This comment has been minimized.

Show comment
Hide comment
@rodrigompaz

rodrigompaz Jul 31, 2018

Hi Alexander. Great snippet! Thanks.
I can't figure it out to use the price of a variant, the snippet grabs the lower price of the range.
Can you help me?
Thanks.
captura de pantalla 2018-07-31 a las 11 46 37

rodrigompaz commented Jul 31, 2018

Hi Alexander. Great snippet! Thanks.
I can't figure it out to use the price of a variant, the snippet grabs the lower price of the range.
Can you help me?
Thanks.
captura de pantalla 2018-07-31 a las 11 46 37

@pstevens71

This comment has been minimized.

Show comment
Hide comment
@pstevens71

pstevens71 Sep 14, 2018

Is this supposed to work for variable products? It seems to only grab the product base price.

pstevens71 commented Sep 14, 2018

Is this supposed to work for variable products? It seems to only grab the product base price.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment