Skip to content

Instantly share code, notes, and snippets.

@growdev
Created May 20, 2022 15:45
Show Gist options
  • Save growdev/f0baf9a7330935ca553a491005f80f8f to your computer and use it in GitHub Desktop.
Save growdev/f0baf9a7330935ca553a491005f80f8f to your computer and use it in GitHub Desktop.
Send email when a customer adds an item to their WooCommerce Subscription with Toolbox for WC Subscriptions plugin.
<?php
/**
* Send an email notification when a customer adds an item to their subscription.
*
* @param WC_Subscription $subscription
* @param WC_Product $product
* @param int $quantity
*/
function sp_toolbox_notify_add( $subscription, $product, $quantity ) {
$to = ''; // recipient of the email
$subject = 'Customer Added Item to Subscription'; // subject
$body = 'A customer added a product to their subscription.' . '<br/>' . PHP_EOL;
$body .= 'Subscription ID: ' . $subscription->get_id() . '<br/>' . PHP_EOL; // Subscription ID
$body .= 'for customer: ' . $subscription->get_billing_first_name() . ' ' . $subscription->get_billing_last_name() . '<br/>' . PHP_EOL; // Customer Name
$body .= 'Product: ' . $product->get_name() . '(' . $product->get_sku() . ')<br/>' . PHP_EOL; // The product Name
$body .= 'Quantity: ' . $quantity . '<br/>' . PHP_EOL; // The quantity
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail($to, $subject, $body, $headers);
}
add_action('jgtb_added_item_to_subscription', 'sp_toolbox_notify_add', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment