【发布时间】:2022-01-04 10:57:35
【问题描述】:
我需要将带有订单 ID 和密码的链接添加到订单商品元数据。
目前,我正在使用 woocommerce_checkout_create_order_line_item 操作成功地将其他信息添加到项目元数据,但是当此操作运行时,订单 ID 还无法访问 (?)。
我可以通过其他方式执行此操作,以便在保存订单并向客户发送通知之前添加链接吗?
add_action( 'woocommerce_checkout_create_order_line_item', 'custom_checkout_create_order_line_item', 20, 4 );
function custom_checkout_create_order_line_item( $item, $cart_item_key, $values, $order ) {
if( ! isset( $values['test_title'] ) ) { return; }
// add test info as order item metadata
if( ! empty( $values['test_title'] ) ) {
$test_pw = wp_generate_password(); // generate a password
$item->update_meta_data( '_test_id', $values['test_id'] ); // add test id
$item->update_meta_data( '_test_password', $test_pw ); // add test access password
$item->update_meta_data( 'Access link', // add test access permalink
get_permalink( $values['test_id'] ) . '?order=' . $order->get_id() . '&pw=' . $test_pw );
}
}
【问题讨论】:
标签: wordpress woocommerce hook-woocommerce orders email-notifications