我正在尝试创建一个表单,该表单在提交表单后自动更新订单状态。该表单位于订单详细信息页面,因此我假设当前页面 ID 等于 orderID。当我尝试提交表单时,它只是卡住了,什么也没有发生。我假设获取 orderID 以及更新状态的订单存在问题。
我找到了 gform_after_submission 挂钩并将其链接到放置在订单详细信息页面上的表单(表单 ID 7)。我一直在尝试使用全局 $wpdb; 但不太确定那是否是正确的做法。
add_action( 'gform_after_submission', 'set_post_content', 10, 2 );
function update_order_submission( $order_id ) {
global $wpdb;
//getting orderID
$order = wc_get_order( $order_id );
//changing order status
$order = array();
$order['ID'] = $order->ID;
$order['post_status'] = 'wc-completed';
//updating order
wp_update_post( $order );
}
我期望一旦提交了表单,当前订单 ID(提交表单的页面)的订单状态将随着订单状态完成而更新。
桃花长相依
慕尼黑5688855