How to call WooCommerce update cart function programatically

I am rendering WooCommerce Cart items in a custom html table wrapper by a form that points to a custom PHP file.

<form class="woocommerce-cart-form" action="/update-cart.php" method="POST">
    ...
    <input type="submit" name="update_cart" value="Update cart">
</form>

When I click on update cart, I get redirected via POST to update-cart.php where I do some business related actions with the PHP $_REQUEST.

After doing those actions, I want to call to the WooCommerce original update action, but I am stucked.

This is what I have tried:

// Non of this has worked for me

do_action('woocommerce_update_cart_action_cart_updated'); // 1

WC()->cart->persistent_cart_update(); // 2

do_action('update_cart_action'); // 3

How should I call WooCommerce’s update action?

Thank you.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The default form handler is a static method which you can call with

WC_Form_Handler::update_cart_action();


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x