loading checkout page using ajax not showing payment methods for guest users
-
Following this answer on how to dynamically load checkout page using ajax in Woocommerce.
when using this js/php code to get the checkout page fragment
1.If im logged in it works fine and the defined payment methods (Paypal, bank transfer, checks) are showing up (OK)
2.for guest users, im getting the error: “Sorry, it seems that there are no available payment methods for your state”
add_action( 'wp_ajax_getCheckoutPageContent', 'getCheckoutPageContentCallBack' ); add_action( 'wp_ajax_nopriv_getCheckoutPageContent', 'getCheckoutPageContentCallBack' ); function getCheckoutPageContentCallBack() { define( 'WOOCOMMERCE_CHECKOUT', true ); echo do_shortcode('[woocommerce_checkout]'); die(); } /* JS Code to be called on callback*/ var wp_ajax_url="https://yourwebsite/wp-admin/admin-ajax.php"; var data = { action: 'getCheckoutPageContent' }; jQuery.post( wp_ajax_url, data, function(content) { // append content to my custom one page checkout });
i tried to add this filter
add_filter('woocommerce_countries_base_country', 'set_base_to_usercountry', 1, 1); // and this is used for shipping: add_filter('woocommerce_customer_default_location', 'set_base_to_usercountry', 1, 1); function set_base_to_usercountry($country) { $country = MYCOUNTRYCODE; return $country; }
but this didnt help. Any ideas how to fix this ? Thank you
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘loading checkout page using ajax not showing payment methods for guest users’ is closed to new replies.