【问题标题】:string(2) "id" Notice: id was called incorrectly. Product properties should not be accessed directly. Backtrace:string(2) "id" 注意:id 调用不正确。不应直接访问产品属性。回溯:
【发布时间】:2021-02-06 07:48:46
【问题描述】:

字符串(2)“id” 注意: id 调用不正确。不应直接访问产品属性。回溯:require('wp-blog-header.php')、require_once('wp-includes/template-loader.php')、include('/plugins/woocommerce/templates/single-product.php')、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, Avada_Woocommerce->output_related_products, woocommerce_related_products, wc_get_template, include( '/themes/demo-theme/woocommerce/single-product/related.php'), WC_Abstract_Legacy_Product->__get, wc_doing_it_wrong 有关更多信息,请参阅 WordPress 中的调试。 (此消息是在 3.0 版中添加的。)在 /wp-includes/functions.php 的第 5227 行

【问题讨论】:

    标签: wordpress plugins themes


    【解决方案1】:

    这可能是由于您的模板中有旧文件而您拥有新的 Woocommerce 版本。修复很简单,只需按照堆栈跟踪中的描述查找文件“/themes/demo-theme/woocommerce/single-product/related.php”并替换:

    $product->id;
    

    与:

    $product->get_id();
    

    对于所有出现的“$product->id;”都应该这样做为了摆脱警告

    【讨论】:

      【解决方案2】:

      wp-content/themes/Active-Theme/woocommerce/single-product/related.php

      /*if ( ! $related = $product->get_related( $posts_per_page ) ) {
          return;
      }*/
      
      $related = wc_get_related_products( $product->get_id(), $posts_per_page );
      
      if ( ! $related ) {
        return;
      }
      
      $args = apply_filters( 'woocommerce_related_products_args', array(
      'post_type'            => 'product',
      'ignore_sticky_posts'  => 1,
      'no_found_rows'        => 1,
      'posts_per_page'       => $posts_per_page,
      'orderby'              => $orderby,
      'post__in'             => $related,
      'post__not_in'         => array( $product->get_id() )
      ) );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-01-17
        • 1970-01-01
        • 2011-01-02
        • 1970-01-01
        • 2011-12-06
        • 1970-01-01
        • 2017-08-31
        相关资源
        最近更新 更多