AGREGAR CANTIDAD EN LISTA DE PRODUCTOS

/* Botón de añadir al carrito en tienda */
add_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’, 20 );

//agregamos lac cantidades antes del boton
//Agregamos código HTML
add_filter( ‘woocommerce_loop_add_to_cart_link’, ‘dcms_add_quantity_field’, 10, 2 );
function dcms_add_quantity_field($html, $product) {
if($product&&
$product->is_type(‘simple’)&&
$product->is_purchasable()&&
$product->is_in_stock()&&
!$product->is_sold_individually()){

$html='<form action=”‘. esc_url($product->add_to_cart_url()).'” class=”cart” method=”post” enctype=”multipart/form-data”>’;
$html.= woocommerce_quantity_input(array(),$product,false);
$html.='<button type=”submit” data-quantity=”1″ data-product_id=”‘.$product->get_id().'” class=”button alt ajax_add_to_cart add_to_cart_button product_type_simple”>’. esc_html($product->add_to_cart_text()).'</button>’;
$html.='</form>’;
}
return$html;
}

//Agreamos código javascript
add_action( ‘init’, ‘dcms_quantity_change’ );
function dcms_quantity_change() {
wc_enqueue_js(‘
(function( $ ) {
$(“form.cart”).on(“change”, “input.qty”, function() {
$(this.form).find(“[data-quantity]”).attr(“data-quantity”, this.value);
});
})( jQuery );
‘);
}

Entradas relacionadas

1 comentario

  • Michaeltrugs

    thc products are a within easy reach and enjoyable way to pocket cannabidiol without the high. Diverse people advantage them to quiet stress, improve rest, or promote complete wellness. The effects usually inaugurate within 30–60 minutes and can matrix for respective hours. You’ll reveal options with melatonin, vitamins, vegan ingredients, or no added sugar. They come in a wander of flavors and strengths. It’s in the most suitable way to start with a low quantity and often contain as regards third-party lab testing to insure quality and safety.

Deja tu comentario