helgatheviking / add-to-cart-form-shortcode

Add [add_to_cart_form] shortcode that display a single product add to cart form for WooCommerce

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Could you explain how to use this on my website?

lgdelai opened this issue · comments

Hi. Thanks for sharing this.

Could you explain how to use this on my website?

I already have a child theme installed.

I would like to replace the current shortcode [add_to_cart] with yours, using the same name.

To see if so the quantity field will be displayed in my products listed by ContentViews.

But I don't know how to insert this code, I tried to add to the functions.php file but it didn't work.

commented

Download the zip from github: https://github.com/helgatheviking/add-to-cart-form-shortcode/archive/refs/heads/master.zip and install it as a WordPress plugin.

Then you should be able to use the shortcode as described... ie: [add_to_cart_form id="99"]

I'm not familiar with ContentViews and can't really provide any advice for that.

Got it,
Your plugin displays the quantity fields.

But it doesn't use ajax when I click add to cart.
Look: https://roquesburger.com/

I'm not familiar with ContentViews and can't really provide any advice for that.

This is the part of the ContentView code that displays the shortcode, maybe this will help.

                 // Show Price
                 'price' case:
                     if ( $post_type === 'product' ) {
                         $html = do_shortcode( sprintf( '[add_to_cart id="%s" style=""]', $post->ID ) );
                     }

                     break;

For your plugin to work I replace it
[add_to_cart
per
[add_to_cart_form

In the code above. But as I said, he is not using ajax to add to cart.
Is it possible to adjust this?

Obs.: Without using your plugin, as native shortcode.
The button works with Ajax. (However the quantity field is not displayed)

What I'm trying to do is make the button work with ajax and with the quantity field also being displayed.

This code:
https://gist.github.com/webaware/6260468
Makes the quantity field display all over the site, and it works with ajax (It doesn't work in shortcodes, however)

Yours already works in Shortcodes, (but it doesn't use ajax).

It's a very complicated situation.
Do you think it's possible to adjust your plugin so that it works in ajax?

commented

But it doesn't use ajax

No, it doesn't. That's expected (and in line with Woo's default single product page). I'm sure it could be adjusted to use ajax.

A button needs to have add_to_cart_button and ajax_add_to_cart and the data-product_id attribute for it to automatically have the WooCommerce ajax add to scripts handle that for you.

You would need to change the shortcode's output to be sure all those classes and attributes are present. And then Woo's default script might handle it for you... though I am not sure about who it handles quantity off the top of my head.

I found a very simple plugin that does what I need.
I think I will use it.
https://br.wordpress.org/plugins/quantity-field-on-shop-page-for-woocommerce/

Displays quantity field on all products (including shortcode) and works with ajax.

It just doesn't display variations like yours.
I think I'll use it, it's a very simple plugin, like yours, it only has 1 php file and another css.

Thank you so much for sharing your knowledge with me.

Helped me a lot.

Oi Guilherme (@lgdelai),

Agradeça a Kathy aqui: https://www.paypal.com/fundraiser/charity/1451316

Abraços,
Gabriel

commented

Very cool... glad you found the tool you need.