X/Woocommerce id called incorrectly for reviews

Hi,
We’re running an ecommerce site that switched over to the X theme/cornerstone recently. However we noticed that on our individual product pages we’re receiving an error within the reviews tabs that is the following:

Notice: id was called incorrectly. Product properties should not be accessed directly. Backtrace: require(‘wp-blog-header.php’), require_once(‘wp-includes/template-loader.php’), include(’/themes/x/woocommerce.php’), x_get_view, X_View_Router::render, include(’/themes/x/framework/views/integrity/woocommerce.php’), woocommerce_content, wc_get_template_part, load_template, require(’/plugins/woocommerce/templates/content-single-product.php’), do_action(‘woocommerce_after_single_product_summary’), WP_Hook->do_action, WP_Hook->apply_filters, woocommerce_output_product_data_tabs, wc_get_template, include(’/themes/x/woocommerce/single-product/tabs/tabs.php’), comments_template, require(’/themes/x/woocommerce/single-product-reviews.php’), WC_Abstract_Legacy_Product->__get, wc_doing_it_wrong Please see Debugging in WordPress for more information. (This message was added in version 3.0.) in /home2/site/public_html/wp-includes/functions.php on line 4773

When we disable the reviews within WooCommerce, the issue and the reviews tab goes away. Re-enabling it does not fix the issue. Could you help troubleshoot what’s going on after we switched to X theme? This issue was not present in the previous theme.

Thank you!

Hello @riakhmerov,

Thanks for writing in!

You are seeing the PHP Notice because the Review needs to be activated in the theme options. Please go to X > Theme Options > WooCommerce > Single Product and “Review Tab” should be enabled. And then you can activate the Reviews within your WooCommerce settings.

Hope this helps.

Hey Rue,
The Reviews tab was enabled within X Theme Options > WooComm > Single Product. I went and disabled it, saved, and re-enabled it and saved, and it’s still showing the same issue.

Hello @riakhmerov,

Well, if that is the case, let me investigate further in my local testing server. For the meantime, please disable your debug mode to get rid of the PHP notices. You can do this by opening wp-config.php and adding


define('WP_DEBUG', false);

/* That's all, stop editing! Happy blogging. */

When you revisit the page, you should no longer be seeing those PHP notices.

Regards.

Thank you so much Rue! I appreciate you looking further into this.

Hello @riakhmerov,

I could not replicate the PHP Notices in my local testing server.
Would you mind providing us the url of your site with login credentials so we can take a closer look and investigate the issue this notices in your site?

To do this, you can make a secure note and insert the following info:
– Link to your site
– WordPress Admin username / password

  • FTP Hostname
  • FTP Username
  • FTP Password

To know how to create a secure note, please check this out: https://theme.co/apex/forum/t/how-to-get-support/288

Thank you.

Thanks I’ve attached it to my previous reply

Hello @riakhmerov,

Thanks for writing in!

Can you please confirm the FTP login details as I am getting following error message:

Response: 	530 Login authentication failed
Error:        	Critical error: Could not connect to server

Thanks.

Hi! Sorry about that, please try again. Thank you

Hi @riakhmerov,

Sorry, but the FTP credential is still not working, please check. Did you able to add the define('WP_DEBUG', false); on your wp-config.php file? I don’t see the notice on my end.

Please clarify,
Thanks!

Hi yes, I removed the notice by changing WP_DEBUG to false
Please try connecting using plain FTP. i’ve had issues connecting with TLS as well.

Hey @riakhmerov,

I have investigated your issue and I saw this entire PHP notice:

[17-Oct-2019 19:46:43 UTC] PHP Notice:  Undefined variable: product_id in /home2/calivolv/public_html/wp-content/themes/x-child/functions.php on line 142
[17-Oct-2019 19:46:43 UTC] PHP Notice:  Undefined variable: product_id in /home2/calivolv/public_html/wp-content/themes/x-child/functions.php on line 142
[17-Oct-2019 19:46:43 UTC] PHP Notice:  Undefined variable: product_id in /home2/calivolv/public_html/wp-content/themes/x-child/functions.php on line 142
[17-Oct-2019 19:46:43 UTC] PHP Notice:  Undefined variable: product_id in /home2/calivolv/public_html/wp-content/themes/x-child/functions.php on line 142
[17-Oct-2019 19:47:18 UTC] PHP Notice:  id was called <strong>incorrectly</strong>. Product properties should not be accessed directly. Backtrace: require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/x/woocommerce.php'), x_get_view, X_View_Router::render, include('/themes/x/framework/views/integrity/woocommerce.php'), woocommerce_content, wc_get_template_part, load_template, require('/plugins/woocommerce/templates/content-single-product.php'), do_action('woocommerce_after_single_product_summary'), WP_Hook->do_action, WP_Hook->apply_filters, woocommerce_output_product_data_tabs, wc_get_template, include('/themes/x/woocommerce/single-product/tabs/tabs.php'), comments_template, require('/themes/x/woocommerce/single-product-reviews.php'), WC_Abstract_Legacy_Product->__get, wc_doing_it_wrong Please see <a href="https://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information. (This message was added in version 3.0.) in /home2/calivolv/public_html/wp-includes/functions.php on line 4778

It came from your custom PHP code;

add_action( 'woocommerce_before_shop_loop_item_title', 'addHoverImageToProducts', 10 );

function addHoverImageToProducts() {
    global $product;
    $attachment_ids = $product->get_gallery_image_ids();
    $count = 0;
    foreach( $attachment_ids as $attachment_id ) { 
        $count++;
        //make sure you're on the Shop Page and that you only get the first image
        if(is_shop() && $count <= 1){
    ?>
<div class="secondary-container"><a href="<?php echo get_permalink($product_id); ?>"><div class="product-secondary-image" style="background-image:url('<?php echo wp_get_attachment_image_src( $attachment_id, 'full' )[0]; ?>'); background-repeat:no-repeat;"></div></a></div>
    <?php 
        }
    }
}

The <?php echo get_permalink($product_id); ?> should be replaced with <?php echo get_permalink(); ?>. Or may explicitly need to define the product ID to get the permalink. Are you the one coding this function? You may need to contact the creator of this function for the resolution of the PHP notice.

Please keep in mind that custom coding is beyond the scope of our support. Please reach out to the source of the code of whoever coded this. Or you just simply ignore since this is just a PHP notice. It would affect any feature or functionality to your site.

Hope this helps.

Hi Rue,
I fixed the custom php in my functions.php in the child theme, however the last PHP notice you posted regarding public_html/wp-includes/functions.php on line 4778 is still there, and appears underneath the reviews on the single product pages. I don’t believe those two things were related as I can completely remove that custom code and the notice will still appear.

I appreciate you pointing out the undefined variable error in the child/functions.php

Hi @riakhmerov,

You should replace the references of $product->id to $product->get_id()
Accessing directly product data is not allowed, e.g. $product->id. Correct method going forward is $product->get_id().

Look on your codes, change the existence of $product->id to $product->get_id()

Also, since X theme is not compatible yet on the latest woocommerce, this issue will exist on the theme woocommerce templates customization after the update.

Let me give you an example.
wp-content/themes/x/woocommerce/single-product-reviews.php On line 71 of this file, you can see reference to this $product->id

On the update file of woocommerce 3.7.1
wp-content/plugins/woocommerce/templates/single-product-reviews.php It is on line 68 now, $product->id is now $product->get_id().

If you want to avoid it on the theme customizations, create a folder woocommerce inside your child theme like this: x-child/woocommerce. Copy the original single-product-reviews.php template from the plugin folder and paste it on this folder. Note that this means you will use default woocommerce single product reviews template without the theme customization. Do this on all other templates with that variable.

Hope this helps.

Thank you so much! I appreciate everyone’s help.

You are most welcome @riakhmerov.