This code for showing regular price for each product in minicart and subtotal sum. Work with simple and variable products. For bundle products — need corrections.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
function display_regular_price_in_mini_cart( $item_data, $cart_item ) { $product = wc_get_product( $cart_item['product_id'] ); $quantity = $cart_item['quantity']; if ( $product->is_type( 'variable' ) ) { $variation_id = $cart_item['variation_id']; $variation = wc_get_product( $variation_id ); $regular_price = $variation->get_regular_price(); } else { $regular_price = $product->get_regular_price(); } if ( $regular_price ) { $item_data[] = array( 'key' => 'regular_price', 'value' => '<span class="test_quantity">'.$quantity.' × '.'</span><del>'.wc_price( $regular_price ).'</del><br/>', 'display' => '', ); } return $item_data; } add_filter( 'woocommerce_get_item_data', 'display_regular_price_in_mini_cart', 10, 2 ); function show_subtotal_with_regular_prices( $subtotal ) { $cart = WC()->cart->get_cart(); $subtotal_sale = $subtotal; $subtotal = 0; foreach ( $cart as $cart_item_key => $cart_item ) { $product_id = $cart_item['product_id']; $product = wc_get_product( $cart_item['product_id'] ); $quantity = $cart_item['quantity']; if ( $product->is_type( 'variable' ) ) { $variation_id = $cart_item['variation_id']; $variation = wc_get_product( $variation_id ); $regular_price = $variation->get_regular_price(); } else { $regular_price = $product->get_regular_price(); } $subtotal += $regular_price * $quantity; } return $subtotal_sale.'<del>'.wc_price($subtotal).'</del>'; } add_filter( 'woocommerce_cart_subtotal', 'show_subtotal_with_regular_prices' ); |