Code-Snippets-Functions/Execute a function on a child site/WooCommerce/banner-based-on-get-total-spent-by-customer.txt

15 lines
571 B
Text

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>';
}
}