Skip to content

Commit

Permalink
Send email to site admins when reward is claimed (#923)
Browse files Browse the repository at this point in the history
* [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 <[email protected]>

* Update client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce/Emails/AuctionRewardClaimedAdmin.php

Co-authored-by: Brian DiChiara <[email protected]>

---------

Co-authored-by: Brian DiChiara <[email protected]>
  • Loading branch information
clatwell and bd-viget authored Apr 24, 2024
1 parent f18ee7e commit 38b8f8f
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php
/**
* Auction Reward Claimed Admin: Email the site admins when an auction reward is claimed.
*
* @since 1.0.0
* @package GoodBids
*/

namespace GoodBids\Plugins\WooCommerce\Emails;

defined( 'ABSPATH' ) || exit;

/**
* Auction Reward Claimed Admin Email
*
* @since 1.0.0
* @extends Email
*/
class AuctionRewardClaimedAdmin extends Email {

/**
* Set the unique Email ID
*
* @since 1.0.0
* @var string
*/
public $id = 'goodbids_auction_reward_claimed_admin';

/**
* Set email defaults
*
* @since 1.0.0
*/
public function __construct() {
parent::__construct();

$this->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}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* Auction Reward Claimed Admin email
*
* @since 1.0.0
* @version 1.0.0
* @package GoodBids
*
* @var string $email_heading
*
* @var AuctionRewardClaimedAdmin $instance
*/

use GoodBids\Plugins\WooCommerce\Emails\AuctionRewardClaimedAdmin;

defined( 'ABSPATH' ) || exit;

/** @var WC_Order $reward_order */
$reward_order = $instance->object;

/*
* @hooked WC_Emails::email_header() Output the email header
*/
do_action( 'woocommerce_email_header', $email_heading );
?>
<p>
<?php
printf(
/* translators: %1$s: Reward title, %2$s: Site title, %3$s: Auction title, %4$s: Bid 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}',
);
?>
</p>

<p>
{reward.purchase_note}
</p>

<div style="margin-bottom: 40px;">
<table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" border="1">
<thead>
<tr>
<th class="td" scope="col" style="text-align:left;"><?php esc_html_e( 'Auction', 'goodbids' ); ?></th>
<th class="td" scope="col" style="text-align:left;"><?php esc_html_e( 'Total Donated', 'goodbids' ); ?></th>
</tr>
</thead>
<tbody>
<tr>
<td class="td" scope="col">{auction.title}</td>
<td class="td" scope="col">{auction.user.total_donated}</td>
</tr>
</tbody>
<tfoot>
<?php
$item_totals = $reward_order->get_order_item_totals();

if ( $item_totals ) {
$i = 0;
foreach ( $item_totals as $total ) {
$i++;
?>
<tr>
<th class="td" scope="row" style="text-align:left; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo wp_kses_post( $total['label'] ); ?></th>
<td class="td" style="text-align:left; <?php echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?php echo wp_kses_post( $total['value'] ); ?></td>
</tr>
<?php
}
}
?>
</tfoot>
</table>
</div>

<?php

/* * @hooked WC_Emails::email_footer() Output the email footer */
do_action( 'woocommerce_email_footer' );
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Auction Reward Claimed Admin email (plain text)
*
* @since 1.0.0
* @version 1.0.0
* @package GoodBids
*
* @var AuctionRewardClaimedAdmin $instance
*/

use GoodBids\Plugins\WooCommerce\Emails\AuctionRewardClaimedAdmin;

defined( 'ABSPATH' ) || exit;

/** @var WC_Order $reward_order */
$reward_order = $instance->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();

0 comments on commit 38b8f8f

Please sign in to comment.