id = 'rtkt_customer_update'; $this->customer_email = true; $this->title = __( 'Return request update', 'returnkit' ); $this->description = __( 'Sent to the customer when their request is approved, received, completed or declined, and when you send them a message.', 'returnkit' ); parent::__construct(); } /** * Default subject. * * @return string */ public function get_default_subject() { return __( 'Update on your {request_type} {request_number}', 'returnkit' ); } /** * Default heading. * * @return string */ public function get_default_heading() { return __( 'Update on your request', 'returnkit' ); } /** * Subject per event (a subject customised in the settings wins). * * @return string */ public function get_subject() { if ( '' !== (string) $this->get_option( 'subject', '' ) ) { return parent::get_subject(); } $withdrawal = $this->request && $this->request->is_withdrawal(); $subjects = array( 'approved' => $withdrawal ? __( 'Your withdrawal {request_number} is accepted', 'returnkit' ) : __( 'Your return {request_number} is approved', 'returnkit' ), 'received' => __( 'We\'ve received your returned items ({request_number})', 'returnkit' ), 'completed' => __( 'Your {request_type} {request_number} is complete', 'returnkit' ), 'rejected' => __( 'Update on your {request_type} {request_number}', 'returnkit' ), 'message' => __( 'A message about your {request_type} {request_number}', 'returnkit' ), ); $subject = isset( $subjects[ $this->event ] ) ? $subjects[ $this->event ] : $this->get_default_subject(); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WooCommerce's own hook. return apply_filters( 'woocommerce_email_subject_' . $this->id, $this->format_string( $subject ), $this->object, $this ); } /** * Send. * * @param Request $request Request. * @param string $event Event. * @param string $message Message for the customer. * @param array $data Extra data (amount …). * @return bool */ public function trigger( Request $request, $event, $message = '', array $data = array() ) { $this->setup( $request ); $this->event = (string) $event; $this->recipient = $request->email(); $this->extra = array( 'event' => $this->event, 'message' => (string) $message, 'data' => $data, 'view_url' => Access::request_url( $request, true ), 'instructions' => 'approved' === $event && $request->needs_shipping_back() ? Settings::text( 'return_instructions' ) : '', 'address' => 'approved' === $event && $request->needs_shipping_back() ? (string) Settings::get( 'return_address' ) : '', ); return $this->dispatch(); } /** * Attachments (Pro adds the return label). * * @return array */ public function get_attachments() { $attachments = parent::get_attachments(); if ( $this->request && 'approved' === $this->event ) { /** * Files to attach to the "approved" email. * * @param string[] $attachments Paths. * @param Request $request Request. */ $attachments = (array) apply_filters( 'rtkt_approved_email_attachments', $attachments, $this->request ); } return $attachments; } }