WPPizza – A Restaurant Plugin for WordPress › Support › General Support › Shortcode add_item_to_cart returns a category error after update
- AuthorPosts
- 13 March, 2019 at 2:40 pm #42105
The short code add_item_to_cart_button returns this error after update 3.x to Warning: reset() expects parameter 1 to be array, boolean given in /www/wp-content/plugins/wppizza/classes/markup/loop.php
Other short codes such as “single” work fine. This is not working from within the wppizza/markup/loop/theme-wprapper.php in the theme root either.
13 March, 2019 at 2:51 pm #42107updating from what version to what version exactly
in any event, that’s – most probably – because your item is not associated with any category
although i can add something that would suppress this warning, i would really suggest you select a category to go with it13 March, 2019 at 3:06 pm #42108wppizza menu items (just like normal WP posts) must be assigned to a category
if you do not set one – and when i add something in an update that deals with avoiding this warning – all that would happen is that i would force a category for you programatically (the first/top one in your wppizza categories list)
so you might as well select one that is most likely more appropriate i would thinkhope that explains things somewhat
14 March, 2019 at 9:23 pm #42132Hi and thanks for your quick reply. All the menu items are assigned to a category.
I updated the original plugin from 2.16.11.14 to 2.16.11.26 as instructed in the documentation before updating to the v3. All other short codes work fine. Apart from the warning the rendered buttons do not work to add the items to the cart. I also noticed that if I am on a say Pizzas category archive page the shortcut will work if I test with menu Items not in that category fx if I hardcode an menu item id from the drinks category the button works fine with out the warning.14 March, 2019 at 9:52 pm #42134I’d need a link to the page in question really.
the above is/was really just guesswork on the info supplied15 March, 2019 at 6:45 am #42140This reply has been marked as private.15 March, 2019 at 9:10 am #42141question:
how exactly are you generating the output of this page
/matsedill/shakes/
secondly, what happens if you use a default theme (like 2016 for example)15 March, 2019 at 9:36 am #42142from my_theme_root/wppizza/markup/loop/theme-wrapper.php
if (have_posts()) { while(have_posts()) { the_post(); $postID = get_the_ID(); echo do_shortcode("[wppizza type='add_item_to_cart_button' id='{$postID}']"); } }
I setup the twenty sixteen theme with same results for the add_item_to_card_button
15 March, 2019 at 9:55 am #42143Small update so we are just getting the shakes if we are on the shakes :
$queried_object = get_queried_object(); $queried_object_id = $queried_object->term_id; $category_title = $queried_object->name; $category_slug = $queried_object->slug; if (have_posts()) { while(have_posts()) { the_post(); $postID = get_the_ID(); if(get_query_var( WPPIZZA_TAXONOMY ) == $category_slug){ echo do_shortcode("[wppizza type='add_item_to_cart_button' id='{$postID}']"); } } }
15 March, 2019 at 1:13 pm #42149ok, using the ‘add_item_to_cart_button’ in the loop like that seems to have got lost in the porting from v2.x to v3.x
i’ll amend that in the next update . essentially in this case the category id does not get passed on if you use it like you doin the meantime, you can work around this by simply passing on the cat id as well . i.e something like this)
<?php // before the loop. $obj = get_queried_object(); $cat_id = $obj->term_id; // Start the loop. while ( have_posts() ) : the_post(); echo do_shortcode("[wppizza type='add_item_to_cart_button' id='".get_the_ID()."' category_id='".$cat_id."' ]"); endwhile; ?>
15 March, 2019 at 1:38 pm #42150thinking out loud for a sec. i wonder if this is actually down to something that changed in wordpress itself.
I am not going to spend too much time finding out if this is the case, however it is simply a matter of replacing (my end)$first_term = get_the_terms($atts['id'], WPPIZZA_TAXONOMY);
, which worked like that for years with
$first_term = wp_get_post_terms($atts['id'], WPPIZZA_TAXONOMY);
no, i don’t know either why the 1st doesnt seem to work anymore but the 2nd does. oh well
15 March, 2019 at 2:39 pm #42154Adding the category_id did the trick! Cheers!
- AuthorPosts
- The topic ‘Shortcode add_item_to_cart returns a category error after update’ is closed to new replies.