get_shipping_methods() as $item ) {
if ( in_array( $item->get_method_id(), $pickup_methods, true ) ) {
$is_pickup = true;
break;
}
}
if ( ! $is_pickup ) {
return;
}
$subject = get_option(
'aisp_otools_pickup_subject',
__( 'Your order is ready for pickup', 'aisp-order-tools-for-woocommerce' )
);
$subject = AISP_OTools_Email_Helper::replace_placeholders( $subject, $order );
$heading = __( 'Your order is ready for pickup', 'aisp-order-tools-for-woocommerce' );
$message = get_option(
'aisp_otools_pickup_message',
__( 'Your order is now ready for pickup at our store. You can come anytime during business hours.', 'aisp-order-tools-for-woocommerce' )
);
$message = AISP_OTools_Email_Helper::replace_placeholders( $message, $order );
$first_name = $order->get_billing_first_name();
$greeting = sprintf(
// translators: %s is the first name of the customer (e.g. John).
__( 'Hi %s,', 'aisp-order-tools-for-woocommerce' ),
$first_name
);
$final_message = AISP_OTools_Email_Helper::replace_placeholders( $greeting . ' ' . $message, $order );
$store_address = trim( get_option( 'woocommerce_store_address', '' ) );
$store_city = trim( get_option( 'woocommerce_store_city', '' ) );
$store_postal = trim( get_option( 'woocommerce_store_postcode', '' ) );
$store_country = trim( get_option( 'woocommerce_default_country', '' ) );
$full_address = trim( $store_address . ', ' . $store_city . ' ' . $store_postal . ', ' . $store_country );
$directions_html = '';
if (
! empty( $store_address ) &&
'yes' === get_option( 'aisp_otools_enable_get_direction_pickup_email', 'no' )
) {
$encoded = rawurlencode( $full_address );
$directions_html = '
📍 ' . esc_html__( 'Get directions to the pickup location', 'aisp-order-tools-for-woocommerce' ) . '
';
}
$mailer = \WC()->mailer();
$header_image = get_option( 'woocommerce_email_header_image' );
if ( $header_image ) {
$logo_html = '
';
} else {
$logo_html = '
' . esc_html( get_bloginfo( 'name' ) ) . '
';
}
$html = '
';
$headers = [];
$user_id = $order->get_user_id();
$cc_emails = [];
if ( $user_id ) {
$cc1 = sanitize_email( get_user_meta( $user_id, 'cc_email_1', true ) );
$cc2 = sanitize_email( get_user_meta( $user_id, 'cc_email_2', true ) );
if ( is_email( $cc1 ) ) {
$cc_emails[] = $cc1;
}
if ( is_email( $cc2 ) ) {
$cc_emails[] = $cc2;
}
}
if ( ! empty( $cc_emails ) ) {
$headers[] = 'Cc: ' . implode( ', ', $cc_emails );
}
$customer_email = $order->get_billing_email();
if ( ! $customer_email ) {
return;
}
$mailer->send(
$customer_email,
wp_strip_all_tags( $subject ),
$html,
$headers
);
}
public function disable_default_completed_email_for_pickup( $enabled, $order ) {
if ( ! $order instanceof \WC_Order ) {
return $enabled;
}
if ( 'yes' !== get_option( 'aisp_otools_enable_email_pickup', 'no' ) ) {
return $enabled;
}
$pickup_methods = (array) get_option( 'aisp_otools_pickup_methods', [ 'local_pickup' ] );
foreach ( $order->get_shipping_methods() as $item ) {
foreach ( $pickup_methods as $pickup_option ) {
if ( 0 === strpos( $item->get_method_id(), $pickup_option ) ) {
return false;
}
}
}
return $enabled;
}
}