Zen Cart Logo
Forums / General Questions / PHP Fatal error: Uncaught Error: [] operator not supported for strings

PHP Fatal error: Uncaught Error: [] operator not supported for strings

Views: 1,420

Results 1 to 7 of 7
5 Sep 2019, 10:28 PM
#1
chadlly2003 avatar

chadlly2003

Totally Zenned

Join Date:
Jan 2015
Posts:
748
Plugin Contributions:
0

PHP Fatal error: Uncaught Error: [] operator not supported for strings

I am worrking on creating a pixel for facebook. I got everything to work except on the checkout success page I get an error

Below is the code causing the error. Can someone assist me or lead me in the right direction on getting this solved.

PHP Fatal error: Uncaught Error: [] operator not supported for strings in xxx

$product_ids[] = (int)$product['id'];

5 Sep 2019, 10:57 PM
#2
chadlly2003 avatar

chadlly2003

Totally Zenned

Join Date:
Jan 2015
Posts:
748
Plugin Contributions:
0

Re: PHP Fatal error: Uncaught Error: [] operator not supported for strings

sorry here is the piece of code. The error is coming from $product_ids[] = (int)$product['id'];


case FILENAME_CHECKOUT_SUCCESS:
if ($zv_orders_id > 0) {
if(!class_exists('order')) require_once DIR_WS_CLASSES . 'order.php';
$order = new order($zv_orders_id);
$products = $order->products;
foreach ($products as $product) {
$product_ids[] = (int)$product['id'];
}
echo "fbq('track', 'Purchase', {\n
value: " . number_format($order->info['total'], 2, '.', '') . ",\n
currency: '" . $_SESSION['currency'] . "',\n
content_type: 'product',\n
content_ids: ['" . implode("','", $product_ids) . "']\n
});";
}
break;

5 Sep 2019, 11:21 PM
#3
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,782
Plugin Contributions:
21

Re: PHP Fatal error: Uncaught Error: [] operator not supported for strings

Maybe:

case FILENAME_CHECKOUT_SUCCESS:
if ($zv_orders_id > 0) {
if(!class_exists('order')) require_once DIR_WS_CLASSES . 'order.php';
$order = new order($zv_orders_id);
$products = $order->products;
fbp_pids = array();
foreach ($products as $product) {
$fbp_pids[] = (int)$product['id'];
}
echo "fbq('track', 'Purchase', {\n
value: " . number_format($order->info['total'], 2, '.', '') . ",\n
currency: '" . $_SESSION['currency'] . "',\n
content_type: 'product',\n
content_ids: ['" . implode("','", $fbp_pids) . "']\n
});";
}
break; 
5 Sep 2019, 11:47 PM
#4
chadlly2003 avatar

chadlly2003

Totally Zenned

Join Date:
Jan 2015
Posts:
748
Plugin Contributions:
0

Re: PHP Fatal error: Uncaught Error: [] operator not supported for strings

I tried your suggestion but it did not seem to work. Any other ideas?

5 Sep 2019, 11:51 PM
#5
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: PHP Fatal error: Uncaught Error: [] operator not supported for strings

chadlly2003:

I tried your suggestion but it did not seem to work. Any other ideas?

Please elaborate on "did not seem to work". Did the error go away? Did the desired result get seen? What didn't work? What error(s) are now being generated with the modification that balihr suggested (which looks reasonable).

Other than there is a dollar sign missing
fbp_pids = array();
Should be:
$fbp_pids = array();

5 Sep 2019, 11:57 PM
#6
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,782
Plugin Contributions:
21

Re: PHP Fatal error: Uncaught Error: [] operator not supported for strings

mc12345678:

Please elaborate on "did not seem to work". Did the error go away? Did the desired result get seen? What didn't work? What error(s) are now being generated with the modification that balihr suggested (which looks reasonable).

Other than there is a dollar sign missing
fbp_pids = array();
Should be:
$fbp_pids = array();

:bangin::bangin:

Sorry for the typo... mc12345678 is right, there's a dollar sign missing. Try this:

case FILENAME_CHECKOUT_SUCCESS:
if ($zv_orders_id > 0) {
if(!class_exists('order')) require_once DIR_WS_CLASSES . 'order.php';
$order = new order($zv_orders_id);
$products = $order->products;
$fbp_pids = array();
foreach ($products as $product) {
$fbp_pids[] = (int)$product['id'];
}
echo "fbq('track', 'Purchase', {\n
value: " . number_format($order->info['total'], 2, '.', '') . ",\n
currency: '" . $_SESSION['currency'] . "',\n
content_type: 'product',\n
content_ids: ['" . implode("','", $fbp_pids) . "']\n
});";
}
break;
6 Sep 2019, 12:37 AM
#7
chadlly2003 avatar

chadlly2003

Totally Zenned

Join Date:
Jan 2015
Posts:
748
Plugin Contributions:
0

Re: PHP Fatal error: Uncaught Error: [] operator not supported for strings

that work thank you......