【发布时间】:2021-12-03 04:33:06
【问题描述】:
我正在使用此代码添加管理操作以更改批量订单状态。 我有名为“wc-to-order”的自定义构建状态。 不幸的是,使用 Woo 批量操作中的代码时出现错误。 谁能帮我解决?
这是代码:
add_action( 'admin_action_wc-to-order', 'add_new_order_status_wc_on_hold' ); // admin_action_{action name}
function add_new_order_status_wc_on_hold() {
// if an array with order IDs is not presented, exit the function
if( !isset( $_REQUEST['post'] ) && !is_array( $_REQUEST['post'] ) )
return;
foreach( $_REQUEST['post'] as $order_id ) {
$order = new WC_Order( $order_id );
$order_note = 'That\'s what happened by bulk edit:';
$order->update_status( 'wc-to-order', $order_note, true );
}
$location = add_query_arg( array(
'post_type' => 'shop_order',
'wc-to-order' => 1, // markED_awaiting_shipment=1 is just the $_GET variable for notices
'changed' => count( $_REQUEST['post'] ), // number of changed orders
'ids' => join( $_REQUEST['post'], ',' ),
'post_status' => 'all'
), 'edit.php' );
wp_redirect( admin_url( $location ) );
exit;
}
我在调试日志中得到了这个
PHP Fatal error: Uncaught TypeError: join(): Argument #2 ($array) must be of type ?array, string given in /public_html/sitename/wp-content/themes/themename/functions.php:648
【问题讨论】:
标签: php wordpress woocommerce hook-woocommerce woocommerce-theming