将Woo-commerce变化销售价格移至实际价格以下

时间:2016-05-26 10:35:09

标签: php wordpress woocommerce hook

我想将销售价格转换为实际价格变化,我设法为产品汇总部分执行此操作,但无法找到任何变体过滤器。

请参阅下图。

enter image description here

我试过这段代码但没有用,我的代码适用于Summery部分

add_filter( 'woocommerce_variable_sale_price_html', 'product_variation_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'product_variation_price_format', 10, 2 );

function product_variation_price_format( $price, $product ) {
if(is_singular('product')){
// Main Price
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
$price = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );

// Sale Price
$prices = array( $product->get_variation_regular_price( 'min', true ),$product->get_variation_regular_price( 'max', true ) );
sort( $prices );
$saleprice = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );

if ( $price !== $saleprice ) {
$price = '<ins>' . $price . '</ins> <del>' . $saleprice . '</del>';
 }
   }
 return $price;
 }

请指导我如何解决这个问题。

1 个答案:

答案 0 :(得分:3)

这更多是css问题,您可以使用简单的样式标记

来设置此样式

根据您的结构更改div类

.priceMainWrapperDiv {
  display: table;
}
.salePriceDiv {
  display: table-footer-group;
}
.actualPriceDiv {
  display: table-header-group;
}