...
To extend the standard Maileon transaction you can use th the wc_maileon_transaction_attributes
and wc_maileon_transaction_content
hooks. These hooks are called for all default WooCommerce emails.
...
Adding a custom email type is achieved using the wc_maileon_email_hooks
filter. The keys of this array are the default WooCommerce email handler classes ids and the values are the replacement handler classes.
Code Block | ||
---|---|---|
| ||
function wc_maileon_extend_email_hooks($hooks) { $hooks[\WC_Email_Booking_Reminder::class'booking_reminder'] = BookingReminder::class; return $hooks; } add_filter('wc_maileon_email_hooks', 'wc_maileon_extend_email_hooks'); |
...
Code Block | ||
---|---|---|
| ||
class BookingReminder extends \Maileon\WooCommerce\Emails\TransactionalOrderStatusChanged { /** * Trigger a transaction based on the given object * * @param mixed $object * @param string $to The email sending address to send message. * @param string $subject Optional. Email subject * @param string $message Optional. Message contents * @param string|array $headers Optional. Additional headers. * @param integer $booking_idstring|array $attachments Optional. Files to attach. * @return voidbool Whether the email contents were sent successfully. */ public function send_booking_reminder($booking_id) { trigger($object, $to, $subject = '', $message = '', $headers = '', $attachments = array()) { $booking = get_wc_booking($object); if (is_a($booking, \WC_Booking::class)) { $content = $this->trigger($booking_id>map_maileon_booking_transaction_content($booking); $order = $booking->get_order(); } if(!is_object($order)) { /** * Gets the WooCommerce object for this email return; * * @param integer $id } * @param boolean $object *$customer_id @return \WC_Booking= $order->get_customer_id(); */ protected function get_object($id, $object = false)return $this->trigger_maileon_transaction($to, $content, $customer_id, $object, $this->id); } else { return get_wc_booking($id); throw new \Exception("Booking not found for id: " . $object); } } /** * Gets Sets the default value for the Maileon transaction name for this email * * @return stringvoid */ public function getinit_transactionform_namefields() { parent::init_form_fields(); return$this->form_fields['maileon_transaction_name']['default'] = 'wc_booking_reminder'; } /** * Returns the maileon transaction type definition * * @return array */ public function get_transaction_attributes() { return [ new AttributeType(null, 'booking.id', DataType::$STRING, false), new AttributeType(null, 'booking.start_date', DataType::$TIMESTAMP, false), new AttributeType(null, 'booking.end_date', DataType::$TIMESTAMP, false), new AttributeType(null, 'booking.zoom.link', DataType::$STRING, false), ]; } /** * Maps the underlying booking to the transaction * * @param \WC_Booking $booking * @return array */ public function map_maileon_booking_transaction_content($booking) { return [ 'booking.id' => (string)$booking->get_id(), 'booking.start_date' => $booking->get_start_date(), 'booking.end_date' => $booking->get_end_date(), 'booking.zoom.link' => WC_Bookings_Maileon()->get_zoom_browser_join_link($booking->get_id()) ]; } } |
getinit_transactionform_name
This method should return the name of the transaction type for this classfields
Can be used to override default form fields for the settings of this type of transaction.
get_transaction_attributes
This method should return an array of Maileon attribute types which define the structure of the transaction type.
get_object
trigger
This method should convert the id received by the trigger method to a relevant object (\WC_Booking
in this example). If it is not overridden a \WC_Order
object is returned by default.
map_transaction_content
This method should map the object of this email to a Maileon transaction. The object received by is the type given by get_object
. By default this method receives a \WC_Order
object.
send_booking_reminder
This is the fucntion that handles the wc-booking-action
. In this example it simply forwards to the default trigger
method defined in the parent classMaileon transaction based on the supplied arguments.