Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
patio

Hide option from inline for a user role

I’m using Woocommerce addon. And there is a Status column (Pending, Processing, etc…)

If Admin is user, Ok to have all options available. If not an Admin, how to hide options from Inline Edit OPTIONS?

Thanks, nice plugin btw!

4 years, 7 months ago
Stefan van den Dungen Gronovius
Developer

If you want to disable specific options for a user role, the only option you have is to use one of our filters.
The following filter allows you to alter the editing settings for a column.

acp/editing/view_settings

Have a look at the first example where we set options. You can do something similar and unset the options you don’t want to show. I hope this will solve your issue.

4 years, 7 months ago
patio

I dind’t have success. Can you help?

I put this code but didn’t work:

function my_acp_custom_field_editing_selectbox( $data, $column ) {

	if ( $column instanceof ACP\Column\CustomField ) {
		if ( 'column-status' === $column->get_type() ) {
			$data['type'] = 'select';
			$data['options'] = array(
				'apple'  => 'Apple',
				'orange' => 'Orange',
				'banana' => 'Banana',
				'pear'   => 'Pear',
			);
		}

	}
	return $data;
}

add_filter( 'acp/editing/view_settings', 'my_acp_custom_field_editing_selectbox', 10, 2 );

How am I supposed to make this work? I’ve tried a lot of different variable and ways. But can’t understand how to change the select options, like tutorial.

It is because Woocommerce Add-on ?

4 years, 7 months ago
Stefan van den Dungen Gronovius
Developer

You’ll have to check for the correct column, in this case, the WooCommerce status column (not the custom field column). The following snippet will check for the correct column. Next, it will remove the completed options when a user is an editor.

function acp_iedit_remove_wc_status_options( $data, $column ) {

	if ( $column instanceof ACA\WC\Column\ShopOrder\Status ) {
		$user = wp_get_current_user();

		if ( in_array( 'author', $user->roles ) ) {
			unset( $data['options']['wc-completed'] );
		}
	}

	return $data;
}

add_filter( 'acp/editing/view_settings', 'acp_iedit_remove_wc_status_options', 10, 2 );
4 years, 7 months ago
patio

No success. I even checked more easily, like this code:

function acp_iedit_remove_wc_status_options( $data, $column ) {
	if ( $column instanceof ACA\WC\Column\ShopOrder\Status ) {
		$data = '<span>test</span>';
	}
	return $data;
}

add_filter( 'acp/editing/view_settings', 'acp_iedit_remove_wc_status_options', 10, 2 );

Still no changes. I put the Status column at the Products page. Does this make any difference?

Thanks

4 years, 7 months ago
Stefan van den Dungen Gronovius
Developer

The check is for the Status column available on the Order overview page.
Which version of WooCommerce are you using?
I remember that there was an older status column in a WooCommerce version below 3.3 (if I’m correct).
So I believe the snippet only works for WooCommerce 3.3+
The change you made should give an error, as the $data cannot be a string but has to follow the structure our Editing plugin needs. Since you don’t get any error, I suspect that it does not pass the conditional, meaning you’re probably using the older or another status column.

4 years, 7 months ago
patio

At the Shop Order page this works, but the Status Column is at the Products page.

See the screencast below to see where I add the column:

https://recordit.co/WbGsrvu8NH

I need to select this column to work. How to do this?

And I have the last Woocommerce 3.7.0

4 years, 7 months ago
patio

Ok, I figured it out.

Perhaps there’s another way, but this worked it out for me.

function acp_iedit_remove_wc_status_options( $data, $column ) {
		    if ( 'Status' === $column->get_label()) {
				$user = wp_get_current_user();
		    if ( in_array( 'administrator', $user->roles ) ) {
			        unset( $data['options']['draft'] );
				unset( $data['options']['private'] );
				unset( $data['options']['in-progress'] );
				unset( $data['options']['failed'] );
		}
}
	return $data;
}

add_filter( 'acp/editing/view_settings', 'acp_iedit_remove_wc_status_options', 10, 2 );

I didn’t test any other select, like get_name, or get_type, but the Column seems to be a CustomField.

4 years, 7 months ago
Stefan van den Dungen Gronovius
Developer

Yes, that will work. But only if you really check for the label === ‘Status’.
Once you change the label for that column, it will not work anymore.
If you want a specific column check, you can use the following conditional.

if ( $column instanceof \ACP\Column\Post\Status )

4 years, 6 months ago

You must be logged in to reply to this topic.