添加等待,然后添加操作功能已运行
我正在按新的WooCommerce订单发送额外的邮件。
我正在使用Woo Commerce_new_order钩。
问题是,当电子邮件到达时,它没有产品信息。我认为WooCommerce_New_Order Hook在所有内容都存储在数据库中之前会发射。因为如果我使用现有订单运行此信息,则每个信息都包含在内。
问题是如何在获取数据并发送电子邮件之前添加延迟?
add_action( 'woocommerce_new_order', 'extra_mail_after_new_order', 20, 1 );
function extra_mail_after_new_order( $order_id ) {
$order = wc_get_order( $order_id );
$items = $order->get_items();
foreach ( $items as $item ) {
$product_name = $item->get_name();
$product_id = $item->get_product_id();
$product = wc_get_product($product_id);
$product_variation_id = $item->get_variation_id();
$product_data = $product->get_meta('extra_email')
}
add_filter('wp_mail_content_type', function( $content_type ) {
return 'text/html';
});
$to = '[email protected]';
$subject = $product_name . ' uusi tilaus!';
$message = 'Order id: '. $order_id . '<br />product name: '. $product_name . '<br />product id: '. $product_id. '<br />product meta: '. $product_data. '<br />status: '. $status ;
wp_mail( $to, $subject, $message ); }
I am sending extra Mail after new woocommerce order.
I am using woo commerce_new_order hook.
Problem is that when the email arrives it hasn't had product info. I think that woocommerce_new_order hook fires before everything are stored in the database. Because if I run this with the existing order every info is included.
The question is how could I add a delay before data is fetched and email is sent?
add_action( 'woocommerce_new_order', 'extra_mail_after_new_order', 20, 1 );
function extra_mail_after_new_order( $order_id ) {
$order = wc_get_order( $order_id );
$items = $order->get_items();
foreach ( $items as $item ) {
$product_name = $item->get_name();
$product_id = $item->get_product_id();
$product = wc_get_product($product_id);
$product_variation_id = $item->get_variation_id();
$product_data = $product->get_meta('extra_email')
}
add_filter('wp_mail_content_type', function( $content_type ) {
return 'text/html';
});
$to = '[email protected]';
$subject = $product_name . ' uusi tilaus!';
$message = 'Order id: '. $order_id . '<br />product name: '. $product_name . '<br />product id: '. $product_id. '<br />product meta: '. $product_data. '<br />status: '. $status ;
wp_mail( $to, $subject, $message ); }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
这个钩子解决了问题
Problem was solved with this hook