Skip to content

Instantly share code, notes, and snippets.

@danielcharrua
Last active August 1, 2025 18:07
Show Gist options
  • Save danielcharrua/d3459a80c7a194bfb8a41220d0306e1c to your computer and use it in GitHub Desktop.
Save danielcharrua/d3459a80c7a194bfb8a41220d0306e1c to your computer and use it in GitHub Desktop.
Restrict permission on WooCommerce REST API
<?php
/**
* Restrict permission on WooCommerce REST API based on user_login and request type
* Let 'daniel' access ONLY to products data
*/
add_filter( 'woocommerce_rest_check_permissions', 'charrua_allow_only_products', 10, 4 );
function charrua_allow_only_products( $permission, $context, $object_id, $type ) {
if ('daniel' === wp_get_current_user()->user_login){
return ( 'product' === $type ) ? $permission : false;
}
return $permission;
}
@rifatspir
Copy link

rifatspir commented Aug 1, 2025

How to provide only write/read permission only in orders rest all other things will be Read Only. Based on any specific generated rest api?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment