Ecommerce Shopify WordPress Discussion

How to call Woocommerce custom shipping class calculate_shipping method using AJAX?

Based on WooCommerce Documentation - Shipping Method API tutorial, I have built a WooCommerce shipping plugin. This is a simplified version: if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { function your_shipping_method_init() { if ( ! class_exists( 'WC_Your_Shipping_Method' ) ) { class WC_Your_Shipping_Method extends WC_Shipping_Method { /** * Constructor for your shipping class * * @access public * @return void */ public function __construct() { // constructor stuff goes here } public function calculate_shipping( $package = array() ) { $rate = array( 'label' => $this->title, 'cost' => '10.99', 'calc_tax' => 'per_item' ); // Register the rate $this->add_rate( $rate ); } } } } add_action( 'woocommerce_shipping_init', 'your_shipping_method_init' ); function add_your_shipping_method( $methods ) { $methods['your_shipping_method'] = 'WC_Your_Shipping_Method'; return $methods; } add_filter( 'woocommerce_shipping_methods', 'add_your_shipping_method' ); } I want to call the calculate_shipping method when the user changes the option in a Select field. I am trying to call the calculate_shipping method using AJAX. This is currently returning a 400 error. (I also tried 'WC_Your_Shipping_Method->call_calculate_shipping'). <script type='text/javascript'> jQuery(document).ready(function() { jQuery('select[name="shipping_delivery_method"]').change(function () { jQuery.ajax({ type: "POST", url: 'https://garpenstaging.wpenginepowered.com/wp-admin/admin-ajax.php', data: { action: 'WC_Your_Shipping_Method::call_calculate_shipping', }, success: function (output) { console.log(output); }, error: function(error) { console.log(error); } }); }); }); </script>
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.