• Resolved ariban99

    (@ariban99)


    Hi
    on my webiste kosherbasix.com i want to add a qty field in the loop, i found this woocommerce site https://docs.woocommerce.com/document/override-loop-template-and-show-quantities-next-to-add-to-cart-buttons/
    saying to post in my function.php file the below. i did that but now if you go to my page https://kosherbasix.com/product-category/household/aluminum/ and hover over an item the qty field is covering the picture and the cart icon to add to cart is a RED slab instead of the icon.
    is there something i am missing, a css code? maybe a better code than the below?

    /**
    * Override loop template and show quantities next to add to cart buttons
    */
    add_filter( ‘woocommerce_loop_add_to_cart_link’, ‘quantity_inputs_for_woocommerce_loop_add_to_cart_link’, 10, 2 );
    function quantity_inputs_for_woocommerce_loop_add_to_cart_link( $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” class=”button alt”>’ . esc_html( $product->add_to_cart_text() ) . ‘</button>’;
    $html .= ‘</form>’;
    }
    return $html;
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi @ariban99!

    The code you are using is fine, it works. Your theme, however, is doing its own thing, which is what is causing your issues here.

    You can use some CSS code to move the quantity selector to a better place, something along these lines:

    .woocommerce .product-hover-style-icons-top-right .product-actions {
    	position: initial !important;
    }
    
    .woocommerce .products .product-actions .alt, .woocommerce .products .product-actions a {
    	position: absolute !important
    }

    However, you still need to figure out the “add to cart” button.

    Cheers!

    Thread Starter ariban99

    (@ariban99)

    yes your right that works, i will ask the place i bought the theme about the icon for add to cart
    thank you for all your help

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘woocommerce loop qty’ is closed to new replies.