Skip to content

Instantly share code, notes, and snippets.

@TanvirHasan19
Created April 13, 2026 06:09
Show Gist options
  • Select an option

  • Save TanvirHasan19/d43dbd2fc1e73cdfea0e56030b1bafa6 to your computer and use it in GitHub Desktop.

Select an option

Save TanvirHasan19/d43dbd2fc1e73cdfea0e56030b1bafa6 to your computer and use it in GitHub Desktop.
WWOF + WWPP — hide non-wholesale variations in REST when loading
/**
* Temporary: WWOF + WWPP — hide non-wholesale variations in REST when loading
* /wc/v3/products/{id}/variations?wwof=… (parent + dropdown on order form).
* Remove after Wholesale Order Form includes an official fix.
*/
add_filter(
'woocommerce_rest_product_variation_object_query',
static function ( $args, $request ) {
if ( ! $request instanceof WP_REST_Request || ! $request->get_param( 'wwof' ) ) {
return $args;
}
if ( 'yes' !== get_option( 'wwpp_settings_only_show_wholesale_products_to_wholesale_users', 'no' ) ) {
return $args;
}
if ( 'edit' === $request->get_param( 'context' ) || current_user_can( 'manage_options' ) ) {
return $args;
}
if ( ! function_exists( 'wc_get_product' ) || empty( $GLOBALS['wc_wholesale_prices'] ) ) {
return $args;
}
global $wc_wholesale_prices;
$registered = $wc_wholesale_prices->wwp_wholesale_roles->getAllRegisteredWholesaleRoles();
$user_role = $wc_wholesale_prices->wwp_wholesale_roles->getUserWholesaleRole()[0] ?? '';
if ( ! $user_role || ! isset( $registered[ $user_role ] ) ) {
return $args;
}
$product_id = isset( $request['product_id'] ) ? absint( $request['product_id'] ) : 0;
if ( ! $product_id ) {
return $args;
}
$parent = wc_get_product( $product_id );
if ( ! $parent || ! $parent->is_type( 'variable' ) ) {
return $args;
}
$filtered_children = array_map( 'absint', (array) $parent->get_children() );
if ( ! empty( $args['post__in'] ) ) {
$intersect = array_values(
array_intersect(
array_map( 'absint', (array) $args['post__in'] ),
$filtered_children
)
);
$args['post__in'] = ! empty( $intersect ) ? $intersect : array( 0 );
} else {
$args['post__in'] = ! empty( $filtered_children ) ? $filtered_children : array( 0 );
}
return $args;
},
110,
2
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment