Guest User

Untitled

a guest
Jun 1st, 2018
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.35 KB | None | 0 0
  1. add_action( 'woocommerce_single_product_summary', 'woocommerce_total_product_price', 25 );
  2. function woocommerce_total_product_price() {
  3.     if(!is_admin()) {
  4.     global $woocommerce, $product;
  5.     // let's setup our divs
  6.     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>');
  7.     ?>
  8.         <script>
  9.             jQuery(function($){
  10.                 $(document).ready(function() {
  11.                     function setMinMax() {
  12.                         var price = <?php echo $product->get_price(); ?>;
  13.                         var currency = '<?php echo get_woocommerce_currency_symbol(); ?>';
  14.                         var qtycont =  $('.quantity');
  15.                         var qty =  qtycont.find('[name=quantity]');
  16.                         var max = qty.attr('max');
  17.                         var min = qty.attr('min');
  18.                         var wordCount = 250;
  19.                        
  20.                         if(typeof max === typeof undefined || max === false || max === '') qty.attr('max', 99999);
  21.  
  22.                         qty.attr('data-qty', 1);
  23.                        
  24.                         $('.variations select').on('change', function() {
  25.                             qty.attr('data-qty', 1);
  26.                             qty.attr('value', 1);
  27.                             qty.text(1);
  28.                         });
  29.  
  30.                         qtycont.on('click', '.plus, .minus', function(){
  31.                             var qtythis = $(this).find('[name=quantity]');
  32.                             var qtyNum = $(qtythis.selector).attr('data-qty'); 
  33.                             var max = $(qtythis.selector).attr('max');
  34.                             var min = $(qtythis.selector).attr('min');
  35.                             var totalQty = parseInt(qtyNum);
  36.  
  37.                             if($(this).is('.plus') && qtyNum < max) {
  38.                                 totalQty = parseInt(qtyNum) + 1;
  39.                                 $(qtythis.selector).attr('data-qty', totalQty);
  40.                             } else if($(this).is('.minus') && qtyNum > min) {
  41.                                 totalQty = parseInt(qtyNum) - 1;
  42.                                 $(qtythis.selector).attr('data-qty', totalQty);
  43.                             }
  44.  
  45.                             $(qtythis.selector).attr('value', totalQty);
  46.                                        
  47.                             if (!totalQty < 1) {
  48.                                 wordCount = wordCount * parseInt(totalQty);
  49.                                 var product_total = parseFloat(price * totalQty);
  50.                                 $('#product_total_price .price').html( currency + product_total + ' per page (' + wordCount + ' words)');          
  51.                             }  
  52.                         });
  53.                     }  
  54.                
  55.                     setTimeout(function() {
  56.                         setMinMax();
  57.                     }, 200);
  58.                    
  59.                     $(document).on('updated_cart_totals', setMinMax);  
  60.                 });
  61.             });
  62.         </script>
  63.     <?php
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment