Skip to content

Commit

Permalink
fix(woocommerce-emails): use the default email if there are no donati…
Browse files Browse the repository at this point in the history
…on products
  • Loading branch information
adekbadek committed Nov 13, 2024
1 parent 489ce0f commit e9664ce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion includes/class-donations.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private static function get_parent_donation_product() {
/**
* Get the child products of the main donation product.
*/
private static function get_donation_product_child_products_ids() {
public static function get_donation_product_child_products_ids() {
$child_products_ids = [
'once' => false,
'month' => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,19 @@ public static function force_disable_order_attribution( $should_allow ) {
* @return bool
*/
public static function send_customizable_receipt_email( $enable, $order, $class ) {
// If there are no donation products in the order, do not override the default WC receipt email.
$has_donation_product = false;
$donation_product_ids = array_values( \Newspack\Donations::get_donation_product_child_products_ids() );
foreach ( $order->get_items() as $item_id => $item ) {
if ( in_array( $item->get_product()->get_id(), $donation_product_ids ) ) {
$has_donation_product = true;
break;
}
}
if ( ! $has_donation_product ) {
return $enable;
}

// If we don't have a valid order, or the customizable email isn't enabled, bail.
if ( ! is_a( $order, 'WC_Order' ) || ! Emails::can_send_email( Reader_Revenue_Emails::EMAIL_TYPES['RECEIPT'] ) ) {
return $enable;
Expand Down

0 comments on commit e9664ce

Please sign in to comment.