Hi. How can we help?

Role Based prices - How show the total saving on the review order section with shortcode version of checkout

If you want to show the total saving on the review order section you can use the followed code in your functions.php:

if( defined('YWCRBP_PREMIUM' ) && !function_exists('ywrbp_show_total_discounts')) {
add_action( 'woocommerce_review_order_after_order_total', 'ywrbp_show_total_discounts', 99 );

function ywrbp_show_total_discounts() {

if ( ! is_null( WC()->cart ) ) {
$how_price = get_option( 'ywcrbp_apply_rule', 'regular' );
$save = 0;
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {

/**
* @var WC_Product $product
*/
$product = $cart_item['data'];
$role_price = $cart_item['line_subtotal'];
$qty = $cart_item['quantity'];

$sale_price = $product->get_sale_price( 'edit' );
if ( $sale_price > 0 && 'on_sale' == $how_price ) {
$original_price = $sale_price;
} else {
$original_price = $product->get_regular_price( 'edit' );
}

$original_price = wc_get_price_to_display( $product, array(
'price' => $original_price,
'qty' => $qty
) );
$save += $original_price - $role_price;

}

if ( $save > 0 ) {
?>
<tr class="order-discount">
<th><?php _e( 'You saved', 'yith-woocommerce-role-baseed-price' ); ?></th>
<td>
<?php echo wc_price( $save ); ?>
</td>
</tr>
<?php }
}
}
}

You should obtain the same result of the attached image:

image.png

Was this article helpful?
1 out of 2 found this helpful

Back to Help Center >