I’m having hard time debugging an issue with Woocommerce-powered site. When I checkout, fill in all the order fields, click on Place Order button and then there is an AJAX request to
https://www.shop.com/wp-admin/admin-ajax.php
which responds with success JSON:
{"result":"success","redirect":"https://www.shop.com/checkout/pay/?key=order_50b9f4b86e75f&order=4491"}
And then the browser actually goes to https://www.shop.com/checkout/pay/?key=order_50b9f4b86e75f&order=4491 but the problem is that on this request it gets redirected back (302 redirect via headers) to /checkout without /pay, and all fields are empty. But it used to redirect to default payment gateway of woocommerce which is paypal in my case. The order is actually placed and visible in admin, but user is never directed to paypal for payment.
This appeared when I switched from apache to nginx server.
Here is my nginx config for this site:
server {
listen 80;
server_name shop.com www.shop.com;
root /var/www/shop;
index index.php;
error_log /var/log/nginx/shop_error.log notice;
rewrite_log on;
location / {
try_files $uri $uri/ /index.php;
}
location ~* .(?:ico|css|js|gif|jp?g|png) {
expires 100d;
}
location ~ .php$ {
include fastcgi_params;
fastcgi_pass localhost:9000;
}
# include /var/www/shop/nginx.conf;
location = /wp-config.php {
deny all;
}
}
server {
listen 443;
server_name shop.com www.shop.com;
error_log /var/log/nginx/shop_error.log notice;
rewrite_log on;
root /var/www/shop;
index index.php;
ssl on;
ssl_certificate /etc/nginx/sslchain.crt;
ssl_certificate_key /etc/nginx/server.key;
ssl_client_certificate /etc/nginx/cert.ca-bundle;
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
ssl_prefer_server_ciphers on;
location / {
try_files $uri $uri/ /index.php;
}
#include /var/www/shop/nginx.conf;
location ~* .(?:ico|css|js|gif|jp?g|png) {
expires 100d;
}
location ~ .php$ {
include fastcgi_params;
fastcgi_pass localhost:9000;
}
location = /wp-config.php {
deny all;
}
}
I looked at nginx rewrite log and it correctly redirects /checkout/pay request to WP index.php, at least I think that this is correct.
Now I’m not asking anyone to point me to exact problem. Even though I’d appreciate that, but I’m trying to figure out woocommerce rewrite rules and where the script which handles /checkout/pay is and I’ll try to debug it myself before the redirect to /checkout to understand why it redirects.
The “pay” page has only Woocommerce shortcode it in [woocommerce_pay] and its URL seems to
be right: “/checkout/pay/”
I tried to place a debug dump in functions in shortcodes/shortcode-pay.php and nothing happens, so it gets redirected before that?
Any cache plugins are turned off now. Here is the list of all active plugins at the moment:
akismet
debug-bar
gravityforms
secure-wordpress
tinymce-advanced
vslider
woocommerce
woocommerce-compare-products
woocommerce-custom-product-tabs-lite
woocommerce-debug-bar
woocommerce-delivery-notes
woocommerce-fedex
woocommerce-gateway-paypal-advanced
woocommerce-gravityforms-product-addons
woocommerce-product-bundles
woocommerce-usps
woocommerce-USPS
woodojo
woodojo-downloads
woosidebars
wordpress-importer
wordpress-seo
wp-dbmanager
I found the error myself, it was wrong config of nginx rewrite rules. Specifically, I think I got
But it should have been like here in “Abridged basic setup” section