Support » Plugin: Paid Memberships Pro » Redirect to woocommerce cart page

  • Resolved fabianski


    I am using this custom code to redirect, when a user clicks the subscription button, from the pmpro checkout to the woocommerce checkout.
    But I wanted to instead of redirect to the checkout directly, the product was just added to the cart.
    Can someone with knowledge edit this code for this?
    Thank you!

    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']));
            $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);  
              // if no products in cart, add it
              WC()->cart->add_to_cart( $product_id );
              wp_redirect( $checkout_url);  
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Jason Coleman


    Note these lines in your code:

    wp_redirect( $checkout_url);

    You can comment those out or remove them to stop the redirect behavior.

    Hi, Jason!
    Thanks for the answer.

    I removed these lines but now I’m not being redirected to any page, I’m on a totally white page.
    My intention was to be redirected to the wagon of woocommerce.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.