Skip Navigation

[Resolved] Cannot Override add_to_cart_with_quantity_ajax template

This support ticket is created 5 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 6 replies, has 2 voices.

Last updated by jonB-5 5 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#1261501

I am trying to customise add_to_cart_with_quantity_ajax.php in woocommerce-views/custom_shortcode_templates by copying the file into my theme folder then editing.

I have tried placing the edited version in themefolder/woocommerce-views/custom_shortcode_templates and in themefolder/woocommerce-views/ but neither has worked.

Can you advise on how to customise this file without loosing changes when updating my plugins?

#1261625

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jon,

Thank you for getting in touch.

The best thing to do for this is to use a hook to overwrite the default function.

I would suggest letting me know which function you want to overwrite exactly, there may be a woocommerce hook that can be used to overwrite the default function in a hook.

Thanks,
Shane

#1261635

Hi Shane,

I had originally been attempting to add a hidden input field as outlined at hidden link but I then realised that this hook doesn’t exist in the template file for this short code.

The bigger picture is that I need to get a number specified in a URL parameter on the page where the short code is output and add this to the cart_item array so it can be displayed in the cart and checkout.

Because of that I could bypass the hidden field idea but I’d still need a way to get that variable when the Add to Cart button is clicked.

#1261653

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jon,

So these are custom functions.

What you can do is to go to Toolset -> Settings -> Custom code and then add your snippets here and then activate it.

This should help you.

Thanks,
Shane

#1262139

Hi Shane,

I'm well versed in adding custom code and using hooks - the problem is that the toolset WooCommerce views shortcode template add_to_cart_with_quantity_ajax.php does not contain the WooCommerce hook that I need to use (woocommerce_before_add_to_cart_button) and furthermore it does not appear to contain any hooks that would allow me to add content within the <form> tags.

Because of this, I need to know how I can make changes to the template without loosing them when I update the plugin.

#1262487

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jon,

The hook (woocommerce_before_add_to_cart_button) should still function given that woocommerce is enabled.

I see what you mean tho since it isn't using the default templating for woocommerce thats why it doesn't work. In this case you will need to add it directly to the template file itself.

Changes made to the file itself will get overwritten when an update is performed.

Thanks,
Shane

#1262575

Hi Shane,

I have managed to debug the initial problem I was trying to solve (https://toolset.com/forums/topic/unable-to-send-custom-cart-item-data-through-wpv-woo-buy-or-select-shortcode/) and so no longer need to edit or override the plugin template files.

Thank You for your time!