function b2b_redirect_if_product_is_not_for_user() { if ( is_product() ) { $allowed_user = get_post_meta( get_the_ID(), '_allowed_user', true ); if ( $allowed_user != get_current_user_id() ) { wp_redirect( site_url( '/shop' ), 301 ); } } } add_action('template_redirect', 'b2b_redirect_if_product_is_not_for_user');
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter