【发布时间】:2017-04-10 01:52:19
【问题描述】:
我从 2.6.x 版更新到 WooCommerce 3.0.x 版,但我的网站奇怪地停止正确加载。
我收到消息:
“WC_Product_Variable 类的对象无法转换为字符串”
错误的来源是woocommerce/includes/wc-product-functions.php文件中的一行
$value = ucwords( str_replace( '-', ' ', $value ) );
通过注释掉包含该行的代码块(从“if ( taxonomy_exists( $name ) ) {”开始),我能够让网站再次正常运行,但我对此不太满意拼凑的解决方案。
有人能解释一下这个错误的原因吗?
这是我的代码:
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>';
}
}*/
}
谢谢
【问题讨论】:
标签: php wordpress class woocommerce product