id = 'mbsrr_szerzoi_ertesito'; $this->title = 'My-Book szerzői értesítő'; $this->description = 'Rendeléskor a könyv szerzőjének kiküldött értesítés a vevő adataival és visszajelző gombokkal.'; $this->customer_email = false; $this->template_base = MBSRR_DIR . 'templates/'; $this->template_html = 'emails/mbsrr-szerzoi-ertesito.php'; $this->placeholders = [ '{rendeles_szam}' => '', '{szerzo_nev}' => '', ]; parent::__construct(); // Feladó: a beállított cím (alapból magankiadas@my-book.hu) add_filter( 'woocommerce_email_from_address', [ $this, 'felado_cim' ], 10, 2 ); add_filter( 'woocommerce_email_from_name', [ $this, 'felado_nev' ], 10, 2 ); } public function felado_cim( $cim, $email ) { if ( $email instanceof WC_Email && $email->id === $this->id ) { $sajat = sanitize_email( get_option( 'mbsrr_felado_email' ) ); if ( $sajat ) { return $sajat; } } return $cim; } public function felado_nev( $nev, $email ) { if ( $email instanceof WC_Email && $email->id === $this->id ) { return 'My-Book.hu – Magánkiadás'; } return $nev; } public function get_default_subject() { return 'Új rendelés érkezett a könyvére – #{rendeles_szam}'; } public function get_default_heading() { return 'Új rendelés érkezett a könyvére'; } /** * Küldés egy szerzőnek. * * @param WC_Order $order * @param array $adat term_id, nev, email, cimzett, item_ids, emlekezteto, teszt_mod, linkek * @return bool */ public function trigger( $order, $adat ) { if ( ! $order instanceof WC_Order ) { return false; } $this->setup_locale(); $this->object = $order; $this->mbsrr_adat = $adat; $this->recipient = $adat['cimzett']; $this->placeholders['{rendeles_szam}'] = $order->get_order_number(); $this->placeholders['{szerzo_nev}'] = $adat['nev']; $targy = $this->get_subject(); if ( ! empty( $adat['emlekezteto'] ) ) { $targy = 'Emlékeztető: ' . $targy; } if ( ! empty( $adat['teszt_mod'] ) ) { $targy = '[TESZT – eredeti címzett: ' . $adat['email'] . '] ' . $targy; } $siker = false; if ( $this->is_enabled() && $this->get_recipient() ) { $siker = $this->send( $this->get_recipient(), $targy, $this->get_content(), $this->get_headers(), $this->get_attachments() ); } $this->restore_locale(); return (bool) $siker; } /** Reply-To: a vásárló neve + címe */ public function get_headers() { $headers = 'Content-Type: ' . $this->get_content_type() . "\r\n"; if ( $this->object instanceof WC_Order && $this->object->get_billing_email() ) { $vevo_nev = trim( $this->object->get_billing_first_name() . ' ' . $this->object->get_billing_last_name() ); $headers .= 'Reply-to: ' . $vevo_nev . ' <' . $this->object->get_billing_email() . ">\r\n"; } return apply_filters( 'woocommerce_email_headers', $headers, $this->id, $this->object, $this ); } public function get_content_html() { return wc_get_template_html( $this->template_html, [ 'order' => $this->object, 'email_heading' => $this->get_heading(), 'email' => $this, 'adat' => $this->mbsrr_adat, 'sent_to_admin' => false, 'plain_text' => false, ], '', $this->template_base ); } public function get_content_plain() { $order = $this->object; $adat = $this->mbsrr_adat; $sor = []; $sor[] = 'Kedves ' . $adat['nev'] . '!'; $sor[] = ''; $sor[] = 'A my-book.hu oldalon új megrendelés érkezett az Ön könyvére (#' . $order->get_order_number() . ').'; $sor[] = 'Kérjük, vegye fel a kapcsolatot a vásárlóval, majd az alábbi hivatkozások egyikével jelezze az állapotot.'; $sor[] = ''; $sor[] = 'Vásárló: ' . trim( $order->get_billing_first_name() . ' ' . $order->get_billing_last_name() ); $sor[] = 'E-mail: ' . $order->get_billing_email(); $sor[] = 'Telefon: ' . $order->get_billing_phone(); $sor[] = 'Cím: ' . $order->get_formatted_billing_address(); $sor[] = ''; foreach ( (array) $adat['item_ids'] as $item_id ) { $item = $order->get_item( $item_id ); if ( $item ) { $sor[] = '- ' . $item->get_name() . ' × ' . $item->get_quantity(); } } $sor[] = ''; $sor[] = 'Felvettem a kapcsolatot: ' . $adat['linkek']['kapcsolatfelvetel']; $sor[] = 'Megegyeztünk: ' . $adat['linkek']['lezarva']; $sor[] = 'Nem érem el a vevőt: ' . $adat['linkek']['sikertelen']; return implode( "\n", $sor ); } }