Forum Replies Created

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

    (@gvoji)

    I took me a long time to figure this out, so it may help someone. Probably it is not the best solution but I dont know much of ajax or .js nor i found a better solution

    I installed the following plugins:

    Ajax add to cart for WooCommerce
    Quantity Plus Minus Button for WooCommerce by CodeAstrology
    Header Footer Code Manager
    Code Snippets

    ———————————————————————————-

    Header Footer Code Manager I put into Header:
    change localhost to your domain

    <script src="https://localhost/wp-content/plugins/woo-ajax-add-to-cart/assets/frontend/woo-ajax-add-to-cart.min.js?ver=2.2.0" id="woo-ajax-add-to-cart-js"></script>

    type: javascript
    sitewide
    header

    ————————————————————————–

    code snippets “php” I had to add woocommerce to body class in order to have a spinning icon during the action

    add_filter( 'body_class', 'custom_body_class' );
    /**
     * Add custom body class(es) to the body classes.
     *
     * @param array $classes Existing body classes.
     * @return array Amended body classes.
     */
    function custom_body_class( array $classes ) {
    	// Add "woocommerce" class to the body classes
    	$classes[] = 'woocommerce';
    
    	return $classes;
    }

    ———————————————————————————–
    Added the button to the page
    add new page
    add gutenberg block: custom html

    add this code:

    <form class="cart" action="https://localhost/" method="post" enctype="multipart/form-data">
    	<div class="qib-button qib-button-wrapper qib-button-wrapper-4452">
    		<label class="screen-reader-text" for="quantity_649600f4ab29f">Quantity</label>
    
    		<button type="button" class="minus qib-button">-</button>
    		<div class="quantity wqpmb_quantity">
    			<input
    				type="number"
    				id="quantity_649600f4ab29f"
    				class="wqpmb_input_text input-text qty text"
    				step="1"
    				data-product_id="4452"
    				data-variation_id=""
    				min="1"
    				max=""
    				name="quantity"
    				value="1"
    				title="Qty"
    				size="4"
    				placeholder=""
    				inputmode="numeric"
    			/>
    		</div>
    		<span class="wqpmb_plain_input hidden">1</span>
    
    		<button type="button" class="plus qib-button">+</button>
    	</div>
    
    	<button type="submit" name="add-to-cart" value="4452" class="single_add_to_cart_button button alt">Add to cart</button>
    </form>
    

    change localhost to your domain
    change “4452”s to your product ID

    With this you can add a nice plus minus add to cart ajax button anywhere on your site.
    when you press the button an icon will spin, after product added a checkmark will appear with a view cart link next to it. looks nice



    keywords:
    Ajax add to cart button anywhere on your site page, ajax add to cart button into price table, or place it on any page

    • This reply was modified 1 year, 8 months ago by gvoji.
Viewing 1 replies (of 1 total)