Created
March 29, 2021 07:19
-
-
Save trueqap/800457a853248dd9b14b3cdc23f1b73e to your computer and use it in GitHub Desktop.
Mennyiségi gombok WooCommerce archive oldalra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function custom_quantity_field_archive() | |
{ | |
$product = wc_get_product(get_the_ID()); | |
if (! $product->is_sold_individually() && 'variable' != $product->get_type() && $product->is_purchasable()) { | |
woocommerce_quantity_input(array( 'min_value' => 1, 'max_value' => $product->backorders_allowed() ? '' : $product->get_stock_quantity() )); | |
} | |
} | |
add_action('woocommerce_after_shop_loop_item', 'custom_quantity_field_archive', 0, 9); | |
function custom_add_to_cart_quantity_handler() | |
{ | |
wc_enqueue_js(' | |
jQuery( "body" ).on( "click", ".quantity input", function() { | |
return false; | |
}); | |
jQuery( "body" ).on( "change input", ".quantity .qty", function() { | |
var add_to_cart_button = jQuery( this ).parents( ".product" ).find( ".add_to_cart_button" ); | |
// For AJAX add-to-cart actions | |
add_to_cart_button.attr( "data-quantity", jQuery( this ).val() ); | |
// For non-AJAX add-to-cart actions | |
add_to_cart_button.attr( "href", "?add-to-cart=" + add_to_cart_button.attr( "data-product_id" ) + "&quantity=" + jQuery( this ).val() ); | |
}); | |
'); | |
} | |
add_action('init', 'custom_add_to_cart_quantity_handler'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment