Skip to content

Instantly share code, notes, and snippets.

@pramodjodhani
Created May 7, 2026 08:53
Show Gist options
  • Select an option

  • Save pramodjodhani/482e8f037068facf95e806f778ce615e to your computer and use it in GitHub Desktop.

Select an option

Save pramodjodhani/482e8f037068facf95e806f778ce615e to your computer and use it in GitHub Desktop.
Show Sales Booster FBT discount and estimated total in the WooCommerce mini cart.
<?php
/**
* Show Sales Booster FBT discount and estimated total in the WooCommerce mini cart.
*/
add_action( 'woocommerce_before_mini_cart', 'iconic_recalculate_cart_fees_before_mini_cart', 1 );
add_action( 'woocommerce_widget_shopping_cart_before_buttons', 'iconic_show_fbt_discount_and_total_in_mini_cart', 5 );
function iconic_recalculate_cart_fees_before_mini_cart() {
if ( ! function_exists( 'WC' ) || ! WC()->cart || WC()->cart->is_empty() ) {
return;
}
static $calculating = false;
if ( $calculating ) {
return;
}
$calculating = true;
WC()->cart->calculate_totals();
$calculating = false;
}
function iconic_show_fbt_discount_and_total_in_mini_cart() {
if ( ! function_exists( 'WC' ) || ! WC()->cart || WC()->cart->is_empty() ) {
return;
}
$has_fbt_discount = false;
foreach ( WC()->cart->get_fees() as $fee ) {
$is_fbt_discount = (
( isset( $fee->id ) && '_iconic_wsb_fbt_discount' === $fee->id )
|| 'Bought together discount' === $fee->name
);
if ( ! $is_fbt_discount ) {
continue;
}
$has_fbt_discount = true;
echo '<p class="woocommerce-mini-cart__fbt-discount total">';
echo '<strong>' . esc_html( $fee->name ) . ':</strong> ';
wc_cart_totals_fee_html( $fee );
echo '</p>';
}
if ( ! $has_fbt_discount ) {
return;
}
echo '<p class="woocommerce-mini-cart__estimated-total total">';
echo '<strong>' . esc_html__( 'Estimated total:', 'woocommerce' ) . '</strong> ';
echo WC()->cart->get_total(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '</p>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment