id = 'proofkit_proof_ready'; $this->title = __( 'Proof ready to review', 'proofkit' ); $this->description = __( 'Sent to the customer when the shop sends a proof for approval.', 'proofkit' ); $this->customer_email = true; $this->enabled = 'yes'; $this->template_html = 'emails/proof-ready.php'; $this->template_plain = 'emails/plain/proof-ready.php'; $this->template_base = PROOFKIT_DIR . 'templates/'; $this->placeholders = [ '{order_number}' => '', '{order_date}' => '', '{customer_name}' => '', '{item_name}' => '', ]; parent::__construct(); $this->enabled = $this->get_option( 'enabled', 'yes' ); } /** * Send the proof-ready email. * * @param \WC_Order $order Order. * @param object $proof Proof record. * @param string $url Tokenised proof URL. */ public function trigger( $order, $proof = null, $url = '' ): bool { $this->setup_locale(); $this->proof = is_object( $proof ) ? $proof : null; $this->proof_url = (string) $url; $this->item_name = ''; if ( $order instanceof \WC_Order ) { $this->object = $order; $this->recipient = (string) $order->get_billing_email(); $this->placeholders['{order_number}'] = (string) $order->get_order_number(); $created = $order->get_date_created(); $this->placeholders['{order_date}'] = $created ? wc_format_datetime( $created ) : ''; $this->placeholders['{customer_name}'] = (string) $order->get_formatted_billing_full_name(); if ( $this->proof && isset( $this->proof->order_item_id ) ) { $item = $order->get_item( (int) $this->proof->order_item_id ); if ( $item instanceof \WC_Order_Item_Product && '' !== (string) $item->get_name() ) { $this->item_name = (string) $item->get_name(); } } } if ( '' === $this->item_name ) { $this->item_name = __( 'your artwork', 'proofkit' ); } $this->placeholders['{item_name}'] = $this->item_name; $sent = false; if ( $this->is_enabled() && '' !== $this->get_recipient() ) { $sent = (bool) $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ); } $this->restore_locale(); return $sent; } /** * Subject from settings, with placeholders replaced. */ public function get_subject() { $subject = (string) Settings::get( 'subject', __( 'Your proof is ready to review — order {order_number}', 'proofkit' ) ); if ( '' === trim( $subject ) ) { $subject = __( 'Your proof is ready to review — order {order_number}', 'proofkit' ); } $subject = $this->format_string( $subject ); if ( $this->object instanceof \WC_Order ) { $subject = str_replace( '{order_number}', (string) $this->object->get_order_number(), $subject ); } return apply_filters( // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Reuses WooCommerce's own email subject filter name. 'woocommerce_email_subject_' . $this->id, $subject, $this, $this->object ); } /** * HTML body. */ public function get_content_html() { return wc_get_template_html( $this->template_html, [ 'order' => $this->object, 'email' => $this, 'additional_content' => $this->get_additional_content(), ], '', $this->template_base ); } /** * Plain-text body. */ public function get_content_plain() { return wc_get_template_html( $this->template_plain, [ 'order' => $this->object, 'email' => $this, 'additional_content' => $this->get_additional_content(), ], '', $this->template_base ); } /** * From name from settings when set. */ public function get_from_name( $from_name = '' ) { $name = (string) Settings::get( 'from_name', '' ); if ( '' !== trim( $name ) ) { return wp_specialchars_decode( $name, ENT_QUOTES ); } return parent::get_from_name( $from_name ); } /** * From address from settings when it is a valid email address. */ public function get_from_address( $from_email = '' ) { $email = (string) Settings::get( 'from_email', '' ); if ( is_email( $email ) ) { return $email; } return parent::get_from_address( $from_email ); } /** * Send a proof-ready email through the mailer instance when available. * * @param \WC_Order $order Order. * @param object $proof Proof record. * @param string $url Tokenised proof URL. */ public static function send_proof_ready( \WC_Order $order, object $proof, string $url ): bool { $email = null; $woocommerce = function_exists( 'WC' ) ? WC() : null; if ( $woocommerce instanceof \WooCommerce ) { $mailer = $woocommerce->mailer(); if ( $mailer && isset( $mailer->emails['proofkit_proof_ready'] ) && $mailer->emails['proofkit_proof_ready'] instanceof self ) { $email = $mailer->emails['proofkit_proof_ready']; } } if ( ! $email instanceof self ) { $email = new self(); } return $email->trigger( $order, $proof, $url ); } }