Php 在Woocommerce的商店页面上显示分组产品的总价

Php 在Woocommerce的商店页面上显示分组产品的总价,php,wordpress,woocommerce,product,price,Php,Wordpress,Woocommerce,Product,Price,我想显示分组产品的总价格,而不是价格范围。我已经用这个片段在产品页面上修复了这个问题 我如何使用此代码或在商店页面上修复我的问题 global $product; $price = $product->get_price_html(); if ( $product->get_type() == 'grouped') { $children = $product->get_children(); $price = 0; foreach ($children

我想显示分组产品的总价格,而不是价格范围。我已经用这个片段在产品页面上修复了这个问题

我如何使用此代码或在商店页面上修复我的问题

global $product;
$price = $product->get_price_html();
if ( $product->get_type() == 'grouped') {
    $children = $product->get_children();
    $price = 0;
    foreach ($children as $key => $value) {
        $_product = wc_get_product( $value );
        $price += $_product->get_price();
    }
    $price = get_woocommerce_currency_symbol( '' ) . ' ' . $price;
}
?>
<p class="price"><?php echo $price; ?></p>
global$产品;
$price=$product->get_price_html();
如果($product->get_type()=='grouped'){
$children=$product->get_children();
$price=0;
foreach($key=>$value的子项){
$\u product=wc\u get\u product($value);
$price+=$\产品->获取\价格();
}
$price=获取商业货币符号(“”)。$price;
}
?>


尝试使用全局筛选器更改商店循环中返回的价格:

add_filter( 'woocommerce_get_price_html', 'highest_price', 10, 2 );

function highest_price( $price, $product ) {
  if ( $product->get_type() == 'grouped') {
    $children = $product->get_children();
    $price = 0;
    foreach ($children as $key => $value) {
      $_product = wc_get_product( $value );
      $price += $_product->get_price();
    }
    $price = get_woocommerce_currency_symbol( '' ) . ' ' . $price;
  }
  return $price;
}

我无法测试此解决方案,但如果它不起作用,请尝试将筛选器添加到另一个函数,而不是woocommerce\u get\u price\u html,例如woocommerce\u template\u loop\u price

我测试了以下解决方案,它在woocommerce 3.6.3上工作。在此之后,组产品将显示一个价格,该价格是其所有子产品的总和

function max_grouped_price( $price_this_get_price_suffix, $instance, $child_prices ) { 

    return wc_price(array_sum($child_prices)); 
} 

add_filter( 'woocommerce_grouped_price_html', 'max_grouped_price', 10, 3 );