Why form tag is missing from related products using add to cart hook?

Viewed 19

I have used the following hook to add "Add to cart" button and quantity input to product archive.

woocommerce_loop_add_to_cart_link

/* Display Quantity in product archive loop */
add_filter( 'woocommerce_loop_add_to_cart_link', 'quantity_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2 );
/**
 * Override loop template and show quantities next to add to cart buttons
 * @link https://gist.github.com/mikejolley/2793710
 */
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 customatc" method="post" enctype="multipart/form-data">';
        $html .= '<div class="quantitydiv"><button type="button" class="plus" >+</button>';
        $html .= woocommerce_quantity_input( array(), $product, false );
        $html .= '<button type="button" class="minus" >-</button> </div>';
        $html .= '<div class="atcwrap"><button type="submit" class="button alt atc">' . esc_html( $product->add_to_cart_text() ) . '</button></div>';
        $html .= '</form>';
    }
    return $html;
}

The hook works and the entire shop implements the buttons except related product section in product page.

Inspecting the area (via Chrome inspect tool) I found the <form> tag is removed from the hook on related products section only, and I couldn't find what causing this.

No Form With form

Why form tag is missing from WooCommerce related product after using woocommerce_loop_add_to_cart_link hook? And how to fix it?

Link to my website

0 Answers
Related