Advertisement
oscarviedma

Agregar botón añadir carrito y el campo cantidad al módulo tienda

Nov 21st, 2020
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. /** Agregar botón de "añadir a carrito" en los productos del módulo tienda **/
  2. add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 20 );
  3.  
  4. /** Agregar campo de cantidad en los productos de la tienda woo **/
  5. function ov_agregar_campo_cantidad_productos_tienda() {
  6.  
  7. $product = wc_get_product( get_the_ID() );
  8.  
  9. if ( ! $product->is_sold_individually() && 'variable' != $product->product_type && $product->is_purchasable() ) {
  10. woocommerce_quantity_input( array( 'min_value' => 1, 'max_value' => $product->backorders_allowed() ? '' : $product->get_stock_quantity() ) );
  11. }
  12.  
  13. }
  14. add_action( 'woocommerce_after_shop_loop_item', 'ov_agregar_campo_cantidad_productos_tienda', 15, 9 );
  15.  
  16.  
  17. function custom_add_to_cart_quantity_handler() {
  18. wc_enqueue_js( '
  19. jQuery( "body" ).on( "click", ".quantity input", function() {
  20. return false;
  21. });
  22. jQuery( "body" ).on( "change input", ".quantity .qty", function() {
  23. var add_to_cart_button = jQuery( this ).parents( ".product" ).find( ".add_to_cart_button" );
  24. // For AJAX add-to-cart actions
  25. add_to_cart_button.attr( "data-quantity", jQuery( this ).val() );
  26. // For non-AJAX add-to-cart actions
  27. add_to_cart_button.attr( "href", "?add-to-cart=" + add_to_cart_button.attr( "data-product_id" ) + "&quantity=" + jQuery( this ).val() );
  28. });
  29. ' );
  30. }
  31. add_action( 'init', 'custom_add_to_cart_quantity_handler' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement