php - 将 Woo-commerce 变体销售价格低于实际价格

标签 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;
 }

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

最佳答案

这更多是 css 问题,你可以使用简单的样式标签来设计它

根据您的结构更改 div 类

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

关于php - 将 Woo-commerce 变体销售价格低于实际价格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37458335/

相关文章:

php - 如何使用带有 UTF-8 的 Codeigniter 路由(如阿拉伯字符 404)

javascript - 每个标记的 InfoBox (getElementById) – Google Maps API 3

wordpress - 如何使 woocommerce 产品标签分层?

php - != 和 !== 之间的区别

php - 使用 jQuery 滑动一个 div 打开一个关闭

javascript - 在 script.aculo.us 中使用 jQuery noConflict()

php - WooCommerce:结帐验证失败后更新自定义字段

wordpress - 添加产品时 Woocommerce 产品类别丢失(未显示)

php - 通过拒绝英文字符来防止SQL注入(inject)?

php - header.php 中的 Wordpress Logo 图像