WC_Email_Customer_Fulfillment_Deleted{}WC 1.0└─ WC_Email

Customer Fulfillment Deleted Email.

Fulfillment deleted emails are sent to the customer when the merchant cancels an already fulfilled fulfillment. The notification isn’t sent for draft fulfillments.

Hooks from the class

Usage

$WC_Email_Customer_Fulfillment_Deleted = new WC_Email_Customer_Fulfillment_Deleted();
// use class methods

Methods

  1. public __construct()
  2. public trigger( $order_id, $fulfillment, $order = false )
  3. public get_default_subject()
  4. public get_default_heading()
  5. public get_content_html()
  6. public get_content_plain()
  7. public get_block_editor_email_template_content()
  8. public get_default_additional_content()
  9. private maybe_init_fulfillment_for_preview( $order )

Notes

  • Package: WooCommerce\Classes\Emails

WC_Email_Customer_Fulfillment_Deleted{} code WC 10.7.0

class WC_Email_Customer_Fulfillment_Deleted extends WC_Email {
	/**
	 * Fulfillment object.
	 *
	 * @var Fulfillment|null
	 */
	private $fulfillment;

	/**
	 * Constructor.
	 */
	public function __construct() {
		$this->id             = 'customer_fulfillment_deleted';
		$this->customer_email = true;
		$this->title          = __( 'Fulfillment deleted', 'woocommerce' );
		$this->email_group    = 'order-updates';
		$this->template_html  = 'emails/customer-fulfillment-deleted.php';
		$this->template_plain = 'emails/plain/customer-fulfillment-deleted.php';
		$this->placeholders   = array(
			'{order_date}'   => '',
			'{order_number}' => '',
		);

		// Triggers for this email.
		add_action( 'woocommerce_fulfillment_deleted_notification', array( $this, 'trigger' ), 10, 3 );

		// Call parent constructor.
		parent::__construct();

		$this->description = __( 'Fulfillment deleted emails are sent to the customer when the merchant cancels an already fulfilled fulfillment. The notification isn’t sent for draft fulfillments.', 'woocommerce' );

		$this->template_block_content = 'emails/block/general-block-content-for-fulfillment-emails.php';
	}

	/**
	 * Trigger the sending of this email.
	 *
	 * @param int            $order_id The order ID.
	 * @param Fulfillment    $fulfillment The fulfillment.
	 * @param WC_Order|false $order Order object.
	 */
	public function trigger( $order_id, $fulfillment, $order = false ) {
		$this->setup_locale();

		if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
			$order = wc_get_order( $order_id );
		}

		if ( is_a( $order, 'WC_Order' ) ) {
			$this->object                         = $order;
			$this->fulfillment                    = $fulfillment;
			$this->recipient                      = $this->object->get_billing_email();
			$this->placeholders['{order_date}']   = wc_format_datetime( $this->object->get_date_created() );
			$this->placeholders['{order_number}'] = $this->object->get_order_number();
		}

		if ( $this->is_enabled() && $this->get_recipient() ) {
			$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
		}

		$this->restore_locale();
	}

	/**
	 * Get email subject.
	 *
	 * @since  3.1.0
	 * @return string
	 */
	public function get_default_subject() {
		return __( 'A shipment from {site_title} order {order_number} has been cancelled', 'woocommerce' );
	}

	/**
	 * Get email heading.
	 *
	 * @since  3.1.0
	 * @return string
	 */
	public function get_default_heading() {
		return __( 'One of your shipments has been removed', 'woocommerce' );
	}

	/**
	 * Get content html.
	 *
	 * @return string
	 */
	public function get_content_html() {
		$this->maybe_init_fulfillment_for_preview( $this->object );
		return wc_get_template_html(
			$this->template_html,
			array(
				'order'              => $this->object,
				'fulfillment'        => $this->fulfillment,
				'email_heading'      => $this->get_heading(),
				'additional_content' => $this->get_additional_content(),
				'sent_to_admin'      => false,
				'plain_text'         => false,
				'email'              => $this,
			)
		);
	}

	/**
	 * Get content plain.
	 *
	 * @return string
	 */
	public function get_content_plain() {
		$this->maybe_init_fulfillment_for_preview( $this->object );
		return wc_get_template_html(
			$this->template_plain,
			array(
				'order'              => $this->object,
				'fulfillment'        => $this->fulfillment,
				'email_heading'      => $this->get_heading(),
				'additional_content' => $this->get_additional_content(),
				'sent_to_admin'      => false,
				'plain_text'         => true,
				'email'              => $this,
			)
		);
	}

	/**
	 * Get block editor email template content.
	 *
	 * @return string
	 */
	public function get_block_editor_email_template_content() {
		$this->maybe_init_fulfillment_for_preview( $this->object );
		return wc_get_template_html(
			$this->template_block_content,
			array(
				'order'         => $this->object,
				'fulfillment'   => $this->fulfillment,
				'sent_to_admin' => false,
				'plain_text'    => false,
				'email'         => $this,
			)
		);
	}

	/**
	 * Default content to show below main email content.
	 *
	 * @since 3.7.0
	 * @return string
	 */
	public function get_default_additional_content() {
		return __( 'If you have any questions or notice anything unexpected, feel free to reach out to our support team through your account or reply to this email.', 'woocommerce' );
	}

	/**
	 * Initialize fulfillment for email preview.
	 *
	 * This method sets up a dummy fulfillment object when the email is being previewed in the admin.
	 *
	 * @param WC_Order $order The order object.
	 *
	 * @since 10.1.0
	 */
	private function maybe_init_fulfillment_for_preview( $order ) {
		/**
		 * Filter to determine if this is an email preview.
		 *
		 * @since 9.8.0
		 */
		$is_email_preview = apply_filters( 'woocommerce_is_email_preview', false );
		if ( $is_email_preview ) {
			// If this is a preview, we need to set up a dummy fulfillment object.
			$this->fulfillment = new Fulfillment();
			$this->fulfillment->set_items(
				array_map(
					function ( $item ) {
						return array(
							'item_id' => $item->get_id(),
							'qty'     => 1,
						);
					},
					$order->get_items()
				)
			);

			// Set the deleted status.
			$this->fulfillment->set_date_deleted( gmdate( 'Y-m-d H:i:s' ) );
		}
	}
}