将附件添加到 WooCommerce 自定义电子邮件
Add attachment to WooCommerce custom email
我有这个自定义代码电子邮件触发器,它正在向客户发送带有礼物的电子邮件。
我想在电子邮件中附上带有pdf的礼物。我已经尝试过了,但是没有用。有什么建议吗?
你知道我做错了什么吗?
add_action("woocommerce_order_status_changed", "dobierka_gift");
function dobierka_gift($order_id, $checkout=null) {
global $woocommerce;
$order = new WC_Order( $order_id );
if( $order->has_status( 'completed' ) && 'dobirka' == $order->get_payment_method() ) {
// Create a mailer
$mailer = $woocommerce->mailer();
$attachments = array(WP_CONTENT_DIR . 'PDF HERE NOT WORKING');
$message_body = sprintf( __( 'Message here'), $order->get_billing_first_name());
$message = $mailer->wrap_message(
// Message head and message body.
sprintf( __( 'Head here' ), $order->get_order_number() ), $message_body );
$mailer->send( $order->billing_email, sprintf( __( 'Subject here' ), $order->get_order_number() ), $message, $attachments );
}
}
您的代码有一些错误和过时的代码
- 路径文件=
yoursite.com/wp-content/file.pdf
所以你得到:
function action_woocommerce_order_status_changed( $order_id, $old_status, $new_status, $order ) {
// Compare
if ( $new_status == 'completed' && $order->get_payment_method() == 'dobirka' ) {
// Mailer
$mailer = WC()->mailer();
// To, subject, message
$to = $order->get_billing_email();
$subject = __( 'My subject', 'woocommerce' );
$message_body = __( 'My message', 'woocommerce' );
// Message head and message body.
$message = $mailer->wrap_message( sprintf( __( 'Message here %s', 'woocommerce' ), $order->get_billing_first_name() ), $message_body );
// Headers
$headers = 'Content-Type: text/html\r\n';
// Path to file
$attachments = array( WP_CONTENT_DIR . '/file.pdf' );
// Send an email
$mailer->send( $to, $subject, $message, $headers, $attachments );
}
}
add_action( 'woocommerce_order_status_changed', 'action_woocommerce_order_status_changed', 10, 4 );
我有这个自定义代码电子邮件触发器,它正在向客户发送带有礼物的电子邮件。
我想在电子邮件中附上带有pdf的礼物。我已经尝试过了,但是没有用。有什么建议吗?
你知道我做错了什么吗?
add_action("woocommerce_order_status_changed", "dobierka_gift");
function dobierka_gift($order_id, $checkout=null) {
global $woocommerce;
$order = new WC_Order( $order_id );
if( $order->has_status( 'completed' ) && 'dobirka' == $order->get_payment_method() ) {
// Create a mailer
$mailer = $woocommerce->mailer();
$attachments = array(WP_CONTENT_DIR . 'PDF HERE NOT WORKING');
$message_body = sprintf( __( 'Message here'), $order->get_billing_first_name());
$message = $mailer->wrap_message(
// Message head and message body.
sprintf( __( 'Head here' ), $order->get_order_number() ), $message_body );
$mailer->send( $order->billing_email, sprintf( __( 'Subject here' ), $order->get_order_number() ), $message, $attachments );
}
}
您的代码有一些错误和过时的代码
- 路径文件=
yoursite.com/wp-content/file.pdf
所以你得到:
function action_woocommerce_order_status_changed( $order_id, $old_status, $new_status, $order ) {
// Compare
if ( $new_status == 'completed' && $order->get_payment_method() == 'dobirka' ) {
// Mailer
$mailer = WC()->mailer();
// To, subject, message
$to = $order->get_billing_email();
$subject = __( 'My subject', 'woocommerce' );
$message_body = __( 'My message', 'woocommerce' );
// Message head and message body.
$message = $mailer->wrap_message( sprintf( __( 'Message here %s', 'woocommerce' ), $order->get_billing_first_name() ), $message_body );
// Headers
$headers = 'Content-Type: text/html\r\n';
// Path to file
$attachments = array( WP_CONTENT_DIR . '/file.pdf' );
// Send an email
$mailer->send( $to, $subject, $message, $headers, $attachments );
}
}
add_action( 'woocommerce_order_status_changed', 'action_woocommerce_order_status_changed', 10, 4 );