Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter llupien

    (@llupien)

    With further troubleshooting I’ve determined it’s the custom child theme that a previous developer had put in place (a child of Themify Shoppe). They were producing a “link” for a button for Add to Cart, somehow that was not working with default quantity. I am overriding whatever they did by putting the base function WooCommerce suggested into the child theme functions.php which adds a form with button instead of just a link (had to restyle the default button CSS again but that’s easy). Then for the user group in question, I’m just hiding the quantity field with CSS, as I’ve already added a function to put the User Role into the body tag. (This also gives Admins access to a qty field in the Product Archive page, as they will be doing custom purchases of more than 2 in certain circumstances, making their job easier!)

    /**
    * 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 product_type_simple add_to_cart_button ajax_add_to_cart">' . esc_html( $product->add_to_cart_text() ) . '</button>';
    
    ????????$html .= '</form>';
    
    ????}
    
    ????return $html;
    
    }

    Adding this solution here for anyone who encounters the same issue.

Viewing 1 replies (of 1 total)