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:
- Checked endpoints in WooCommerce -> Settings -> Advanced
- Created new checkout page and deleted old
- Checked Chrome DevTools Console for JS errors
- Turned off all plugins except for WooCommerce. Issue still exists.
- Checked it on another test-site with Storefront theme. Everything works.
- Checked all default Woocommerce hooks in my custom checkout templates. There are available.
- Create
web.config
file in site's directory with code which provides on https://woocommerce.com/document/woocommerce-endpoints-2-1/ - 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