WooCommerce email notifications play a vital role in keeping both administrators and customers informed about store transactions. When using FastCredit Pro, you may want to handle credit-based purchase notifications differently than regular orders. This guide explains the two main types of WooCommerce notifications and how to customize them for credit purchases.
Understanding WooCommerce Email Notification Types
1. Customer Email Notifications
These notifications are sent to customers and include:
- Order confirmation emails
- Processing order notifications
- Order completion notifications
- Order refund notifications
- Order cancellation notifications
2. Admin Email Notifications
These notifications are sent to store administrators and include:
- New order alerts
- Cancelled order notifications
- Failed order notifications
- Low stock notifications
- Out of stock notifications
Why Customize Email Notifications for Credit Purchases?
When using FastCredit Pro, there are several reasons to customize these notifications:
- Credit purchases often represent internal transactions that need different handling
- Standard WooCommerce order emails may contain irrelevant payment information
- You may want to track credit purchases separately from regular orders
- Credit-based transactions might require different messaging
- Automated systems triggered by order emails may need to exclude credit purchases
Methods to Customize Email Notifications
Method 1: Basic WooCommerce Settings
This method allows you to disable email notifications globally:
- Navigate to WooCommerce > Settings
- Select the “Emails” tab
- Click each email type
- Uncheck “Enable this email notification”
- Save changes
Note: This method affects all orders, not just credit purchases.
Method 2: Custom Code Solution (Recommended)
Disabling Admin Notifications
// Add to your theme's functions.php or custom plugin
add_filter('woocommerce_email_recipient_new_order', 'disable_admin_email_for_credit_purchases', 10, 2);
add_filter('woocommerce_email_recipient_admin_cancelled_order', 'disable_admin_email_for_credit_purchases', 10, 2);
add_filter('woocommerce_email_recipient_admin_failed_order', 'disable_admin_email_for_credit_purchases', 10, 2);
function disable_admin_email_for_credit_purchases($recipient, $order) {
if (!$order) {
return $recipient;
}
// Check if the order was paid with credits
$payment_method = $order->get_payment_method();
// FastCredit Pro uses 'fastcredit' as the payment method ID
if ($payment_method === 'fastcredit') {
return ''; // Return empty string to prevent email sending
}
return $recipient;
}
Disabling Customer Notifications
// Add to your theme's functions.php or custom plugin
add_filter('woocommerce_email_recipient_customer_completed_order', 'disable_customer_email_for_credit_purchases', 10, 2);
add_filter('woocommerce_email_recipient_customer_processing_order', 'disable_customer_email_for_credit_purchases', 10, 2);
add_filter('woocommerce_email_recipient_customer_on_hold_order', 'disable_customer_email_for_credit_purchases', 10, 2);
add_filter('woocommerce_email_recipient_customer_refunded_order', 'disable_customer_email_for_credit_purchases', 10, 2);
function disable_customer_email_for_credit_purchases($recipient, $order) {
if (!$order) {
return $recipient;
}
// Check if the order was paid with credits
$payment_method = $order->get_payment_method();
// FastCredit Pro uses 'fastcredit' as the payment method ID
if ($payment_method === 'fastcredit') {
return ''; // Return empty string to prevent email sending
}
return $recipient;
}
Method 3: Creating Custom Credit Purchase Notifications
Instead of using standard WooCommerce emails, you can create custom notifications specifically for credit purchases:
add_action('woocommerce_order_status_completed', 'send_custom_credit_purchase_notification', 10, 1);
function send_custom_credit_purchase_notification($order_id) {
$order = wc_get_order($order_id);
if ($order->get_payment_method() !== 'fastcredit') {
return;
}
// Send admin notification
$admin_email = get_option('admin_email');
$admin_subject = 'New Credit Purchase Completed';
$admin_message = sprintf(
'A credit purchase has been completed for order #%s.
Credits used: %s
Customer: %s',
$order->get_order_number(),
$order->get_meta('_credits_used'),
$order->get_billing_email()
);
wp_mail($admin_email, $admin_subject, $admin_message);
// Send customer notification
$customer_email = $order->get_billing_email();
$customer_subject = 'Credit Purchase Confirmation';
$customer_message = sprintf(
'Thank you for your credit purchase! You have used %s credits for order #%s.
Your remaining credit balance is: %s',
$order->get_meta('_credits_used'),
$order->get_order_number(),
get_user_meta($order->get_user_id(), '_credit_balance', true)
);
wp_mail($customer_email, $customer_subject, $customer_message);
}
Best Practices for Implementation
- Test Thoroughly
- Test credit purchases with notifications enabled and disabled
- Verify regular purchase notifications still work
- Check all customer-facing communications
- Test admin notifications for credit purchases
- Maintain Clear Communication
- Ensure customers receive confirmation of credit transactions
- Keep credit balance notifications separate from order notifications
- Make sure administrators are properly notified of credit purchases
- Document Your Setup
- Track which notifications are disabled for credit purchases
- Document any custom email templates
- Record conditions for email sending/suppression
- Maintain documentation of custom code implementations
Troubleshooting Common Issues
If you encounter problems after implementing these changes, verify:
- Payment Method Detection
- Confirm payment method is correctly set to ‘fastcredit’
- Check order meta data for proper identification
- Email Filter Operation
- Ensure custom code runs at the correct priority
- Check for conflicts with other email customization plugins
- Communication Flow
- Verify customers receive necessary information
- Confirm admin notifications work as expected
- Test all email scenarios thoroughly
By following this guide, you can create a customized notification system that handles both regular WooCommerce orders and FastCredit Pro credit purchases appropriately, ensuring both customers and administrators receive the right information at the right time.