Advertisement
CodeDropz

New Price - Upload Qty * Qty (WooCommerce)

Aug 7th, 2024 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. add_action( 'wp_footer', function(){
  2.     ?>
  3.         <script type="text/javascript">
  4.             jQuery(document).ready(function($) {
  5.                 if ( dnd_wc_uploader.update_qty_pdf && dnd_wc_uploader.show_qty ) {
  6.                    
  7.                     // Add minimum on upload quantity to 1.
  8.                     document.addEventListener('dndmfu_on_success', function(event){
  9.                         $('.dnd-upload-qty').attr( 'min', 1 );
  10.                     });
  11.                        
  12.                     // After deleting the item, reset cart quantity.
  13.                     document.addEventListener('dndmfu_after_deleted', function(event){
  14.                         $('input.qty').val(1);
  15.                     });
  16.                    
  17.                     // Prevent user to change cart quantity.
  18.                     $('input.qty').attr('readonly', true);
  19.                    
  20.                     // Update Quantity - Multiply (upload_quantity * total_pdf_pages).
  21.                     $(document).on('change', '.dnd-upload-qty', function() {
  22.                         const indexName = $(this).attr('name').match(/\[(.*?)\]/)[1]
  23.                         const pdfIndex  = $('[pdf-index="'+ indexName +'"]');
  24.                         if ( $('input.qty').val() > 1 && pdfIndex.length > 0 && $(this).val() > 0 ) {
  25.                             $('input.qty').val( $(this).val() * parseInt( pdfIndex.attr('data-pages') ) );
  26.                         } else {
  27.                             $('input.qty').val( parseInt( pdfIndex.attr('data-pages') ) );
  28.                         }
  29.                     });
  30.                    
  31.                 }
  32.             });
  33.         </script>
  34.     <?php
  35. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement