Php 显示列出的可变产品的所有价格,而不是价格范围
有没有办法在商店页面上替换woocommerce中可变产品的范围价格,而不是显示变化列表及其每种产品的价格,以便向客户显示变化,并为所有类型的产品显示“添加到购物车”,而不是为可变产品“选择选项” 我已经测试了很多代码片段,但没有成功 下面的代码是最接近我需要的,我使用了这里建议的代码并对其进行了更改。但问题仍然是部分属性未显示Php 显示列出的可变产品的所有价格,而不是价格范围,php,wordpress,woocommerce,plugins,Php,Wordpress,Woocommerce,Plugins,有没有办法在商店页面上替换woocommerce中可变产品的范围价格,而不是显示变化列表及其每种产品的价格,以便向客户显示变化,并为所有类型的产品显示“添加到购物车”,而不是为可变产品“选择选项” 我已经测试了很多代码片段,但没有成功 下面的代码是最接近我需要的,我使用了这里建议的代码并对其进行了更改。但问题仍然是部分属性未显示 add_filter( 'woocommerce_variable_price_html', 'custom_variable_price_html', 10, 2 )
add_filter( 'woocommerce_variable_price_html', 'custom_variable_price_html', 10, 2 );
function custom_variable_price_html( $price, $product ) {
if(!is_admin()){
if(is_shop()){
$product_attribute_slug = 'ابعاد-فرش';
$targeted_taxonomy = 'pa_' . $product_attribute_slug;
$available_variations = $product->get_available_variations();
$output = '<div>';
foreach( $available_variations as $variation_data ){
if( $variation_data['display_price'] === $variation_data['display_regular_price'] ) {
$price_to_display = wc_price( $variation_data['display_price'] );
} else {
$variation = wc_get_product($variation_data['variation_id']); // Get the WC_Product_Variation Object
$price_to_display = wc_get_price_to_display( $variation, array('price' => $variation->get_sale_price() ) );
}
foreach ( $variation_data['attributes'] as $variation_attribute => $term_slug ) {
// Get the taxonomy slug
$taxonomy = str_replace( 'attribute_', '', $variation_attribute );
// Get the correct product attribute term value for this variation
if( $taxonomy === $targeted_taxonomy ) {
// Get the attribute value term name
$term_name = get_term_by( 'slug', $term_slug, $taxonomy )->name;
}
}
$output .= '<span>' . $term_name . ':' . wc_attribute_label( $targeted_taxonomy ) . ':' . strip_tags($price_to_display) . '</span><br>';
}
$output .= '</div>';
$price = $output;
return $price;
} else {
return $price;
}
} else {
return $price;
}
}
我得到的是:
但我需要这样的东西:
我注意到
$term\u名称
代码中的变量为空
非常感谢您的帮助。解决方案:按如下方式设置分类法,并在“按函数获取术语”中使用它:
$taxonomy = 'pa_ابعاد-فرش';
我投票结束这个问题,因为问题中没有提供真正的代码尝试。你所问的是一个真正的发展,一次包括很多问题,所以有些东西太宽泛了。另外请注意StackOverFlow不是免费的编码服务。@LoicTheAztec我在问题中添加了更多细节。非常感谢。