【问题标题】:Display product discount above regular price in order summary on checkout in WooCommerce在 WooCommerce 结帐时的订单摘要中显示高于正常价格的产品折扣
【发布时间】:2020-11-30 23:08:53
【问题描述】:

我想在订单汇总和结账时显示高于正常价格的产品折扣。

我正在使用“WooCommerce: Display Product Discount in Order Summary @ Checkout”。但这显示在左侧(在正常价格之前)。

我希望它显示在顶部。所以我想显示高于正常价格的折扣。

/**
 * @snippet       WooCommerce: Display Product Discount in Order Summary @ Checkout, Cart
 * @author        Sandesh Jangam
 * @donate $7     https://www.paypal.me/SandeshJangam/7
 */
  
add_filter( 'woocommerce_cart_item_subtotal', 'ts_show_product_discount_order_summary', 10, 3 );
 
function ts_show_product_discount_order_summary( $total, $cart_item, $cart_item_key ) {
     
    //Get product object
    $_product = $cart_item['data'];
     
    //Check if sale price is not empty
    if( '' !== $_product->get_sale_price() ) {
         
        //Get regular price of all quantities
        $regular_price = $_product->get_regular_price() * $cart_item['quantity'];
         
        //Prepend the crossed out regular price to actual price
        $total = '<span style="text-decoration: line-through; opacity: 0.5; padding-right: 5px;">' . wc_price( $regular_price ) . '</span>' . $total;
    }
     
    // Return the html
    return $total;
}

【问题讨论】:

  • 这是添加 CSS、显示块与内联的问题
  • 谢谢。那么,我该怎么做呢?
  • 显示你的页面链接。

标签: php css wordpress woocommerce checkout


【解决方案1】:

您需要更改此代码

 //Prepend the crossed out regular price to actual price
 $total = '<span style="text-decoration: line-through; opacity: 0.5; padding-right: 5px;">' . wc_price( $regular_price ) . '</span>' . $total;

不要在前面添加,而是将值附加到总数中。用这段代码替换上面的代码。

 //Append the crossed out regular price to actual price
 $total = $total . '<span style="text-decoration: line-through; opacity: 0.5; padding-right: 5px;">' . wc_price( $regular_price ) . '</span>';

如果您想在价格上方显示,请将span 更改为div 或使用display:block; 更改为span 样式。

【讨论】:

  • 不幸的是,这次划掉的折扣在右边。我打折的那个;我想要普通的。打折的会在上面。
猜你喜欢
  • 2020-01-15
  • 2018-07-06
  • 1970-01-01
  • 2021-05-18
  • 2021-05-18
  • 2019-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多