问题描述
我正在使用“ 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;
}
解决方法
您需要更改此代码
//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
样式。