admin管理员组

文章数量:1289874

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"

/* PHP Code on functions.php */
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="http://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

// this is used for taxing:
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

本文标签: WooCommercedynamically loading checkout page using ajax not showing payment methods for guest