Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Agregar botón de "añadir a carrito" en los productos del módulo tienda **/
- add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 20 );
- /** Agregar campo de cantidad en los productos de la tienda woo **/
- function ov_agregar_campo_cantidad_productos_tienda() {
- $product = wc_get_product( get_the_ID() );
- if ( ! $product->is_sold_individually() && 'variable' != $product->product_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', 'ov_agregar_campo_cantidad_productos_tienda', 15, 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' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement