Restrict Access to Wordpress Pages until WooCommerce Product Purchased - Free Code Snippets Cloud
HTML-код
- Опубликовано: 12 сен 2024
- Join our 'How to Start a Web Design Business' Course - and use strategies to grow, get clients, and generate recurring income: websquadron.co...
Book your 1-2-1 Consultation: websquadron.co...
Code: www.codesnippe...
Restrict Access to Wordpress Pages until WooCommerce Product Purchased - Free Code Snippets Cloud
We love to create - share - respond - and deliver.
🧐 Learn with our Mastery Modules: websquadron.co...
🔗 All of our Important Links: websquadron.co...
😃 Join our Facebook Group: / 3309523509284305
😃 Get Code Snippets Pro: r.freemius.com...
😃 Get Elementor Pro: be.elementor.c...
😃 Boost your RUclips Analysis: www.tubebuddy....
👕 Get our Merchandise: websquadron.co...
🥹 Support us: paypal.me/Webs...
Hire us to work on your Website!
💌 info@websquadron.co.uk
👩💻 Visit websquadron.co.uk
As always Imran, great info!
Would this work on the Ultimate Member plugin, giving the user access to all the member profiles? Or would I have to enter the code for each profile page individually? TIA
Wicked, thats the Product Dependancies plugin deactivated and deleted!!
Nice thanks Imran
Hi, awesome video, a quick question, there are 3 codes, which do almost the same thing, do we need to use all 3 of them?
No just use what you need
This is a great upgrade of a similar video you made that replaced the Thank you page for the one you want depending on the product bought but it was public.
So, the client would need to create an account in order to access in the future, right? And if they are in their dashboard where they can see their orders do you find any way for them to be redirected into this page that was created for this specific product?
Thanks as always for sharing.
A note could be added to the WooCommerce Product (inside the Product Details bit) that contains the URL for where they access the content.
@@websquadron that's a good idea! The client would need to create an account to access the content, right?
Would you use a free LMS all-in-one for Elementor if there is one on the market?
Maybe... but I'd want to be sure about what was free and what required a premium version.
Does this also work with Woo Subscriptions or any other subscriptions plugin?
Nope.
@@websquadron ok, thanks for your reply
nice
🙌🙌
@websquadron Ive got one question in my head...
If I have locked down the Page, which needs to be purchased - is also the content locked?
For eg if I sell an onlinecokrse / video / image or what so ever it should not be possible to directly access via the link although the page is locked.
Is there any solution?
Your video is amazing!
You can use Woo settings to make the download link change each time.
@@websquadron I want to use your solution as a course site.
I meant how to protect direct access to video / images via the file link. Or is this also locked because of the the locked course site?
@@yismedia Depends on how you feed the video. So I feed it via Muse.AI that stops external access unless it is through the page.
I have a question, if you go to restricted page you get redirected to login page right, after you logged in do you get redirect to the restricted again at the end ?
Yes you can set it up to take them to your designated page after login
@websquadron Thanks, pardon me Is it in the codes ?? or I have to write a code for it, I didn't look careful to it
@@mahan_cm_8 I’ll double check in the morning as I’m sure it’s set somewhere
Hi Imran, what if I want to lock several pages (more around 50) to one product? Would it be doable?
Yes, just keep selecting the product for those pages
Not sure I understand. I just want to lock a number of pages to a single product in Woo. Should I copy paste what you did with the 'layout' page for each page that I want to lock? And is the part about the 'test' page in your tutorial not relevant for me since I am only locking the pages to a single product? And if so, should I exclude that part of the code? Thanks! @@websquadron
Would this modification for example work if I replace the slugs, product id and redirect page?
function restrict_page_access() {
// Get the current user ID
$user_id = get_current_user_id();
// Check if the user is an administrator
$is_admin = current_user_can('administrator');
if ($is_admin) {
return; // If admin, let them access any page
}
// Define a list of pages that require the product to be purchased
$restricted_pages = array('layout', 'test', 'another_page_slug'); // Add more page slugs to this array as needed
// Product ID that is required for access
$required_product_id = 297;
// Get the current page
$current_page = get_queried_object();
// If the current page is in our restricted list
if (in_array($current_page->post_name, $restricted_pages)) {
// Check if the user has purchased the required product
$has_purchased = wc_customer_bought_product($user_id, $user_id, $required_product_id);
if (!$has_purchased) {
// Redirect the user to the shop if they haven't purchased the required product
wp_redirect('website.websquadron.co.uk/shop');
exit;
}
}
}
add_action('template_redirect', 'restrict_page_access');
I thought you liked Page Restrict for WooCommerce
I do :)
But this is an option if you want to reduce the plugins