• Resolved LS

    (@lsterling03)


    I am using your plugin, and the Restriction metabox appears on the Woocommerce Product custom post type. However, when I block the product, it isn’t blocked. I can still visit the product post while not logged in.

    Blocking works on all my other post types. Is there something else I need to do to restrict the product post type?

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter LS

    (@lsterling03)

    Update: I have tried this: https://rocketgeek.com/plugins/wp-members/docs/api-functions/wpmem_redirect_to_login/

    But the wpmem_redirect_to_login() function only works when I’m logged in. Do you know how that would be possible? When I test it in an incognito window as a logged-out user, with no caching plugins activated, it simply ignores this redirect function:

    function woo_template_redirect(){
        if( is_product())  ) {  
            // echo 'test';
    	wpmem_redirect_to_login();
        }
    }
    add_action( 'template_redirect', 'woo_template_redirect' );

    I have confirmed that a login page has been set in the WP-Members Settings page. I also tried adding a priority to the add_action, like 99 or 50 or 10… no change.

    However, it DOES work if I use the native wp_redirect() function like this:

    function woo_template_redirect(){
        if( is_product())  ) {  
    	$redirect_page = get_site_url(null, '/login/', 'https');
    	wp_redirect( $redirect_page );
            exit();
        }
    }
    add_action( 'template_redirect', 'woo_template_redirect' );

    Do you know why it may not work? Thanks!

    • This reply was modified 3 years, 5 months ago by LS.
    • This reply was modified 3 years, 5 months ago by LS.
    Plugin Author Chad Butler

    (@cbutlerjr)

    You can’t use the standard block setting on a post type that uses content outside the standard WP loop (such as WooCommerce) or for content that is comprised of post meta. In those cases, your two primary options are to either mark the post as hidden or use the redirect to login.

    The issue you’re having with the redirect to login is probably that you do not have a login page set in the plugin’s settings. You need to actually have a login page to redirect to, and then have that set in the plugin’s settings.

    Thread Starter LS

    (@lsterling03)

    Thank you for your reply. I did have a Login page in the WP-Members settings, but I was using the Woocommerce My Account page as the login page, which I had added the wpmem_profile shortcode to. For some reason, wpmem_redirect_to_login() didn’t work with that.

    I created a new page just for login, and now that redirect function works.

    Thanks!

    • This reply was modified 3 years, 5 months ago by LS.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Block Woocommerce Product’ is closed to new replies.