Invalid argument foreach() error in WordPress Shopping Cart Plugin

my cart iconFor the longest time I held off upgrading any of my client’s stores using WP-Shopping Cart plugin because on my test install of WP I could not get RC1 3.6.8 to work.But it really bothers me not to use the latest version of something so on one client site I did the upgrade and tested it out.I got the same exact errors I got on my test install after trying to checkout/submit and have the payment sent to PayPal.

The old invalid argument foreach() error.

Going to the forum I did not see a way to fix this probably because everyone has different causes for this error? I’m not really sure but there should be definite documentation on how to get rid of so people can have a working cart.

Error Log Messages
This error:
WordPress database error Unknown column ‘files’ in ‘field list’ for query INSERT INTO `wp_cart_contents` ( `prodid` , `purchaseid`, `price`, `pnp`, `gst`, `quantity`, `donation`, `no_shipping`, `files` ) VALUES (’18’, ’75’,’64.50′,’0′, ‘0’,’1′, ‘0’, ‘1’, ”) made by nzshpcrt_submit_checkout

Led to this error:

PHP Warning: Invalid argument supplied for foreach() in /xxx/web10/xxxx/pow.xxxl/htdocs/site/wp-content/plugins/wp-shopping-cart/merchants/paypal_multiple.php on line 82

And this all led to the cart being empty and the logs printing the price as 0.00. If the cart can’t put the order into the wp_cart_contents table it can’t process the order. Not being able to fill in the info leads to a PHP error.

Let’s look at this message again:
WordPress database error Unknown column ‘files’ in ‘field list’ for query INSERT INTO `wp_cart_contents` ( `prodid` , `purchaseid`, `price`, `pnp`, `gst`, `quantity`, `donation`, `no_shipping`, `files` ) VALUES (’18’, ’75’,’64.50′,’0′, ‘0’,’1′, ‘0’, ‘1’, ”) made by nzshpcrt_submit_checkout

Everyone of those fields has to be in the wp_cart_contents table in your WP database.If your cart works perfectly all the way up to trying to test if orders can be processed- chances are when you upgraded a field or 2 even were not created.This can happen to WP upgrades as well.It is not a failing of the cart plugin.The fact that some people have no problem upgrading anything speaks to this.

The wp_cart_contents table.
——————-Type——– –Collation — —-Attributes— — — —Null—- — Default
purchaseid—–bigint(20) ——– —– — -UNSIGNED— – — — -No—— ——0
prodid—— – bigint(20) —– —— — — -UNSIGNED– — — –No—— ——0

——————Type———- —–Collation——- —-Attributes— ——Null——-Default
price——-varchar(128)——–latin1_swedish_ci ————– ——–No———-0
pnp———varchar(128)——–latin1_swedish_ci ——– — —– —-No———-0
gst ———varchar(128)——–latin1_swedish_ci ——- ——— – — No———0
quantity– –int(10)———————————— -UNSIGNED— — No ———-0
donation– -varchar(1) ——— latin1_swedish_ci—- —— — —— No ———0
no_shipping – varchar(1)——–latin1_swedish_ci ——— —- — — – No ———- 0
files ——- —text—————-latin1_swedish_ci——— —— — — No ———-

I know it isn’t really a table but it will have to do.

Fixing It
First check your error logs. It’s good to check your error logs the very first sign of trouble. If you can see the same kind of errors that I printed here you are having the same problem I was: field files was not added to the wp_cart_contents table when I upgraded. How pesky.

1st, log into your control panel find Manage Mysql and when you are in the manage mysql area, click on Administer for your WordPress database.

When you are in, look in the left side panel for wp_cart_contents. Click on it.

Please check to see if a “files” line has been added after the no_shipping line in wp_cart_contents.
If not, don’t be scared. It is easy-peasy to add a field to a database table.If the field called files is already there your problem is being caused by something else.Check the table for missing fields you can use my ugly “graph” up above.There should be 9 fields.If anyone of these fields is missing from the table you are going to get the invalid argument foreach() error.

If the field for “files” was not added – no_shipping will be the last field in this table.It was for me.

Look for this option it’s usually underneath the bottom of the table (my host uses phpMyAdmin some other managers will be set up differently).

Add 1 field(s) At End of Table.

Leave the 1 field to be added. Leave the radio button for At End of Table selected.

Then look for the go button-Click go.

In the Field text box, type files and use all use lowercase.

In VARCHAR dropdown list, select TEXT.

Leave everything else alone and click the save button.It’s very important to save it or the field will not get added.

Test it Out!
You should now be able to add an item to the cart and checkout and send the payment to PayPal with no more errors and blank orders in the purchase logs,

if all your checkout and payment settings in the admin for the plugin are correct and there aren’t any other issues with the plugin besides the ones I have written about.

2 thoughts on “Invalid argument foreach() error in WordPress Shopping Cart Plugin”

    1. I approved this comment because I love it when people ask me stuff in German!
      Anyway,ahem, this post is regarding the problem of when you install the wordpress shoppingcart plugin and not all the tables get created in the database you are using to run your wordpress install. This actually happened to me on one website after upgrading from one version of the plugin to the latest version. The new version of the plugin needed to create some new tables but couldn’t for some reason.So I wrote about how to add the missing table manually.This probably was not the most statistically helpful post I’ve ever written but it will definitely help anyone who had this exact problem.

Comments are closed.