Skip to content

Instantly share code, notes, and snippets.

@pavlo-bondarchuk
Last active February 3, 2019 16:35
Show Gist options
  • Save pavlo-bondarchuk/113e24a22bc5a0988fab2dd767b6f2f3 to your computer and use it in GitHub Desktop.
Save pavlo-bondarchuk/113e24a22bc5a0988fab2dd767b6f2f3 to your computer and use it in GitHub Desktop.
Welcome Message for Repeat Customers
function wc_get_customer_orders() {
// Get all customer orders
$customer_orders = get_posts( array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => wc_get_order_types(),
'post_status' => array_keys( wc_get_order_statuses() ),
) );
$customer = wp_get_current_user();
// Order count for a "loyal" customer
$loyal_count = 5;
// Text for our "thanks for loyalty" message
$notice_text = sprintf( 'Hey %1$s 😀 We noticed you\'ve placed more than %2$s orders with us – thanks for being a loyal customer!', $customer->display_name, $loyal_count );
// Display our notice if the customer has at least 5 orders
if ( count( $customer_orders ) >= $loyal_count ) {
wc_print_notice( $notice_text, 'notice' );
}
}
add_action( 'woocommerce_before_my_account', 'wc_get_customer_orders' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment