Home › Forums › Legacy Support › Support queries › Setup issues › After registration
- This topic has 16 replies, 4 voices, and was last updated 4 years, 4 months ago by Anshuman Sahu.
-
AuthorPosts
-
October 17, 2019 at 6:52 pm #230507MeesterGijsSpectatorHello, Once my visitors are registered they have to pay for their membership. But if they stop after registration they can login but they can't access courses. But once logged in you still see the register button at the homepage (here) and here in the footer. Is it possible to redirect a url (meestergijs.nl/aanmelden) to meestergijs.nl/winkel for logged in visitors? Also, I thought I could use this code to change the label Add to Cart. But it does nothing. Could you help with that as well? /* Aangepaste tekst voor toevoegen aan winkelmand */ add_filter( 'woocommerce_product_single_add_to_cart_text', 'lw_cart_btn_text' ); add_filter( 'woocommerce_product_add_to_cart_text', 'lw_cart_btn_text' ); //Changing Add to Cart text to Buy Now! function lw_cart_btn_text() { return __( 'Buy Now!', 'woocommerce' ); } Thanks, GijsOctober 18, 2019 at 6:20 am #230552loganMemberhello, use this code in customizer, once user is logged in he will be redirected to the entered url automatically. add_filter('login_redirect','logan_custom_login_redirection',999,3); function logan_custom_login_redirection($redirect_url,$request_url,$user){ $url = 'http://google.com'; return $url; }October 18, 2019 at 6:47 am #230558MeesterGijsSpectatorBut I don't want paid members that login to get redirected to the shop. How can we get a redirect not from loggin in but from having paid/finished the checkout page?October 19, 2019 at 4:40 am #230649Anshuman SahuKeymasterTo change the add to cart label you can actually translate it using loco translate . To redirect based on if user bought any product use this code : add_filter('login_redirect','logan_custom_login_redirection',999,3); function logan_custom_login_redirection($redirect_url,$request_url,$user){ $bought = false; // Get all customer orders $customer_orders = get_posts( array( 'numberposts' => -1, 'meta_key' => '_customer_user', 'meta_value' => $user->ID, 'post_type' => 'shop_order', // WC orders post type 'post_status' => 'wc-completed' // Only orders with status "completed" ) ); if(!empty($customer_orders) && count($customer_orders)){ //already bought to wherever you want $url = 'https://meestergijs.nl/start/'; }else{ //to shop $url = 'https://meestergijs.nl/winkel/'; } return $url; }October 19, 2019 at 1:00 pm #230689MeesterGijsSpectatorAlex, Thanks for the code. This is what I eventually will need to use when I have more than one product.. But can I also so send registered users automatically to checkout with my only product available in their basket? See this image; Explain what you see: Users now follow black arrows. You deleted the purple box for me. But I want to go like the red arrow..October 21, 2019 at 6:52 am #230757loganMemberuse this code to redirect them directly to the checkout page: add_filter('login_redirect','logan_custom_login_redirection',999,3); function logan_custom_login_redirection($redirect_url,$request_url,$user){ $bought = false; // Get all customer orders $customer_orders = get_posts( array( 'numberposts' => -1, 'meta_key' => '_customer_user', 'meta_value' => $user->ID, 'post_type' => 'shop_order', // WC orders post type 'post_status' => 'wc-completed' // Only orders with status "completed" ) ); if(!empty($customer_orders) && count($customer_orders)){ //already bought to wherever you want $url = 'https://meestergijs.nl/start/'; }else{ //to shop $url = 'https://meestergijs.nl/checkout/'; } return $url; }October 21, 2019 at 7:56 am #230773MeesterGijsSpectatorThe code doesn't work. Is there something in the code I need to change?October 22, 2019 at 5:22 am #230879MeesterGijsSpectatorThe code gave a page not found error when logging in...October 23, 2019 at 5:24 am #231007loganMemberPlease remove the above codes then share the exact url then i will rewrite the codes.October 23, 2019 at 6:08 am #231016MeesterGijsSpectatorI deleted the code. I want them to register at meestergijs.nl/aanmelden. Then when they click the button AANMELDEN (register) at the bottom of the page, they get logged in and I want them immediately be redirected to checkout with the product in cart (product url: meestergijs.nl/product/abonnement). Checkout url is: meestergijs.nl/checkout. Is this what you mean? GijsOctober 24, 2019 at 2:39 pm #231223Anshuman SahuKeymasterWell then you can simply enable "login and register simultaneously" settings in the custom registration form. and on a common wordpress hook : " wp_login " you can add your product to cart and redirect to checkout . for which the code is this : add_action('wp_login',function ($username){ global $woocommerce; $checkout_url = $woocommerce->cart->get_checkout_url(); //check if product already in cart if ( WC()->cart->get_cart_contents_count() == 0 ) { // if no products in cart, add it WC()->cart->add_to_cart( $product_id ); } wp_redirect($checkout_url);exit(); },1);October 24, 2019 at 7:18 pm #231240MeesterGijsSpectatorThis is what happened after I added the code: videoOctober 25, 2019 at 8:05 am #231299DianaParticipantThis reply has been marked as private.October 25, 2019 at 8:52 am #231302MeesterGijsSpectatorHello, I see. Now it redirects after login. It should redirect after registration (meestergijs.nl/aanmelden). I that possible? When I already have a membership and I log in, I don't need to go to checkout. Hope you understand, GijsOctober 25, 2019 at 8:56 am #231305Anshuman SahuKeymasterSorry please remove the previous code and add this one : add_action('wp_login',function ($username){ //check if product already in cart $product_id = 45;//change the product id here if ( WC()->cart->get_cart_contents_count() == 0 ) { // if no products in cart, add it WC()->cart->add_to_cart( $product_id ); } },1); add_filter('wplms_registeration_redirect_url',function($url){ global $woocommerce; $checkout_url = $woocommerce->cart->get_checkout_url(); return $checkout_url; }); change the product id in above code.
-
AuthorPosts
- The topic ‘After registration’ is closed to new replies.