WooCommerce update version 3.0.x breaks site -

时间:2017-04-10 01:52:19

标签: php wordpress class woocommerce product

I updated to WooCommerce version 3.0.x from version 2.6.x and my site strangely stops loading correctly.

I get the message:

"Object of class WC_Product_Variable could not be converted to string"

the source of the error is a line in the woocommerce/includes/wc-product-functions.php file

$value = ucwords( str_replace( '-', ' ', $value ) );

I was able to get the site working fine again by commenting out the block of code that incorporates the line, starting at "if ( taxonomy_exists( $name ) ) {", but I don't really feel comfortable with such a patchwork solution.

Could someone possibly explain the reason for this error?

Here is my code:

foreach ( $variation_attributes as $name => $value ) {
        if ( ! $value ) {
            continue;
        }

        // If this is a term slug, get the term's nice name
        /*if ( taxonomy_exists( $name ) ) {
            $term = get_term_by( 'slug', $value, $name );
            if ( ! is_wp_error( $term ) && ! empty( $term->name ) ) {
                $value = $term->name;
            }
        } else {
            $value = ucwords( str_replace( '-', ' ', $value ) );
        }

        if ( $include_names ) {
            if ( $flat ) {
                $variation_list[] = wc_attribute_label( $name, $product ) . ': ' . rawurldecode( $value );
            } else {
                $variation_list[] = '<dt>' . wc_attribute_label( $name, $product ) . ':</dt><dd>' . rawurldecode( $value ) . '</dd>';
            }
        } else {
            if ( $flat ) {
                $variation_list[] = rawurldecode( $value );
            } else {
                $variation_list[] = '<li>' . rawurldecode( $value ) . '</li>';
            }
        }*/
    }

Thanks

1 个答案:

答案 0 :(得分:1)

这意味着 $value不是字符串,而是对象或值数组

因此,使用 str_replace() PHP函数无法使用它,因为它适用于字符串。

您最好尝试在其上使用 foreach 循环或 implode() PHP函数将其转换为字符串,但是...... < / p>

  

真正的问题所在:

     
      
  • 您的活动子主题(或主题)和function.php文件,其中大部分时间我们都会放置一些自定义代码。
  •   
  • WooCommerce中涉及的第三方插件
  •   
     

WooCommerce 3.0+版是一个更严格的主要版本。现在需要围绕getter和setter的新语法来访问大多数WC类中的对象。

供参考:

  

以下是遗留和已弃用的功能,用于保持 WC_Abstract_Product 清洁(此类将在以后的版本中删除):