2
votes

I have developed a custom build on woocommerce.

All is fine except for the checkout page.

The site ships to UK only, and i have Flat Rate shipping enabled.

However, on the checkout page there are two issues. The first is an invalid argument in a foreach loop:

Warning: Invalid argument supplied for foreach() in /home/****/public_html/wp-content/plugins/woocommerce/includes/class-wc-shipping.php on line 291

And the second problem is:

There doesn‘t seem to be any available shipping methods. Please double check your address, or contact us if you need any help.

I am bashing my head against a wall here. I have a shipping method enabled, so why is it continuing to tell me there is no method available?

All i want it to do there is simply list all the shipping methods i have enabled so the user can select one.

I also noticed that the shipping methods display when user is not logged in, but when they are logged in it shows Flat Rate - then a random price that isn't entered anywhere in admin.

To elaborate a little. This problem does not occur if i add a variable product to the art using the ?add-to-cart url, but as soon as i use the add_to_cart function it causes those errors.

woocommerce->cart->add_to_cart(522,1, 523,array("attribute_colour" => "colour","attribute_size" => "a3", "attribute_invoice-numbering" => "yes", "attribute_quantity-column" => "yes", "attribute_cc-type" => "duplicate"));

The above code works fine if it is used in a URL, but i want to call it via ajax with the function.

2
Do you have any admin notices about out of date templates? or Do you still see this problem if you revert to Twenty Fourteen? I ask because this just reminds me of some errors I saw when updating WooCommerce once. Additionally, what version of WooCommerce are you using? - helgatheviking
I am using the latest version, and i have removed any custom templates in the theme and the problem still happens. It seems to think there are no shipping methods for some reason. - Glen
in fact it doesn't happen on twenty fourteen, i am wondering if it's down to the custom add to cart code in my own theme. - Glen
It seems as though cart->add_to_cart does this. When i use twenty fourteen it's fine. I wonder if i am somehow formatting the params wrong. Although it takes product id, variation id, variation attributes - should be fine - Glen
Right, well it worked for a bit on twenty 14, now it just produces the same problem with the shipping - Glen

2 Answers

0
votes
  1. Go to woo commerce settings and add a shipping zone. See here.

  2. On existing products and when adding new products always ensure u set the shipping location. See here

0
votes

I had a similar problem, I got that message even if Shipping Zones and Shipping Methods were configured correctly. I expected just one flat rate, no choices available. Doing more tests the bug disappeared when there were 2 or more methods available, it was weird. I found the issue in the theme template, the first control was a wrong:

if ( 1 < count( $available_methods ) ) : 

instead of

if ( $available_methods ) :

Perhaps you have a bug in the theme template too. You can do a diff/compare between the original template (/wp-content/plugins/woocommerce/templates/cart/cart-shipping.php) and the custom file (/wp-content/themes/YOURTHEME/woocommerce/cart/cart-shipping.php)