Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7529487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:40:18+00:00 2026-05-30T04:40:18+00:00

I am using jcart http://conceptlogic.com/jcart/ to create some cart functionality in wordpress. I am

  • 0

I am using jcart http://conceptlogic.com/jcart/ to create some cart functionality in wordpress.

I am trying to access a jcart function within another function in my functions.php file.

foreach($jcart->get_contents() as $item) {
    $psitems[] = $item['id'];
}

This code works fine on functions.php itself or on any template page– it creates the $psitems array so I can check if that array contains certain values.

Now, within the following function:

function gallery_shortcode_fancybox($attr) { ...

I have the following:

foreach($jcart->get_contents() as $item) {
    $psitems[] = $item['id'];
}

foreach ( $attachments as $id => $attachment ) {
    $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_image($id, 'full', false, false) : wp_get_attachment_image($id, 'full', true, false);

    $output .= "<div class='property'>";
    $output .= "$link";
    $output .= '
        <div class="property-details">
            <div class="property-details-inner">

                <form method="post" action="" class="jcart">
                    <fieldset>
                        <input type="hidden" name="jcartToken" value="' . $_SESSION['jcartToken'] . '" />
                        <input type="hidden" name="my-item-id" value="' . $id . '" />
                        <input type="hidden" name="my-item-name" value="Photo #' . $id . '" />
                        <input type="hidden" name="my-item-url" value="' . wp_get_attachment_url( $id ) . '" />
                        <input type="hidden" name="my-item-qty" value="1" size="3" />';

    if(in_array($id,$psitems)) {
        $output .= '<span class="action terminal pull-sheet">Image in Pullsheet</span>'
    } else {
        $output .=          '<input type="submit" name="my-add-button" value="Add to Pull Sheet" class="action terminal pull-sheet" />';
    }
    $output .=              '</fieldset>
                </form>
            </div> <!-- property-details-inner -->
        </div>';
    $output .= "</div>";
}

return $output;

I get the following error:

Call to a member function get_contents() on a non-object

If I try placing the original foreach($jcart->get_contents() as $item) { ... code outside of the function, I get the following error:

Warning: in_array() expects parameter 2 to be array, null given in...

How can I access this array inside the function and avoid these errors?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:40:19+00:00Added an answer on May 30, 2026 at 4:40 am

    Regarding the first error, it means that you have to initialize $jcart.

    As for the warning, try this:

    $array = $jcart->get_contents();
    foreach ($array as $item) ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the http://www.ifans.com/forums/showthread.php?t=132024 post from another question i am allowing the user to enter
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using Google Maps InfoBox - http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html Currently the map will scroll - pan control
Using linq2sql I'm trying to take the string in txtOilChange and update the oilChange
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Using Rails 3.2.0 with haml, sass and coffeescript: Basically I am trying to disable
While using jCart I noticed that it did not work on the iPhone. After
Using Entity Framework CodeFirst, how do I create a created datetime column that gets
I am trying to echo out an array using for each but it's not
Using jQuery UI Resizable I'm trying to prevent resizing based on various rules. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.