Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'woocommerce_single_product_summary', 'woocommerce_total_product_price', 25 );
- function woocommerce_total_product_price() {
- if(!is_admin()) {
- 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($){
- $(document).ready(function() {
- function setMinMax() {
- var price = <?php echo $product->get_price(); ?>;
- var currency = '<?php echo get_woocommerce_currency_symbol(); ?>';
- var qtycont = $('.quantity');
- var qty = qtycont.find('[name=quantity]');
- var max = qty.attr('max');
- var min = qty.attr('min');
- var wordCount = 250;
- if(typeof max === typeof undefined || max === false || max === '') qty.attr('max', 99999);
- qty.attr('data-qty', 1);
- $('.variations select').on('change', function() {
- qty.attr('data-qty', 1);
- qty.attr('value', 1);
- qty.text(1);
- });
- qtycont.on('click', '.plus, .minus', function(){
- var qtythis = $(this).find('[name=quantity]');
- var qtyNum = $(qtythis.selector).attr('data-qty');
- var max = $(qtythis.selector).attr('max');
- var min = $(qtythis.selector).attr('min');
- var totalQty = parseInt(qtyNum);
- if($(this).is('.plus') && qtyNum < max) {
- totalQty = parseInt(qtyNum) + 1;
- $(qtythis.selector).attr('data-qty', totalQty);
- } else if($(this).is('.minus') && qtyNum > min) {
- totalQty = parseInt(qtyNum) - 1;
- $(qtythis.selector).attr('data-qty', totalQty);
- }
- $(qtythis.selector).attr('value', totalQty);
- if (!totalQty < 1) {
- wordCount = wordCount * parseInt(totalQty);
- var product_total = parseFloat(price * totalQty);
- $('#product_total_price .price').html( currency + product_total + ' per page (' + wordCount + ' words)');
- }
- });
- }
- setTimeout(function() {
- setMinMax();
- }, 200);
- $(document).on('updated_cart_totals', setMinMax);
- });
- });
- </script>
- <?php
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment