• Resolved urka

    (@urka)


    We use our woocommerce shop for private customers and also for our dealers who gets discount depending on which role they have been assigned – works great.
    Now we would have some products we want offer only to our dealers. We thought this would be no problem because of toe option “Content permissions” in our woocommerce product page administration but it does not work. If we select a role there, the product will still be displayed to everyone.
    We use TheGem theme if this plays a role. Please can anybody help?
    We found script for hide ID’s (not tested) but would be nice to use the plugin if there is already a function for it.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Omar ElHawary

    (@omarelhawary)

    Hi @urka.

    Thanks for raching out Members Support Team!

    The Members plugin is related to Roles, not show/hide products. You can check this plugin for show/hide products based on user role.

    Regards,

    Thread Starter urka

    (@urka)

    I am a little bit confused because I did not have installed plugin you recommend but I have this option on each page for do special permissions. Isn’t this a part of plugin “Members” ?
    Screenshot

    Regards

    Plugin Support Omar ElHawary

    (@omarelhawary)

    Hi @urka,

    The Members plugin doesn’t fully protect a product on the frontend. It currently only protects post content. WooCommerce templates show post content (which is protected), but it shows a lot more, such as price, short description, etc., which is usually post meta.
    That being said, here’s a snippet that will redirect logged-in users when they don’t have a required role and the product has sneakers or backpacks categories:

    add_filter( 'woocommerce_product_is_visible', 'members_maybe_remove_product_from_query', 95, 2 );
    /**
    * Removes a product from the query depending on if the user has the correct permission.
    *
    * @param boolean $is_visible Whether the product is visible
    * @param int $product_id Product ID
    *
    * @return boolean
    */
    function members_maybe_remove_product_from_query( $is_visible, $product_id ) {
    return members_can_current_user_view_post( $product_id );
    }
    add_action( 'template_redirect', 'members_woocommerce_product_redirect' );
    function members_woocommerce_product_redirect() {
    if ( class_exists( 'WooCommerce' ) && is_singular( 'product' ) ) {
    $user = wp_get_current_user();
    $post_id = get_the_ID();
    //replace role author
    if( ! empty($user) && in_array( 'author', (array) $user->roles ) && has_term( array( 'sneakers', 'backpacks' ), 'product_cat', $post_id ) ) {
    wp_redirect( apply_filters( 'members_woocommerce_product_redirect', get_permalink( wc_get_page_id( 'shop' ) ) ) );
    exit;
    }
    }
    }

    If you want to use it for particular product, you’ll need to modify has_term part in the condition above.

    I hope that helps.

    Thread Starter urka

    (@urka)

    Unfortunately your recommended plugin does not work with new woocommerce because it is incompatible with WooCommerce feature ‘High-Performance Order Storage (HPOS)’ and there was no update in the last 9 months 🙁

    Plugin Support Omar ElHawary

    (@omarelhawary)

    Hi @urka,

    I already added feature request to protect products in Members plugin. But in the mean time, we don’t have any option to protect WooCommerce products.

    Regards,

    Thread Starter urka

    (@urka)

    Thank you. Would be nice to have all function in one plugin.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Content permission does not work’ is closed to new replies.