Woocommerce error in log - product called incorrectly

Hi,

I’m noticing an error in my log, which happens every time the checkout page is hit.

“PHP message: id was called incorrectly. Product properties should not be accessed directly. Backtrace: require(‘wp-blog-header.php’), require_once(‘wp-includes/template-loader.php’), do_action(‘template_redirect’), WP_Hook->do_action, WP_Hook->apply_filters, WC_AJAX::do_wc_ajax, do_action(‘wc_ajax_update_order_review’), WP_Hook->do_action, WP_Hook->apply_filters, WC_AJAX::update_order_review, woocommerce_order_review, WooCommerce->checkout, WC_Checkout::instance, do_action(‘woocommerce_checkout_init’), WP_Hook->do_action, WP_Hook->apply_filters, learndash_woocommerce->force_login, WC_Abstract_Legacy_Product->__get, wc_doing_it_wrong. This message was added in version 3.0”

This seems to be coming from x theme. Anyway I can fix this?

Thanks!

Hello @FreekR,

Thanks for asking. :slight_smile:

For the error message you are getting, please try out following solution:

  1. Ensure everything is up to date according to our version compatibility list here. Please follow the best practices when updating your theme and plugins. Click here for more information.
  2. Test for a plugin conflict. You can do this by deactivating all third-party plugins, and see if the problem remains. If it’s fixed, you’ll know a plugin caused the problem, and you can narrow down which one by reactivating them one at a time.

Let us know how it goes.

Thanks.

Hi Prasant,

Thanks for looking into this. After doing some more research, I found that this is probably related to the following:

“Accessing directly product data is not allowed, e.g. $product->id. Correct method going forward is $product->get_id().”

It seems in one of the woocommerce templates that are part of x theme called single-product-reviews.php.

Is it correct that this template needs to be updated?

Thanks, Freek

Hi Freek,

Please note that the latest supported version of woocommerce is Version: 3.5.1

Kindly check that you have the following version numbers

Pro 2.3.8 (If you are using PRO)
X 6.3.8,
Cornerstone 3.3.8
WooCommerce: | Latest Supported Version: 3.5.1

If you find anything to be out of date, you can review our update guide.

I am also sending the download link for woocommerce in case you need to downgrade.

https://github.com/woocommerce/woocommerce/archive/3.5.1.zip

If this does not help, please provide us your site url and admin login in Secure Note

Thanks

Hi Paul,

I installed 3.5.1 on a staging environment but the issue persists.

Any thoughts on what else might be causing this?

Thanks, Freek

Hello Freek,

Could you please update to the latest versions?
Our latest versions are:

  • X theme 6.4.1
  • Cornerstone 3.4.1

This latest release contains fixes for several issues so be sure to check out the changelog (http://theme.co/changelog/).

_After doing the updates, always remember to clear all caches (if you are using WP Rocket, WP SuperCache or W3 Total Cache) when updating so that the code from the latest release is always in use. This will help you to avoid any potential errors.-

Please let us know how it goes.

Hi RueNel,

Updated, cleared all caches but the error still shows in the log.

I took a look in the changelog, but couldn’t find anything that seemed to relate to this issue.

Let me know what further steps might be taken.

Thanks!

Hi @FreekR,

Is that an error or a warning? Does it cause white screen or internal server error?

I’m not getting any internal error related to product->get_id() on the said template, so it’s probably just a notice or warning. I recommend turning off your Wordpress debugging (like setting WP_DEBUG to false within wp-config.php file). SOme hosting configuration will override Wordpress debugging messages so turning off through Wordpress may not work, so please turn off it through your host.

When WP_DEBUG or error reporting is active, it will display all kinds of messages and not just errors.

Thanks!

@Rad I am having this same issue and am running the most current of everything.

WordPress 5.0.1
WooCommerce 3.5.2 and X Pro 2.4.1 with the Pro Child Theme 1.0.0.

The error is from where the theme appears to be trying to call the product ID directly which should not be the case. It appears that method has been deprecated. This started happening after the latest upgrades. The errors from my logs are below.

When trying to edit the products it is failing and returning a 502 Error page.

I have an open ticket with WooCommerce on this as well, but it appears to be a theme issue.

Hello @klevur and Freek,

“Accessing directly product data is not allowed, e.g. $product->id. Correct method going forward is $product->get_id().”
It seems in one of the woocommerce templates that are part of x theme called single-product-reviews.php.

You might have this error in one of the files in your child theme because in the latest version of X/Pro theme, this is the contents of single-product-reviews.php

<?php

// =============================================================================
// WOOCOMMERCE/SINGLE-PRODUCT-REVIEWS.PHP
// -----------------------------------------------------------------------------
// @version 3.5.0
// =============================================================================

GLOBAL $product;

if ( ! defined( 'ABSPATH' ) ) {
  exit; // Exit if accessed directly
}

if ( ! comments_open() ) {
  return;
}

$stack         = x_get_stack();
$stack_comment = 'x_' . $stack . '_comment';

if ( $stack == 'ethos' ) {
  $placeholder_name    = ' placeholder="' . __( 'Your Name *', 'woocommerce' ) . '"';
  $placeholder_email   = ' placeholder="' . __( 'Your Email *', 'woocommerce' ) . '"';
  $placeholder_comment = ' placeholder="' . __( 'Your Comment *', 'woocommerce' ) . '"';
} else {
  $placeholder_name    = '';
  $placeholder_email   = '';
  $placeholder_comment = '';
}

?>

<div id="reviews">
  <div id="comments" class="x-comments-area">

    <h2>
      <?php
      if ( get_option( 'woocommerce_enable_review_rating' ) === 'yes' && ( $count = $product->get_rating_count() ) ) {
        printf( _n( '%s review for %s', '%s reviews for %s', $count, 'woocommerce' ), $count, get_the_title() );
      } else {
        _e( 'Reviews', 'woocommerce' );
      }
      ?>
    </h2>

    <?php if ( have_comments() ) : ?>
      <ol class="x-comments-list">
        <?php wp_list_comments( apply_filters( 'woocommerce_product_review_list_args', array( 'callback' => $stack_comment ) ) ); ?>
      </ol>
      <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?>
        <nav class="x-pagination">
          <?php
          paginate_comments_links( apply_filters( 'woocommerce_comment_pagination_args', array(
            'prev_text' => '&larr;',
            'next_text' => '&rarr;',
            'type'      => 'list',
          ) ) );
          ?>
        </nav>
      <?php endif; ?>
    <?php else : ?>
      <p class="woocommerce-noreviews"><?php _e( 'There are no reviews yet.', 'woocommerce' ); ?></p>
    <?php endif; ?>

  </div>

  <?php if ( get_option( 'woocommerce_review_rating_verification_required' ) === 'no' || wc_customer_bought_product( '', get_current_user_id(), $product->id ) ) : ?>

    <div id="review_form_wrapper">
      <div id="review_form">

        <?php

        $commenter = wp_get_current_commenter();

        $comment_form = array(
          'title_reply'          => have_comments() ? __( '<span>Add a Review</span>', 'woocommerce' ) : __( 'Be the First to Review', 'woocommerce' ) . ' &ldquo;' . get_the_title() . '&rdquo;',
          'title_reply_to'       => __( 'Leave a Reply to %s', 'woocommerce' ),
          'comment_notes_before' => '',
          'comment_notes_after'  => '',
          'fields'               => array(
            'author' => '<p class="comment-form-author">'
                        . '<label for="author">' . __( 'Name', 'woocommerce' ) . ' <span class="required">*</span></label>'
                        . '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $placeholder_name . ' /></p>',
            'email'  => '<p class="comment-form-email">'
                        . '<label for="email">' . __( 'Email', 'woocommerce' ) . ' <span class="required">*</span></label>'
                        . '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $placeholder_email . ' /></p>',
          ),
          'label_submit'  => __( 'Submit Review', 'woocommerce' ),
          'logged_in_as'  => '',
          'comment_field' => ''
        );

        if ( get_option( 'woocommerce_enable_review_rating' ) === 'yes' ) {

          $comment_form['comment_field'] = '<select name="rating" id="rating">
                                              <option value="">'  . __( 'Rate&hellip;', 'woocommerce' ) . '</option>
                                              <option value="5">' . __( 'Perfect', 'woocommerce' ) . '</option>
                                              <option value="4">' . __( 'Good', 'woocommerce' ) . '</option>
                                              <option value="3">' . __( 'Average', 'woocommerce' ) . '</option>
                                              <option value="2">' . __( 'Not that bad', 'woocommerce' ) . '</option>
                                              <option value="1">' . __( 'Very Poor', 'woocommerce' ) . '</option>
                                            </select>';

        }

        $comment_form['comment_field'] .= '<p class="comment-form-comment">'
                                          // . '<label for="comment">' . __( 'Your Review', 'woocommerce' ) . '</label>'
                                          . '<textarea id="comment" name="comment" cols="45" rows="8"' . $placeholder_comment . '></textarea></p>';

        comment_form( apply_filters( 'woocommerce_product_review_comment_form_args', $comment_form ) );

        ?>

      </div>
    </div>

  <?php else : ?>

    <p class="woocommerce-verification-required"><?php _e( 'Only logged in customers who have purchased this product may leave a review.', 'woocommerce' ); ?></p>

  <?php endif; ?>

  <div class="clear"></div>
</div>

Make sure that you are using the updated version of the file. And if nothing is working, please provide us your login details in a secure note so we can investigate. To know how to create a secure note, please check this out: https://theme.co/apex/forum/t/how-to-get-support/288

Regards.

I just posted a secure note.

Hey @klevur,

Thank you for providing your credentials. I’m sorry though that we haven’t notified you that your credentials would be available to the original poster so I removed it in this thread after logging in. Please change it as soon as you can.

I believe this has something to do with your WooCommerce Subscriptions plugin. That is basing on the errors and also from this WooCommerce Github thread.

It is also important for us to know if this is an issue with the Pro parent theme so it is important that you activate the parent theme and also deactivate all third party plugins then test if the issue persists. This should be done in a test environment though so I’d recommend you copy your site to a staging server and test there.

We also can’t do anything in your live site’s WordPress Admin other than to check what plugins you use. Troubleshooting is also not recommended in a live site because there is a chance of breaking it or it will interrupt or affect your live site’s operation.

Once you’ve tested the parent theme and there’s no modification and third party plugins causing the issue and the issue persists, please open a new thread and post your updated WordPress Admin credentials and also provide us with FTP access. Again, it’s best that we troubleshoot in a test or staging copy of your site so you might want to give us staging access instead.

Thanks.

Hi everyone,

@klevur, thanks for sharing. Good to get some more details on this.

@RueNel

I do not have single-product-reviews.php in my child theme. However, I checked and I do not have the version you posted aboven in my parent theme. Strange I thought. So I downloaded the latest version from my profile here on Apex (6.4.1) and it is also not the same as what you posted above. (It still uses the deprecated way of calling an ID.) So I copied in the version you posted above, but that did not solve the issue unfortunately.

@christian_y, thanks for looking into this and the helpful suggestions.

I found out that disabling the plugin ‘learndash_woocommerce’ made the error no longer appear. So I’ve just posted a support request with Learndash.

Thanks for the help so far and I’ll keep everyone updated.

All the best, Freek

Hi Freek,

I see, glad it’s okay now and thanks for sharing.

Thanks!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.