Plugin Directory

Changeset 3295075


Ignore:
Timestamp:
05/17/2025 04:44:54 AM (10 months ago)
Author:
tanvirul
Message:

Release 10.0.18

Location:
add-quantity-field-on-shop-page-for-woocommerce
Files:
13 added
2 edited

Legend:

Unmodified
Added
Removed
  • add-quantity-field-on-shop-page-for-woocommerce/trunk/add-quantity-field-on-shop-page.php

    r3257222 r3295075  
    55 * Description: Display quantity field on the Shop / Archive page of WooCommerce.
    66 * Author: Tanvirul Haque
    7  * Version: 1.0.17
     7 * Version: 1.0.18
    88 * Author URI: http://wpxpress.net
    99 * Text Domain: add-quantity-field-on-shop-page
     
    1111 * Requires PHP: 7.4
    1212 * Requires at least: 4.8
    13  * Tested up to: 6.7
     13 * Tested up to: 6.8
    1414 * WC requires at least: 4.5
    15  * WC tested up to: 9.7
     15 * WC tested up to: 9.8
    1616 * License: GPLv2+
    1717*/
     
    3434         * @var  string
    3535         */
    36         public $version = '1.0.17';
     36        public $version = '1.0.18';
    3737
    3838        /**
     
    156156            if ( class_exists( 'Woo_Variation_Swatches_Pro' ) ) {
    157157                $get_wvsp_options       = get_option( 'woo_variation_swatches' );
    158                 $is_enable_swatches     = array_key_exists( 'show_on_archive', $get_wvsp_options ) ? $get_wvsp_options['show_on_archive'] : 'yes';
    159                 $is_enable_catalog_mode = array_key_exists( 'enable_catalog_mode', $get_wvsp_options ) ? $get_wvsp_options['enable_catalog_mode'] : 'no';
     158                $is_enable_swatches     = ( $get_wvsp_options && array_key_exists( 'show_on_archive', $get_wvsp_options ) ) ? $get_wvsp_options['show_on_archive'] : 'yes';
     159                $is_enable_catalog_mode = ( $get_wvsp_options && array_key_exists( 'enable_catalog_mode', $get_wvsp_options ) ) ? $get_wvsp_options['enable_catalog_mode'] : 'no';
    160160                $is_variable_enable     = ( 'variable' == $product->get_type() && 'yes' == $is_enable_swatches && 'no' == $is_enable_catalog_mode ) ? true : false ;
    161161            }
     
    176176        public function add_to_cart_quantity_handler() {
    177177            wc_enqueue_js( '
    178                 jQuery( ".type-product" ).on( "click", ".quantity input", function() {
    179                     return false;
    180                 } );
    181                
    182                 jQuery( ".type-product" ).on( "change input", ".quantity .qty", function() {
    183                     var add_to_cart_button = jQuery( this ).parents( ".product" ).find( ".add_to_cart_button" );
    184                    
    185                     // For AJAX add-to-cart actions
    186                     add_to_cart_button.attr( "data-quantity", jQuery( this ).val() );
    187                    
    188                     // For non-AJAX add-to-cart actions
    189                     add_to_cart_button.attr( "href", "?add-to-cart=" + add_to_cart_button.attr( "data-product_id" ) + "&quantity=" + jQuery( this ).val() );
    190                 } );
    191                
     178                 jQuery( ".type-product" ).on( "click", ".quantity input", function() {
     179                     return false;
     180                 } );
     181
     182                jQuery(".type-product").on("change", ".quantity input", function(e) {
     183                    var add_to_cart_button = jQuery( this ).closest( ".product" ).find( ".add_to_cart_button" ),
     184                        href = add_to_cart_button.attr("href"),
     185                        qty = jQuery(this).val();
     186
     187                    // Update data quantity
     188                    add_to_cart_button.attr( "data-quantity", qty );
     189
     190                    if( ! jQuery(this).closest(".type-product").hasClass("wvs-archive-product-wrapper") ){
     191                        // For non-AJAX add-to-cart actions
     192                        add_to_cart_button.attr( "href", "?add-to-cart=" + add_to_cart_button.attr( "data-product_id" ) + "&quantity=" + jQuery( this ).val() );
     193                    } else {
     194                        // URL fix for Variation Swatches
     195
     196                        // Create a complete URL for parsing   
     197                        var new_url = new URL(href);
     198
     199                        // Set the quantity parameter
     200                        new_url.searchParams.set("quantity", qty);
     201
     202                        // Update the href
     203                        add_to_cart_button.attr( "href", new_url.toString() );
     204                    }
     205                });
     206
    192207                // Trigger on Enter press
    193208                jQuery( ".woocommerce .products" ).on( "keypress", ".quantity .qty", function(e) {
     
    196211                    }
    197212                } );
     213
     214                // Support for Variation Swatches
     215                jQuery( document.body ).on( "adding_to_cart", function( e, btn, data ) {
     216                    data.quantity = btn.attr("data-quantity");
     217                });
     218               
     219                // Support for Variation Swatches - Trigger on swatches selection and push quantity value with the add_to_cart_url as a parameter
     220                jQuery( ".wvs-archive-variations-wrapper" ).on( "show_variation", function(e,data) {
     221                    var add_to_cart_button = jQuery( this ).closest( ".product" ).find( ".add_to_cart_button" ),
     222                        href = add_to_cart_button.attr("href"),
     223                        qty = jQuery( this ).closest( ".product" ).find( ".input-text.qty" ).val(),
     224                        new_url = new URL(href);
     225                       
     226                    new_url.searchParams.set("quantity", qty);
     227                    add_to_cart_button.attr( "href", new_url.toString() );
     228                });
    198229            ' );
    199230        }
  • add-quantity-field-on-shop-page-for-woocommerce/trunk/readme.txt

    r3257222 r3295075  
    44Requires PHP: 7.4
    55Requires at least: 4.8
    6 Tested up to: 6.7
     6Tested up to: 6.8
    77WC requires at least: 4.5
    8 WC tested up to: 9.7
    9 Stable tag: 1.0.17
     8WC tested up to: 9.8
     9Stable tag: 1.0.18
    1010License: GPLv2 or later
    1111License URI: https://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.