我有一段代码,用于在有人购买ID为1136的产品后创建视频通行证。由于某些原因,order\\u status\\u completed没有执行任何操作。我尝试将该函数挂接到woocommerce\\u thankyou和woocommerce\\u payment\\u complete。我不知所措。我运行代码时没有将其与操作挂钩,它运行得很好。我的错误日志中没有bug。。没有什么
add_action(\'woocommerce_order_status_completed\',\'create_video_passes\',10,1);
function create_video_passes($orderId){
$order = wc_get_order($orderId);
$orderData = $order->get_data();
foreach( $order->get_items() as $item ):
$item = $item->get_data();
if($item[\'id\'] == 1136){
foreach(range(1,$item[\'quantity\']) as $index) {
$passArray = array(
\'post_title\' => generateRandomString(),
\'post_type\' => \'videopass\',
\'post_status\' => \'publish\',
\'post_author\' => 1
);
// Insert the post into the database
$passId = wp_insert_post( $passArray );
update_post_meta( $passId, \'gebruikt\',\'nee\');
update_post_meta( $passId, \'email\',$orderData[\'billing\'][\'email\']);
}
}
endforeach;
}