WooCommerce - always calculate shipping on update_order_review - woocommerce

I need to always fire off the calculate_shipping method when update_order_review is called on the checkout page.
I cannot find the logic where it decides whether or not to call calculate shipping. I can confirm that unless I change the shipping address or similar it does not fire off the calculate_shipping method.
I've been trying to follow the code, both from calculate_shipping up and update_order_review down but I cannot make heads or tails of it.
Tried
There is a set_calculated_shipping on the customer class method right before calculate_totals method is called on the cart class in class-wc-ajax.php I thought might be related. I tried changing the value, but it doesn't seem to affect anything.

Related

WooCommerce updating the shipping method depending on the shipping choice field changes

In my online store, there are sevral shipping methods. I added a plugin for distance delivery (Boxtal Connect)
I would like to be able to autorefresh total amount when a new shipping method is chose on the checkout page.
I think the selector is name=shipping_method[0] and the trigger is jQuery('body').trigger('update_checkout',
I would like to find an code to add on my child function.php to do it.
In fact it works well on the cart page and I think it is a native woocommerce function.
Thanks for you help

Woocommerce checkout page change country doesn't update shipping methods

Here is a screencast https://www.screencast.com/t/llJl5QZ8
When country is changed, only payment methods are updated (with ajax), but NOT shipping methods.
I have tried using additional javascript code to force triggering 'update_checkout' but no luck. The code I used was a manual call of jQuery(document.body).trigger('update_checkout') which only triggers payments update but not shipping methods.
Can someone shed a light on possible ways to debug & fix this problem?

Unique issue with WooCommerce and hiding the add to cart button..?

We have a plugin that allows people to submit offers on products, and then the site owner can accept, counter, or decline offers, and you can negotiate back and forth until a price agreement is reached.
We are using the woocommerce_after_add_to_cart_button hook to add the offer button after the cart button.
We are getting lots of feedback that people want to leave the price of the product empty so that it simply display a price on the site, it won't display the Add to Cart button, but they do want it to display the offer button and allow that functionality.
If you set the price to 0.00, then it says FREE on the site, and still includes the add to cart button, so that's no good.
When left blank, though, the problem we run into is that when a customer clicks to buy a product from an accepted offer, WooCommerce keeps removing the item out of the cart because it says it's not purchase. This is happening because of the is_purchasable() function. With a blank price WC says the product is not purchasable, so it will automatically remove itself out of the cart, which it is indeed doing.
There is a hook available that allows us to force $purchasable = true for the product, but then of course that makes the Add to Cart button show up again, which doesn't make sense for this use-case.
So as it stands now we're at that point. We've got the system overriding $purchasable so that we can complete the checkout on a product with an empty price, but it's leaving the Add to Cart button, which allows the person to add the product at 0.00.
I'm stumped on the best way to hide to the Add to Cart button in this scenario..?? I would usually hide it by using that hook to make $purchasable = false, which takes care of it nicely, but in this case I can't do that because that's what keeps us from being able to purchase the product, of course.
Any information on a way around this would be greatly appreciated!
UPDATE
I found this tutorial for overriding core template files from a plugin: https://www.skyverge.com/blog/override-woocommerce-template-file-within-a-plugin/
So I think what we're going to try is to basically say "if $purchasable = false and $offers_enabled = true, then use these templates for the add to cart button."
Within our template we're doing nothing but commenting out the actual <button> element. This leaves all hooks in place, but hides our button.
Decent solution? Horrible idea?

WooCommerce - Apply coupon of discounts of a given payment method

I'm integrating a solution with WooCommerce where a coupon of discount is given depending on the payment method that customer chooses. So, to do it, the coupon needs to be created/applyed in checkout page, when customer is selecting the payment method he wants.
Is it possible? How should I do this?
There are 2 free plugins that allow you to set discount codes based on payment methods:
https://wordpress.org/plugins/woocommerce-auto-added-coupons/ - With over 5K+ active installs, this one seems to be the right choice.
https://wordpress.org/plugins/woocommerce-payment-discounts/ - Although this one has 3K+ active installs, it is specifically meant to give discounts based on payment methods. So this does exactly what you are looking for.
Try out both plugins, preferrably 2nd one first.

Repeat triggering of 'woocommerce_payment_complete' hook for dev

'woocommerce_payment_complete' is the hook that is triggered when payment is flagged as accepted by your payment gateway in WooCommerce.
It's a really useful hook because you can make things happen as soon as payment passes.
The problem I'm having it testing custom functions I attach to the hook - it is extremely laborious.
Basically, every time I want to test one of my functions attached to this hook I have to fill up my card, go through check out, submit payment then analyse what happens. If there's a bug or error then I have to fill up my card, go through check out, submit payment then analyse what happens all over again.
I'm losing hours doing this, so I was wondering, does anyone have a dev tip to make this less time consuming?
This hook is fired after the steps which (may) include financial transactions. Testing its contents does not actually require a financial transaction, but your wordpress does have to step through shopping cart events, in order to get you to the later point where the hook is fired.
What I did was to create a 100% discount coupon, so that I do not need to bother with
financial transactions when I modify/test code involved in this hook. That way I can quickly buy something from my shopping cart and then watch my logs output messages telling me about the code that is called when this hook is called, after the shop code has done its thing.

Resources