添加等待,然后添加操作功能已运行

发布于 2025-02-04 07:07:16 字数 1252 浏览 7 评论 0原文

我正在按新的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

り繁华旳梦境 2025-02-11 07:07:16

这个钩子解决了问题

woocommerce_booking_in-cart_to_pending-confirmation_notification

Problem was solved with this hook

woocommerce_booking_in-cart_to_pending-confirmation_notification
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文