Woocommerce-services: fix: error messaging appears after add to cart

Created on 9 Mar 2021  ·  6Comments  ·  Source: Automattic/woocommerce-services

Description

It looks like the error messaging introduced in earlier PRs appears immediately after adding a product to the cart.
Markup 2021-03-09 at 08 05 12

Steps to reproduce

  • Go to your site
  • You can have shipping debug on/off, doesn't matter
  • Make sure your cache is clear - as if you're a new visitor
  • Add a product to the cart
  • Messaging appears on product pages

Also reported here: https://wordpress.org/support/topic/recent-update-causes-error-messages/

[Pri] CRITICAL [Type] Bug

All 6 comments

Even with #2366 I don't think this issue is fully fixed.
Even then on the cart page you will see the error notice before you enter any address.
image

I have it 3 times because I have 3 different WCS shipping methods enabled.

It's worth noting that there is an option in WooCommerce->Settings->Shipping->Shipping Options called "Hide shipping costs until an address is entered" If this option is checked then these errors would not be shown until the customer enters shipping information.
image

This is where that option is used in the code. Ideally every store using WCS would enable this option.
https://github.com/woocommerce/woocommerce/blob/trunk/includes/class-wc-cart.php#L1545
I feel like maybe core should default it to enabled. Only sites with only flat rate shipping or local pickup shipping methods would want it disabled. There is also a filter we could use woocommerce_cart_ready_to_calc_shipping so we could add our own logic around this. We could also use a pre or post get_option filter to force the option to always be checked.

I feel we should add add_filter( 'pre_option_woocommerce_shipping_cost_requires_address', function() { return 'yes' } ) in our plugin whenever a WCS shipping method is enabled.

@frosso - FYI your questions were answered at https://wordpress.org/support/topic/recent-update-causes-error-messages/#post-14157104. I'm going to leave that thread open for now should you have any other questions.

@superdav42 , should we reconsider the approach on this and not show the notice on top of the cart page?

I feel a little concerned about unintended effects of forcing that option (though I do see your point about it).

/cc @bborman22

Hello– I'm the OP on the wordpress.org support forum.

@superdav42

Ideally every store using WCS would enable this option.

We are using the Local Pickup Plus plugin to offer local pickup as a shipping option. I can’t enable the “_Hide shipping costs until an address is entered_” option. We have to disable it to allow the _Local Pickup Plus_ shipping option to be available without entering a billing address.

Customers who want to pickup their orders complain they can't see pickup as an option prior to entering their billing address when that option is enabled. And the ones that don't complain, drop out not realizing pickup is an option after entering their billing address.

From our perspective, we'd appreciate a fix to this error that doesn't rely on that shipping option being enabled. I'm not even sure why that error now exists when it hasn't for years; but hopefully you'll figure out a solution that works for everyone.

Thanks for your hard work on this!! Much appreciated and highly anticipated!

I see two options for fixing this problem.

Option 1:
Remove all shipping validation cart notices from the code. We can still keep the improved error message which overrides the "No shipping rates..." message.

Option 2:
Keep the cart notices but only show them in the right context.
So the conditions in which the cart notices are show would be:

  • "Hide shipping costs until an address is entered" option has been enabled by the merchant
  • No non-WCS shipping methods are enabled. We would add a filter like add_filter( 'pre_option_woocommerce_shipping_cost_requires_address', function() { return 'yes' } ) which would force the option to be enabled.

So if neither of these conditions are met we would not show cart notices. Basically the only code changes would be to check if the woocommerce_shipping_cost_requires_address option is enabled before we add the notice. and add this line add_filter( 'pre_option_woocommerce_shipping_cost_requires_address', function() { return 'yes' } ) when the WCS shipping method is loaded and no other methods are enabled.

Fixed in 1.25.10

Was this page helpful?
0 / 5 - 0 ratings