How to make my custom email trigger inside my email class, so that I can make it send, but only if a specific meta key and value from database is specificly meta_key = Pickup location and if the meta_value = Ishøj ?
Down below here I will paste my current code.
// Trigger email when status is processing
add_action( 'woocommerce_order_status_cancelled_to_processing_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_failed_to_processing_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_on-hold_to_processing_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $this, 'trigger' ), 10, 2 );
/**
* Prepares email content and triggers the email
*
* @param int $order_id
*/
public function trigger( $order_id, $order = false ) {
$this->setup_locale();
// Bail if no order ID is present
if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
$order = wc_get_order( $order_id );
}
$pickup = get_post_meta( $order_id, 'Pickup Location', true );
if ( is_a( $order, 'WC_Order' ) ) {
$this->object = $order;
$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();
}
// Send the email only once when an order is made
if ( ! get_post_meta( $order_id, 'Pickup Location', true ) && $pickup == 'Ishøj' ) {
if ( ! $this->is_enabled() || ! $this->get_recipient() ) {
return;
}
// All well, send the email
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
$this->restore_locale();
}
}