Home > Blockchain >  Endpoints not working on WooCommerce checkout page
Endpoints not working on WooCommerce checkout page

Time:01-17

I developing a custom theme. I have an issue on checkout page. When I click on 'Place order' button the URL of checkout page changing from http://localhost/sitename/checkout to look like http://localhost/sitename/checkout/order-received/390/?key=wc_order_DvIkeeaIUoNFI if payment-method is 'Cash on delivery' or http://localhost/sitename/checkout/order-pay/391/?key=wc_order_2TbWibkoOZcxz&order=391 if I choose Internet acquiring payment-method. But on that pages displayed content of checkout page. I think that endpoints don't work.

Here is what I did to fix that issue:

  1. Checked endpoints in WooCommerce -> Settings -> Advanced
  2. Created new checkout page and deleted old
  3. Checked Chrome DevTools Console for JS errors
  4. Turned off all plugins except for WooCommerce. Issue still exists.
  5. Checked it on another test-site with Storefront theme. Everything works.
  6. Checked all default Woocommerce hooks in my custom checkout templates. There are available.
  7. Create web.configfile in site's directory with code which provides on https://woocommerce.com/document/woocommerce-endpoints-2-1/
  8. Trying to redirect with this code:

<?php

add_action( 'template_redirect', 'woo_custom_redirect_after_purchase' );
function woo_custom_redirect_after_purchase() {
    global $wp;
    if ( is_checkout() && !empty( $wp->query_vars['order-received'] ) ) {
        
        wp_redirect( home_url('/thank-you') );
        exit;
    }

    if ( is_checkout() && !empty( $wp->query_vars['order-pay'] ) ) {
        
        wp_redirect( 'https://secure.wayforpay.com/pay' );
        exit;
    }
}

?>

As for me it's bad solution. Because if payment-method is 'Cash on delivery' on thank you page it is not possible to get order data, and if method is 'Internet acquiring' I need to get and transfer order data to acquiring system, but I have a plugin which should do it without my participation. And plugin working on another test-site.

This issue is very popular among junior Wordpress-developers, but there is few information about solving this problem. I think that endpoints works incorrect, but I don't know how to fix it. I will be very grateful if you share your own experience in solving the problem or tell me what to look for.

Updated

In addition I compared requests and responds in Chrome->DevTools->Network between site with Storefront theme and my site. They are the same, but on my site the redirect is not happening.

CodePudding user response:

I fixed it. Main issue consist in that my woocommerce doesn't do shortcodes from Console->Pages, so I activated checkout template via page-checkout.php where I get template part form-checkout.php (get_template_part( 'woocommerce/checkout/form-checkout' );). To fix a bug I replaced this string with echo do_shortcode(['woocommerce_checkout']);. Very simple solution that I spent almost 3 days searching for, but even better I learned how wordpress works

  • Related