• Resolved grifas

    (@grifas)


    Hi. Awesome plugin. Want to ask you if there is a way to implement amount field between text and add to cart button. An example is here

    Image

    Thanks

Viewing 1 replies (of 1 total)
  • Plugin Author WP Zone

    (@aspengrovestudios)

    Hi and thank you!

    Yes this is possible, but it depends on the theme you are using.

    Try adding following to the functions.php of your theme:

    To shop quantity for simple products and donations:

    /**
     *  This snippet contains code from the WooCommerce Plugin by Automatic, https://docs.woocommerce.com/document/override-loop-template-and-show-quantities-next-to-add-to-cart-buttons/ ,
     *  modified by Divi Space and/or Aspen Grove Studios, August 4th, 2021.
     *  Licensed under the GNU General Public License, no warranty;
     *  Go to https://divi.space/gnu-general-public-license/  for details.
     */
    
    /**
     * Enable quantity input in shop loop for simple products and for donations
     */
    add_filter( 'woocommerce_loop_add_to_cart_link', 'ags_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2 );
    
    function ags_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()) || $product->is_type( 'donation' ) ) )  {
    		$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;
    }
     

    OR

    to show quantity only for donation products:

    /**
     *  This snippet contains code from the WooCommerce Plugin by Automatic, https://docs.woocommerce.com/document/override-loop-template-and-show-quantities-next-to-add-to-cart-buttons/ ,
     *  modified by Divi Space and/or Aspen Grove Studios, August 4th, 2021.
     *  Licensed under the GNU General Public License, no warranty;
     *  Go to https://divi.space/gnu-general-public-license/  for details.
     */
    
    /**
     * Enable quantity input in shop loop only for donations
     */
    
    add_filter( 'woocommerce_loop_add_to_cart_link', 'ags_donations_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2 );
    
    function ags_donations_inputs_for_woocommerce_loop_add_to_cart_link( $html, $product ) {
    	if ( $product->is_type( 'donation' ) )  {
    		$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 1 replies (of 1 total)
  • The topic ‘Amount in product’ is closed to new replies.