Changeset 3295075
- Timestamp:
- 05/17/2025 04:44:54 AM (10 months ago)
- Location:
- add-quantity-field-on-shop-page-for-woocommerce
- Files:
-
- 13 added
- 2 edited
-
tags/1.0.18 (added)
-
tags/1.0.18/add-quantity-field-on-shop-page.php (added)
-
tags/1.0.18/includes (added)
-
tags/1.0.18/includes/admin (added)
-
tags/1.0.18/includes/admin/assets (added)
-
tags/1.0.18/includes/admin/assets/img (added)
-
tags/1.0.18/includes/admin/assets/img/wvpd-icon.gif (added)
-
tags/1.0.18/includes/admin/class-aqf_plugin_installer.php (added)
-
tags/1.0.18/includes/plugin_compatibility.php (added)
-
tags/1.0.18/index.php (added)
-
tags/1.0.18/languages (added)
-
tags/1.0.18/languages/add-quantity-field-on-shop-page.pot (added)
-
tags/1.0.18/readme.txt (added)
-
trunk/add-quantity-field-on-shop-page.php (modified) (6 diffs)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
add-quantity-field-on-shop-page-for-woocommerce/trunk/add-quantity-field-on-shop-page.php
r3257222 r3295075 5 5 * Description: Display quantity field on the Shop / Archive page of WooCommerce. 6 6 * Author: Tanvirul Haque 7 * Version: 1.0.1 77 * Version: 1.0.18 8 8 * Author URI: http://wpxpress.net 9 9 * Text Domain: add-quantity-field-on-shop-page … … 11 11 * Requires PHP: 7.4 12 12 * Requires at least: 4.8 13 * Tested up to: 6. 713 * Tested up to: 6.8 14 14 * WC requires at least: 4.5 15 * WC tested up to: 9. 715 * WC tested up to: 9.8 16 16 * License: GPLv2+ 17 17 */ … … 34 34 * @var string 35 35 */ 36 public $version = '1.0.1 7';36 public $version = '1.0.18'; 37 37 38 38 /** … … 156 156 if ( class_exists( 'Woo_Variation_Swatches_Pro' ) ) { 157 157 $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'; 160 160 $is_variable_enable = ( 'variable' == $product->get_type() && 'yes' == $is_enable_swatches && 'no' == $is_enable_catalog_mode ) ? true : false ; 161 161 } … … 176 176 public function add_to_cart_quantity_handler() { 177 177 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 192 207 // Trigger on Enter press 193 208 jQuery( ".woocommerce .products" ).on( "keypress", ".quantity .qty", function(e) { … … 196 211 } 197 212 } ); 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 }); 198 229 ' ); 199 230 } -
add-quantity-field-on-shop-page-for-woocommerce/trunk/readme.txt
r3257222 r3295075 4 4 Requires PHP: 7.4 5 5 Requires at least: 4.8 6 Tested up to: 6. 76 Tested up to: 6.8 7 7 WC requires at least: 4.5 8 WC tested up to: 9. 79 Stable tag: 1.0.1 78 WC tested up to: 9.8 9 Stable tag: 1.0.18 10 10 License: GPLv2 or later 11 11 License URI: https://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset
for help on using the changeset viewer.