Display banner based on total spent by the customer in WooCommerce

Display banner based on total spent by the customer in WooCommerce on your child site.

Snippet Type

Execute on Child Sites

Snippet

add_action( 'woocommerce_before_cart', 'wc_show_banner_if_user_spent_more_than_99' );
   
function wc_show_banner_if_user_spent_more_than_99() {
    
   $current_user = wp_get_current_user();
    
   // if logged out, exit
   if ( 0 == $current_user->ID ) return;
    
   // if spent more than 99, display banner
   if ( wc_get_customer_total_spent( $current_user->ID ) > 99 ) {
      echo '<div class="woocommerce-info">Well done - you have unlocked your Valued Customer discount! Use coupon code <i><b>JRP7EWKD2</b></i> and get 5% off all products.</div>';
   }
    
}
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.