Hi @leobr, @dineshinau and @vasyltech,
I encounter a similar problem using AAM with Woocommerce extension.
Here are modifications proposals that worked for me.
@vasyltech, can you tell me if this code can produce some bugs/problems ? Especially for is_tax() call addition that may be added in the official source code ?
First step : “Plus Package Extension” allow to manage access to categories. In Woocommerce, this can be useful to hide some product categories to the user. However, Woocommerce use custom taxonomy for product category and this is not managed by AAM as “is_category” function is used to check the capability to restrict access.
We need to add a call to “is_tax” method to manage custom post types.
In plus-package/Frontend.php, line 58, replace :
if (is_category()) {
With :
if (is_category() || is_tax()) {
Second step : As @vasyltech write, Woocommerce use a “strange” method to manage the shop page that do not raise a call to AAM. This can be bypassed by checking the location of the user ton page display and manually call AAM if user is on the shop page.
Here is the code to add in a your custom functions :
function wpse_131562_redirect() {
if (is_plugin_active(“advanced-access-manager/aam.php”) &&
class_exists(‘AAM’) && class_exists(‘AAM_Frontend_Authorization’)
&& is_plugin_active(“woocommerce/woocommerce.php”) && function_exists(‘is_shop’)) {
if (is_shop()) {
$user = AAM::getUser();
$post = $user->getObject(‘post’, wc_get_page_id( ‘shop’ ));
if ($post) {
AAM_Frontend_Authorization::getInstance()->post($post);
}
}
} else {
$to = get_bloginfo(‘admin_email’);
$subject = get_bloginfo(‘name’) . ‘ : Security Breach’;
$message = ‘Advanced Access Manager/Woocommerce have been disabled or the behavior/name of its classes have been modified.
Link between AAM and Woocommerce is broken.’;
wp_mail( $to, $subject, $message );
}
}
add_action(‘template_redirect’, ‘wpse_131562_redirect’);
Note that mail sending is not mandatory. I use it to manage plugin update which would break this function behavior.
Hope this will helps,
Birmania