Using Woocommerce Checkout Page With PmPro membership.

Introduction: 

In this tutorial we will learn how to use woocommerce checkout page with PmPro memberships. This is usefull to the users who do not want to use PmPro checkout page and instead use woocommerce checkout page even for memberships.

Steps to do:

  • First please download this free plugin: Paid Memberships Pro – WooCommerce Add On, (its assumed that the PmPro plugin is already installed).
  • Now upload the plugin on the website and activate the plugin.
  • Now add this code in your function.php file (child theme), if not using a child theme then add the below code in your wplms-customizer.php file present in your wplms customizer plugin:
    add_action('template_redirect','pmpro_woocommerce_redirect_checkout');
    function pmpro_woocommerce_redirect_checkout(){
      $id = get_option('pmpro_checkout_page_id');
      global $post;
      if($post->ID == $id && !empty($_REQUEST['level'])){
        global $wpdb;
        $product_id = $wpdb->get_var($wpdb->prepare("SELECT pm.post_id FROM {$wpdb->postmeta} as pm LEFT JOIN {$wpdb->posts} as p ON p.ID=pm.post_id WHERE pm.meta_key = %s AND pm.meta_value = %d AND p.post_status='publish'",'_membership_product_level',$_REQUEST['level']));
        if(!empty($product_id)){
            $checkout_url = WC()->cart->get_checkout_url();
            if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
              foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
                $_product = $values['data'];
                if ( $_product->id == $product_id )
                    $found = true;
              }
              // if product not found, add it
              if ( ! $found )
                WC()->cart->add_to_cart( $product_id );
              wp_redirect( $checkout_url);  
            }else{
              // if no products in cart, add it
              WC()->cart->add_to_cart( $product_id );
              wp_redirect( $checkout_url);  
            }
            exit();
        }
        
      }
    }
    
  • Now go to wp-admin->products->add new and create a new product with the name of the membership, like if you have a membership named as gold then create a product gold membership and select it in the membership setting, refer: http://prntscr.com/bndpxx and publish the product.
  • similarly create one product for each membership you have created and make sure its not mandatory to connect any course to these products.
  • Now use the PmPro plugin normally and connect the memberships to the courses instead of the products.
  • When the user clicks on take this course button she will be redirected to the membership page.
  • When the user selects a membership then she will be redirected to the woocommerce checkout page to the corresponding membership product.
  • Once the product is purchased, the user will get the access to the course.

 

NOTE:  You have to create only one product for each membership, you cannot connect same membership with different products.

 

Please refer the video on this:

Leave a Reply

Your email address will not be published. Required fields are marked *