Wrong redirect
-
Hello B2BKing Support,
we found a compatibility issue between B2BKing and WooCommerce (latest version) when manually creating a new order in the WooCommerce admin.
When opening this WooCommerce admin URL:
/wp-admin/admin.php?page=wc-orders&action=new
the request is incorrectly redirected to:
/wp-admin/edit.php?post_type=b2bking_groupWe debugged the redirect using a wp_redirect backtrace. The redirect is triggered here:
/wp-content/plugins/b2bking-wholesale-for-woocommerce/admin/class-b2bking-admin.php:1638
B2bkingcore_Admin->b2bking_save_groups_metaboxes()The backtrace shows that WooCommerce creates/saves the new order via HPOS, then WooCommerce creates a backup post via wp_insert_post(), and during that process the B2BKing group metabox save handler is executed.
Relevant call chain:
WooCommerce PageController->setup_action_new_order()
WC_Order->save()
OrdersTableDataStore->maybe_create_backup_post()
wp_insert_post()
do_action()
B2bkingcore_Admin->b2bking_save_groups_metaboxes()
wp_redirect()So it looks like the B2BKing group metabox save handler is running during WooCommerce order creation, although it should only run for the B2BKing group post type.
As a temporary workaround, we solved the issue by blocking only this specific wrong redirect with the following snippet:
add_filter('wp_redirect', function ($location, $status) {
$request_uri = $_SERVER['REQUEST_URI'] ?? '';
$is_new_wc_order_screen =
is_admin()
&& strpos($request_uri, 'admin.php?page=wc-orders') !== false
&& strpos($request_uri, 'action=new') !== false;
$is_wrong_b2bking_redirect =
strpos($location, 'edit.php?post_type=b2bking_group') !== false;
if ($is_new_wc_order_screen && $is_wrong_b2bking_redirect) {
return false;
}
return $location;
}, 999999, 2);This workaround prevents the wrong redirect and allows the WooCommerce “new order” screen to load correctly.
However, this is only a temporary workaround. The proper fix should be inside B2BKing: the function b2bking_save_groups_metaboxes() should return early unless the current saved post is actually a b2bking_group post type.
For example, something like:
if (get_post_type($post_id) !== 'b2bking_group') {
return;
}Please check why B2BKing performs a redirect to edit.php?post_type=b2bking_group during WooCommerce HPOS order creation and restrict this handler/redirect to the B2BKing group post type only.
– All other plugins was disabled.
– Default htacces
– No caching enabled
– Default wp theme
– tested in private tab.Thank you.
BR
Tommy
You must be logged in to reply to this topic.