سلام دوستان
دمو پیوست شد.
برای نمایش میزان سود مشتری از خرید
از کد زیر در فانکشن استفاده کنید.
این بخش هم در سبد خرید و هم در تسویه حساب اضافه می شود.
این کد قیمت اصلی و قیمت ویژه را از هم کم کرده و میزان سود را نشان می دهد.
کد :
function wpirpayam_wc_discount_total_30() {
global $woocommerce;
$discount_total = 0;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values) {
$_product = $values;
if ( $_product->is_on_sale() ) {
$regular_price = $_product->get_regular_price();
$sale_price = $_product->get_sale_price();
$discount = ($regular_price - $sale_price) * $values;
$discount_total += $discount;
}
}
if ( $discount_total > 0 ) {
echo ''; '. __( 'سود شما از این خرید :', 'woocommerce' ) .' '
. wc_price( $discount_total + $woocommerce->cart->discount_cart ) .'
}
}
// هوک های افزودن این قابلیت به سبد خریدو تسویه حساب
add_action( 'woocommerce_cart_totals_after_order_total', 'wpirpayam_wc_discount_total_30', 99);
add_action( 'woocommerce_review_order_after_order_total', 'wpirpayam_wc_discount_total_30', 99);
دوستان عزیز
برای اینکه استایل بدید به این کد به کلاس : cart-discount
استایل بدید.