Reply To: Override for Single Post?
April 28, 2022 at 8:56 am Reply
Support Manager
Hi Caraldine,
Since you’re using Elementor templates to create a global template for your recipes, the access rules you applied to that template will apply to every recipe post.
To get around this, I put together a code snippet for you to add to your theme’s functions.php file or a custom snippets plugin. You’ll want to modify the $free_posts
section to use the post slugs for your free recipes.
add_filter( 'elegant_modules_elementor_woo_can_view_content', 'ww_free_recipes_can_view' ); /** * Override access to specific content * * @param boolean $can_view Whether the user can view the content * * @return boolean */ function ww_free_recipes_can_view( $can_view ) { if ( is_singular( 'recipes' ) ) { // Add the recipe slugs here $free_posts = [ 'baked-oats', 'perfect-pancakes', 'apple-ginger-overnight-oats' ]; global $post; // Check if the current recipe's slug is in the list of free slugs if ( in_array( $post->post_name, $free_posts ) ) { $can_view = true; } } return $can_view; }
Please let me know if you need help with getting this set up.