Answer the question
In order to leave comments, you need to log in
Guys, I need a plugin to sell video courses on wordpress, am I thinking right?
I see all kinds of plugins related to membership (membership), but I would like individual video courses to be sold as different products. This is how I understand the system: you need to make a post in which course videos will be gradually added, as they appear, this post will be closed until a person pays for access to it. In the same way, new posts with courses are created. It's just that with the membership system, it turns out that a person pays once and goes to a premium group, where all hidden sections are available to him.
Answer the question
In order to leave comments, you need to log in
Simply, assign a user role when purchasing a product or sell access itself and at the same time change the role of the person who paid, for example:
add_action( 'woocommerce_order_status_completed', 'change_role_on_pro' );
function change_role_on_pro( $order_id ) {
$order = wc_get_order( $order_id );
$items = $order->get_items();
$products_to_check = array( '3420' ); // id товара, при оплате которого меняется роль
foreach ( $items as $item ) {
if ( $order->user_id > 0 && in_array( $item['product_id'], $products_to_check ) ) {
$user = new WP_User( $order->user_id );
// заменить роль
$user->remove_role( 'customer' );
$user->remove_role( 'subscriber' );
$user->add_role( 'clientpro' );
// окончание цикла
break;
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question