From f8b539eb5ee2e97536fd939155eed54b4633e855 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 12 Aug 2015 19:01:05 +0100 Subject: [PATCH] Improved refund email events and woocommerce_order_fully_refunded hook. Closes #8793 --- includes/class-wc-emails.php | 2 +- ...class-wc-email-customer-refunded-order.php | 39 ++++++++++++------- includes/wc-order-functions.php | 10 ++++- readme.txt | 1 + 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/includes/class-wc-emails.php b/includes/class-wc-emails.php index eeb1a23d1b6..4721fa2ce3e 100644 --- a/includes/class-wc-emails.php +++ b/includes/class-wc-emails.php @@ -69,7 +69,7 @@ class WC_Emails { 'woocommerce_order_status_on-hold_to_processing', 'woocommerce_order_status_on-hold_to_cancelled', 'woocommerce_order_status_completed', - 'woocommerce_order_status_refunded', + 'woocommerce_order_fully_refunded', 'woocommerce_order_partially_refunded', 'woocommerce_new_customer_note', 'woocommerce_created_customer' diff --git a/includes/emails/class-wc-email-customer-refunded-order.php b/includes/emails/class-wc-email-customer-refunded-order.php index 8f8b7fbcd8f..05e5a1a15d6 100644 --- a/includes/emails/class-wc-email-customer-refunded-order.php +++ b/includes/emails/class-wc-email-customer-refunded-order.php @@ -22,22 +22,18 @@ class WC_Email_Customer_Refunded_Order extends WC_Email { /** * Constructor */ - function __construct() { - + public function __construct() { $this->set_email_strings(); // Triggers for this email - add_action( 'woocommerce_order_status_refunded_notification', array( $this, 'trigger' ), null, 3 ); - add_action( 'woocommerce_order_partially_refunded_notification', array( $this, 'trigger' ), null, 3 ); - + add_action( 'woocommerce_order_fully_refunded_notification', array( $this, 'trigger_full' ), 10, 2 ); + add_action( 'woocommerce_order_partially_refunded_notification', array( $this, 'trigger_partial' ), 10, 2 ); // Call parent constuctor parent::__construct(); } - function set_email_strings( $partial_refund = false ) { - - + public function set_email_strings( $partial_refund = false ) { $this->subject_partial = $this->get_option( 'subject_partial', __( 'Your {site_title} order from {order_date} has been partially refunded', 'woocommerce' ) ); $this->subject_full = $this->get_option( 'subject_full', __( 'Your {site_title} order from {order_date} has been refunded', 'woocommerce' ) ); @@ -64,11 +60,24 @@ class WC_Email_Customer_Refunded_Order extends WC_Email { } } + /** + * Full refund notification + */ + public function trigger_full( $order_id, $refund_id = null ) { + $this->trigger( $order_id, false, $refund_id ); + } + + /** + * Partial refund notification + */ + public function trigger_partial( $order_id, $refund_id = null ) { + $this->trigger( $order_id, true, $refund_id ); + } + /** * Trigger. */ - function trigger( $order_id, $partial_refund = false, $refund_id = null ) { - + public function trigger( $order_id, $partial_refund = false, $refund_id = null ) { $this->partial_refund = $partial_refund; $this->set_email_strings( $partial_refund ); @@ -102,7 +111,7 @@ class WC_Email_Customer_Refunded_Order extends WC_Email { * @access public * @return string */ - function get_subject() { + public function get_subject() { return apply_filters( 'woocommerce_email_subject_customer_refunded_order', $this->format_string( $this->subject ), $this->object ); } @@ -112,7 +121,7 @@ class WC_Email_Customer_Refunded_Order extends WC_Email { * @access public * @return string */ - function get_heading() { + public function get_heading() { return apply_filters( 'woocommerce_email_heading_customer_refunded_order', $this->format_string( $this->heading ), $this->object ); } @@ -122,7 +131,7 @@ class WC_Email_Customer_Refunded_Order extends WC_Email { * @access public * @return string */ - function get_content_html() { + public function get_content_html() { ob_start(); wc_get_template( $this->template_html, array( 'order' => $this->object, @@ -140,7 +149,7 @@ class WC_Email_Customer_Refunded_Order extends WC_Email { * * @return string */ - function get_content_plain() { + public function get_content_plain() { ob_start(); wc_get_template( $this->template_plain, array( 'order' => $this->object, @@ -156,7 +165,7 @@ class WC_Email_Customer_Refunded_Order extends WC_Email { /** * Initialise settings form fields. */ - function init_form_fields() { + public function init_form_fields() { $this->form_fields = array( 'enabled' => array( 'title' => __( 'Enable/Disable', 'woocommerce' ), diff --git a/includes/wc-order-functions.php b/includes/wc-order-functions.php index 9dbeaf5a714..03530470ba7 100644 --- a/includes/wc-order-functions.php +++ b/includes/wc-order-functions.php @@ -722,7 +722,15 @@ function wc_create_refund( $args = array() ) { $max_remaining_items = absint( $order->get_item_count() - $order->get_item_count_refunded() ); if ( $max_remaining_refund > 0 || $max_remaining_items > 0 ) { - do_action( 'woocommerce_order_partially_refunded', $args['order_id'], true, $refund_id ); + /** + * woocommerce_order_partially_refunded + * + * @since 2.4.0 + * Note: 3rd arg was added in err. Kept for bw compat. 2.4.3 + */ + do_action( 'woocommerce_order_partially_refunded', $args['order_id'], $refund_id, $refund_id ); + } else { + do_action( 'woocommerce_order_fully_refunded', $args['order_id'], $refund_id ); } do_action( 'woocommerce_refund_created', $refund_id, $args ); diff --git a/readme.txt b/readme.txt index 71f1eee3eca..231e6b90abd 100644 --- a/readme.txt +++ b/readme.txt @@ -168,6 +168,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc * Fix - wc_get_product_variation_attributes should only get parent attributes which are for variations. * Tweak - Disable display_errors during ajax requests to prevent malformed JSON. * Tweak - When merging shipping taxes with a shipping rate taxes, ensure shipping rate taxes is not malformed. +* Tweak - Improved refund email events and woocommerce_order_fully_refunded hook. = 2.4.2 - 11/08/2015 = * Fix - If all variations are out of stock, maintain pricing display.