Shortcode add_item_to_cart returns a category error after update

WPPizza – A Restaurant Plugin for WordPress Support General Support Shortcode add_item_to_cart returns a category error after update

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #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.

    #42107
    Olly
    Admin & Mod

      updating 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 it

      #42108
      Olly
      Admin & Mod

        wppizza 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 think

        hope that explains things somewhat

        #42132

        Hi 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.

        #42134
        Olly
        Admin & Mod

          I’d need a link to the page in question really.
          the above is/was really just guesswork on the info supplied

          #42140
          This reply has been marked as private.
          #42141
          Olly
          Admin & Mod

            question:
            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)

            #42142

            from 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

            #42143

            Small 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}']");
            }
            }
            }
            #42149
            Olly
            Admin & Mod

              ok, 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 do

              in 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;
              ?>
              
              #42150
              Olly
              Admin & Mod

                thinking 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

                #42154

                Adding the category_id did the trick! Cheers!

              Viewing 12 posts - 1 through 12 (of 12 total)
              • The topic ‘Shortcode add_item_to_cart returns a category error after update’ is closed to new replies.