【发布时间】:2019-11-11 13:42:32
【问题描述】:
我正在尝试创建一个在提交表单后自动更新订单状态的表单。该表单位于订单详细信息页面,因此我假设当前页面 ID 等于 orderID。当我尝试提交表单时,它只是卡住了,没有任何反应。我假设获取 orderID 以及更新状态的订单存在问题。
我找到了 gform_after_submission 挂钩并将其链接到放置在订单详细信息页面上的表单(表单 ID 7)。我一直在尝试使用 global $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(提交表单的页面)的订单状态将随着订单状态完成而更新。
【问题讨论】:
标签: php wordpress woocommerce hook gravity-forms-plugin