简体   繁体   中英

How to whitelist the order-received page in wordpress using the force-login plugin

I am using the plugin force login: https://en-gb.wordpress.org/plugins/wp-force-login/ and need to allow guests to get to the order received page after purchasing.

After checking out, a user which is logged in would be forwarded to this page: [mydomain]/checkout/order-received/[order_id]/?key=[order_key]. I have tried this: Show customer details on WooCommerce Thankyou page even if not registered but could not figure out what to do after I added it.

I currently have this code which allows certain pages to be whitelisted so users that are not logged in can bypass the "force-login" plugin and pay for the relevant product:

add_filter('v_forcelogin_whitelist', 'my_forcelogin_whitelist', 10, 1);
    function my_forcelogin_whitelist() {
        return array(
            home_url( '/cart/' ),
            home_url( '/checkout/' ),
            home_url( '/cart/?add-to-cart=1465' ),
        );
    }

I want none logged in users to be forwarded to a page which looks like this after checkout:

[mydomain]/checkout/order-received/5304/?key=wc_order_5cffcfbc96028

For anyone that has this problem this is how I got it working. Since some of the URL's generated are dynamic I needed a work around for those. Using the following code in function.php works for ALL URL's assiciated with woocommerce:

function my_forcelogin_bypass( $bypass ) {
  if ( class_exists( 'WooCommerce' ) ) {
    if ( is_woocommerce() || is_wc_endpoint_url() ) {
      $bypass = true;
    }
  }
  return $bypass;
}
add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass' );

WooCommerce Checkout/order-received issue

For the problem of [mydomain]/checkout/order-received/[order_id]/?key=[order_key] it is not loading right or is not showing something or 500 Internal Server Error ?

For Temporary purpose because whenever the plugin will be updated the file will be updated in a woo-commerce plugin?

  1. Open File Zilla
  2. The Visit : /var/www/html/wp-content/plugins/woocommerce/includes directory
  3. Then in the directory open : class-wc-order.php
  4. Find this with ctrl+F : get_checkout_order_received_url()
  5. There Will be two lines of code(Earlier) :

     $order_received_url = wc_get_endpoint_url( 'order-received', $this->get_id(), wc_get_checkout_url() ); $order_received_url = add_query_arg( 'key', $this->get_order_key(), $order_received_url );
  6. Change to(Updated) Add a comment in the second line :

     $order_received_url = wc_get_endpoint_url( 'order-received', $this->get_id(), wc_get_checkout_url() ); //$order_received_url = add_query_arg( 'key', $this->get_order_key(), $order_received_url );
  7. Save it and update it to the server.
  8. You issue will be resolved, but it's for temporary it will be changes whenever the woocommerce plugin will be updated, so you have to update it again.

Thanks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM