From 38b8f8f476232ea8559b7db1962936d13e961645 Mon Sep 17 00:00:00 2001 From: Claire Atwell Date: Wed, 24 Apr 2024 12:09:27 -0400 Subject: [PATCH] Send email to site admins when reward is claimed (#923) * [n/a] reward claimed admin email * [n/a] add reward claimed admin email to WooCommerce emails file * [n/a] add missing end line * Update client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce/Emails/AuctionRewardClaimedAdmin.php Co-authored-by: Brian DiChiara <122309362+bd-viget@users.noreply.github.com> * Update client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce/Emails/AuctionRewardClaimedAdmin.php Co-authored-by: Brian DiChiara <122309362+bd-viget@users.noreply.github.com> --------- Co-authored-by: Brian DiChiara <122309362+bd-viget@users.noreply.github.com> --- .../classes/Plugins/WooCommerce/Emails.php | 1 + .../Emails/AuctionRewardClaimedAdmin.php | 108 ++++++++++++++++++ .../emails/auction-reward-claimed-admin.php | 81 +++++++++++++ .../plain/auction-reward-claimed-admin.php | 49 ++++++++ 4 files changed, 239 insertions(+) create mode 100644 client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce/Emails/AuctionRewardClaimedAdmin.php create mode 100644 client-mu-plugins/goodbids/views/woocommerce/emails/auction-reward-claimed-admin.php create mode 100644 client-mu-plugins/goodbids/views/woocommerce/emails/plain/auction-reward-claimed-admin.php diff --git a/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce/Emails.php b/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce/Emails.php index b2843f37..82c40a04 100644 --- a/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce/Emails.php +++ b/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce/Emails.php @@ -16,6 +16,7 @@ use GoodBids\Plugins\WooCommerce\Emails\AuctionOutbid; use GoodBids\Plugins\WooCommerce\Emails\AuctionPaidBidPlaced; use GoodBids\Plugins\WooCommerce\Emails\AuctionRewardClaimed; +use GoodBids\Plugins\WooCommerce\Emails\AuctionRewardClaimedAdmin; use GoodBids\Plugins\WooCommerce\Emails\AuctionRewardReminder; use GoodBids\Plugins\WooCommerce\Emails\AuctionSummaryAdmin; use GoodBids\Plugins\WooCommerce\Emails\AuctionWinnerConfirmation; diff --git a/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce/Emails/AuctionRewardClaimedAdmin.php b/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce/Emails/AuctionRewardClaimedAdmin.php new file mode 100644 index 00000000..5f99a4d7 --- /dev/null +++ b/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce/Emails/AuctionRewardClaimedAdmin.php @@ -0,0 +1,108 @@ +title = __( 'Auction Reward Claimed Admin', 'goodbids' ); + $this->description = __( 'Notification email sent to site admins when a reward is claimed', 'goodbids' ); + $this->template_html = 'emails/auction-reward-claimed-admin.php'; + $this->template_plain = 'emails/plain/auction-reward-claimed-admin.php'; + $this->admin_email = true; + + $this->trigger_on_reward_claimed(); + } + + /** + * Trigger this email to admins when an auction reward is claimed. + * + * @since 1.0.0 + * @return void + */ + private function trigger_on_reward_claimed(): void { + add_action( + 'goodbids_reward_redeemed', + function ( int $auction_id, int $order_id ) { + $order = wc_get_order( $order_id ); + $this->send_to_admins( $order ); + }, + 10, + 2 + ); + } + + /** + * Get email subject. + * + * @since 1.0.0 + * @return string + */ + public function get_default_subject(): string { + return sprintf( + /* translators: %1$s: site title, %2$s: auction title */ + __( '[%1$s] %2$s Claim Confirmation', 'goodbids' ), + '{site_title}', + '{auction.title}' + ); + } + + /** + * Get email heading. + * + * @since 1.0.0 + * @return string + */ + public function get_default_heading(): string { + return __( 'Auction winner has claimed their reward!', 'goodbids' ); + } + + /** + * Get button text + * + * @since 1.0.0 + * @return string + */ + public function get_default_button_text(): string { + return __( 'See Auction Results', 'goodbids' ); + } + + /** + * Set Button URL + * + * @since 1.0.0 + * @return string + */ + public function get_button_url(): string { + return '{auction.url}'; + } +} diff --git a/client-mu-plugins/goodbids/views/woocommerce/emails/auction-reward-claimed-admin.php b/client-mu-plugins/goodbids/views/woocommerce/emails/auction-reward-claimed-admin.php new file mode 100644 index 00000000..5ea8efd5 --- /dev/null +++ b/client-mu-plugins/goodbids/views/woocommerce/emails/auction-reward-claimed-admin.php @@ -0,0 +1,81 @@ +object; + +/* + * @hooked WC_Emails::email_header() Output the email header + */ +do_action( 'woocommerce_email_header', $email_heading ); +?> +

+ +

+ +

+ {reward.purchase_note} +

+ +
+ + + + + + + + + + + + + + + get_order_item_totals(); + + if ( $item_totals ) { + $i = 0; + foreach ( $item_totals as $total ) { + $i++; + ?> + + + + + + +
{auction.title}{auction.user.total_donated}
+
+ +object; + +$instance->plain_text_header(); + +printf( + /* translators: %1$s: Reward title, %2$s: Site title, %3$s: Auction title, %4$s: Reward Claim Date */ + esc_html__( 'This is confirmation that the auction winner has claimed the %1$s reward for the %2$s %3$s auction on %4$s.', 'goodbids' ), + '{reward.title}', + '{site_title}', + '{auction.title}', + '{order.date}', +); + +echo "\n\n----------------------------------------\n\n"; + +echo '{reward.purchase_note}'; + +esc_html_e( 'Auction', 'goodbids' ) . ': ' . '{auction.title}' . "\n"; +esc_html_e( 'Total Donated', 'goodbids' ) . ': ' . '{auction.user.total_donated}' . "\n"; + +echo "\n\n----------------------------------------\n\n"; + +$item_totals = $reward_order->get_order_item_totals(); + +if ( $item_totals ) { + foreach ( $item_totals as $total ) { + echo esc_html( wp_strip_all_tags( $total['label'] ) . ': ' . wp_strip_all_tags( $total['value'] ) ) . "\n"; + } +} + +echo "\n\n----------------------------------------\n\n"; + +$instance->plain_text_footer();