在WooCommerce结账时,在订单摘要中显示高于常规价格的产品折扣



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

我正在使用";WooCommerce:在订单摘要@结账时显示产品折扣;。但这显示在左边(在正常价格之前(。

我想让它出现在上面。所以我想展示比正常价格高的折扣。

/**
* @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;
}

您需要更改此代码

//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样式。

最新更新