Skip to content

Instantly share code, notes, and snippets.

@xlplugins
Created November 4, 2026 13:34
Show Gist options
  • Select an option

  • Save xlplugins/7794502c2eda77b7ffcc575decd26612 to your computer and use it in GitHub Desktop.

Select an option

Save xlplugins/7794502c2eda77b7ffcc575decd26612 to your computer and use it in GitHub Desktop.
FunnelKit Cart: show the reward progress bar on the WooCommerce cart page
<?php
/**
* FunnelKit Cart: show the reward progress bar on the WooCommerce cart page, kept in sync with the slide cart.
*
* Renders FunnelKit Cart's own rewards template above the cart table and adds it to FunnelKit Cart's
* fragments, so every slide cart refresh replaces it too. Changes made on the cart page itself
* (quantity, coupon) ask FunnelKit Cart to refresh.
*/
function fk_cart_page_rewards_html() {
$html = '';
if ( class_exists( '\FKCart\Includes\Data' ) && function_exists( 'fkcart_get_template_part' ) && \FKCart\Includes\Data::is_rewards_enabled() ) {
$classes = array( 'fkcart-reward-product-wrap' );
if ( filter_var( \FKCart\Includes\Data::get_value( 'reward_progress_bar_enable_animation' ), FILTER_VALIDATE_BOOLEAN ) ) {
$classes[] = 'fkcart-animation-active';
}
ob_start();
echo '<div class="' . esc_attr( implode( ' ', $classes ) ) . '">';
fkcart_get_template_part( 'modern' === \FKCart\Includes\Data::get_value( 'reward_progress_bar_style' ) ? 'cart/rewards/design-2' : 'cart/rewards' );
echo '</div>';
$html = ob_get_clean();
}
// The wrapper is always printed so a later refresh has something to replace.
return '<div class="fkcart-cart-page-rewards">' . $html . '</div>';
}
add_action( 'woocommerce_before_cart', function () {
echo fk_cart_page_rewards_html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- FunnelKit Cart template output.
} );
add_filter( 'fkcart_fragments', function ( $fragments ) {
$fragments['.fkcart-cart-page-rewards'] = fk_cart_page_rewards_html();
return $fragments;
} );
add_action( 'wp_footer', function () {
if ( ! function_exists( 'is_cart' ) || ! is_cart() ) {
return;
}
?>
<script>
jQuery( function ( $ ) {
$( document.body ).on( 'updated_cart_totals applied_coupon removed_coupon', function () {
$( document.body ).trigger( 'fkcart_update_side_cart', [ false ] );
} );
} );
</script>
<?php
}, 30 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment