我有这个自定义代码电子邮件触发器,它发送电子邮件给客户的礼物。
我想把礼物和电子邮件中的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/htmlrn';
// 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 );