[Plugin: WooCommerce] when change shipping method, payment fee remains
-
Hi,
the problem is, when i choose shipping method with an extra payment fee and then, when i change it do the one that hasn’t payment method the choosed before one has, the “old” payment method fee remains, although automaticly new payment (with different fee) was selected.
When i change payment method the FireBug shows me error:
ReferenceError: $fragment_refresh is not defined
$.ajax( $fragment_refresh );Automaticly changing payment doesn’t show this error.
I’m tring to resolve this problem more than a week and can’t find any solution… I’ve already tried to play with woocommerce core code, adding some hooks to functions.php but every “solution” to the problem of “update cart on changing shipping/payment method” didn’t work.
All shipping methods are custom. I’ve made plugin with them using local delivery as an example.
<?php /** * Check if WooCommerce is active */ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { function ata_shipping_method_init() { if ( ! class_exists( 'WC_Shipping_Paczkomatyinpost' ) ) { class WC_Shipping_Paczkomatyinpost extends WC_Shipping_Method { /** * Constructor */ public function __construct() { $this->id = 'paczkomatyinpost'; $this->method_title = __( 'Paczkomaty InPost', 'woocommerce' ); $this->init(); } /** * init function. */ public function init() { // Load the settings. $this->init_form_fields(); $this->init_settings(); // Define user set variables $this->title = $this->get_option( 'title' ); $this->type = $this->get_option( 'type' ); $this->fee = $this->get_option( 'fee' ); $this->free = $this->get_option( 'free' ); add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) ); } /** * calculate_shipping function. * * @param array $package (default: array()) */ public function calculate_shipping( $package = array() ) { $shipping_total = 0; $total = WC()->cart->cart_contents_total; if($total >= $this->free) { $shipping_total = 0; } else { $shipping_total = $this->fee; } $rate = array( 'id' => $this->id, 'label' => $this->title, 'cost' => $shipping_total ); $this->add_rate( $rate ); } /** * Init form fields. */ public function init_form_fields() { $this->form_fields = array( 'enabled' => array( 'title' => __( 'W??cz', 'woocommerce' ), 'type' => 'checkbox', 'label' => __( 'W??cz Paczkomaty InPost', 'woocommerce' ), 'default' => 'no' ), 'title' => array( 'title' => __( 'Tytu?', 'woocommerce' ), 'type' => 'text', 'description' => __( '', 'woocommerce' ), 'default' => __( 'Paczkomaty InPost', 'woocommerce' ), 'desc_tip' => false, ), 'fee' => array( 'title' => __( 'Koszt dostawy', 'woocommerce' ), 'type' => 'price', 'description' => __( '', 'woocommerce' ), 'default' => '0', 'desc_tip' => true, 'placeholder' => wc_format_localized_price( 0 ) ), 'free' => array( 'title' => __( 'Darmowa wysy?ka od kwoty', 'woocommerce' ), 'type' => 'price', 'description' => __( '', 'woocommerce' ), 'default' => '0', 'desc_tip' => true, 'placeholder' => wc_format_localized_price( 0 ) ) ); } } } if ( ! class_exists( 'WC_Shipping_Kurier48' ) ) { class WC_Shipping_Kurier48 extends WC_Shipping_Method { /** * Constructor */ public function __construct() { $this->id = 'kurier48'; $this->method_title = __( 'Kurier48', 'woocommerce' ); $this->init(); } /** * init function. */ public function init() { // Load the settings. $this->init_form_fields(); $this->init_settings(); // Define user set variables $this->title = $this->get_option( 'title' ); $this->type = $this->get_option( 'type' ); $this->fee = $this->get_option( 'fee' ); $this->free = $this->get_option( 'free' ); add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) ); } /** * calculate_shipping function. * * @param array $package (default: array()) */ public function calculate_shipping( $package = array() ) { $shipping_total = 0; $total = WC()->cart->cart_contents_total; if($total >= $this->free) { $shipping_total = 0; } else { $shipping_total = $this->fee; } $rate = array( 'id' => $this->id, 'label' => $this->title, 'cost' => $shipping_total ); $this->add_rate( $rate ); } /** * Init form fields. */ public function init_form_fields() { $this->form_fields = array( 'enabled' => array( 'title' => __( 'W??cz', 'woocommerce' ), 'type' => 'checkbox', 'label' => __( 'W??cz Kurier48 Poczta Polska', 'woocommerce' ), 'default' => 'no' ), 'title' => array( 'title' => __( 'Tytu?', 'woocommerce' ), 'type' => 'text', 'description' => __( '', 'woocommerce' ), 'default' => __( 'Kurier48 Poczta Polska', 'woocommerce' ), 'desc_tip' => false, ), 'fee' => array( 'title' => __( 'Koszt dostawy', 'woocommerce' ), 'type' => 'price', 'description' => __( '', 'woocommerce' ), 'default' => '0', 'desc_tip' => true, 'placeholder' => wc_format_localized_price( 0 ) ), 'free' => array( 'title' => __( 'Darmowa wysy?ka od kwoty', 'woocommerce' ), 'type' => 'price', 'description' => __( '', 'woocommerce' ), 'default' => '0', 'desc_tip' => true, 'placeholder' => wc_format_localized_price( 0 ) ) ); } } } if ( ! class_exists( 'WC_Shipping_Poleconyinpost' ) ) { class WC_Shipping_Poleconyinpost extends WC_Shipping_Method { /** * Constructor */ public function __construct() { $this->id = 'poleconyinpost'; $this->method_title = __( 'Polecony InPost', 'woocommerce' ); $this->init(); } /** * init function. */ public function init() { // Load the settings. $this->init_form_fields(); $this->init_settings(); // Define user set variables $this->title = $this->get_option( 'title' ); $this->type = $this->get_option( 'type' ); $this->fee = $this->get_option( 'fee' ); $this->free = $this->get_option( 'free' ); add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) ); } /** * calculate_shipping function. * * @param array $package (default: array()) */ public function calculate_shipping( $package = array() ) { $shipping_total = 0; $total = WC()->cart->cart_contents_total; if($total >= $this->free) { $shipping_total = 0; } else { $shipping_total = $this->fee; } $rate = array( 'id' => $this->id, 'label' => $this->title, 'cost' => $shipping_total ); $this->add_rate( $rate ); } /** * Init form fields. */ public function init_form_fields() { $this->form_fields = array( 'enabled' => array( 'title' => __( 'W??cz', 'woocommerce' ), 'type' => 'checkbox', 'label' => __( 'W??cz Polecony InPost', 'woocommerce' ), 'default' => 'no' ), 'title' => array( 'title' => __( 'Tytu?', 'woocommerce' ), 'type' => 'text', 'description' => __( '', 'woocommerce' ), 'default' => __( 'Polecony InPost', 'woocommerce' ), 'desc_tip' => false, ), 'fee' => array( 'title' => __( 'Koszt dostawy', 'woocommerce' ), 'type' => 'price', 'description' => __( '', 'woocommerce' ), 'default' => '0', 'desc_tip' => true, 'placeholder' => wc_format_localized_price( 0 ) ), 'free' => array( 'title' => __( 'Darmowa wysy?ka od kwoty', 'woocommerce' ), 'type' => 'price', 'description' => __( '', 'woocommerce' ), 'default' => '0', 'desc_tip' => true, 'placeholder' => wc_format_localized_price( 0 ) ) ); } } } if ( ! class_exists( 'WC_Shipping_Fedex' ) ) { class WC_Shipping_Fedex extends WC_Shipping_Method { /** * Constructor */ public function __construct() { $this->id = 'fedex'; $this->method_title = __( 'Kurier FedEx', 'woocommerce' ); $this->init(); } /** * init function. */ public function init() { // Load the settings. $this->init_form_fields(); $this->init_settings(); // Define user set variables $this->title = $this->get_option( 'title' ); $this->type = $this->get_option( 'type' ); $this->fee = $this->get_option( 'fee' ); $this->free = $this->get_option( 'free' ); add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) ); } /** * calculate_shipping function. * * @param array $package (default: array()) */ public function calculate_shipping( $package = array() ) { $shipping_total = 0; $total = WC()->cart->cart_contents_total; if($total >= $this->free) { $shipping_total = 0; } else { $shipping_total = $this->fee; } $rate = array( 'id' => $this->id, 'label' => $this->title, 'cost' => $shipping_total ); $this->add_rate( $rate ); } /** * Init form fields. */ public function init_form_fields() { $this->form_fields = array( 'enabled' => array( 'title' => __( 'W??cz', 'woocommerce' ), 'type' => 'checkbox', 'label' => __( 'W??cz Kurier FedEx', 'woocommerce' ), 'default' => 'no' ), 'title' => array( 'title' => __( 'Tytu?', 'woocommerce' ), 'type' => 'text', 'description' => __( '', 'woocommerce' ), 'default' => __( 'Kurier FedEx', 'woocommerce' ), 'desc_tip' => false, ), 'fee' => array( 'title' => __( 'Koszt dostawy', 'woocommerce' ), 'type' => 'price', 'description' => __( '', 'woocommerce' ), 'default' => '0', 'desc_tip' => true, 'placeholder' => wc_format_localized_price( 0 ) ), 'free' => array( 'title' => __( 'Darmowa wysy?ka od kwoty', 'woocommerce' ), 'type' => 'price', 'description' => __( '', 'woocommerce' ), 'default' => '0', 'desc_tip' => true, 'placeholder' => wc_format_localized_price( 0 ) ) ); } } } } add_action( 'woocommerce_shipping_init', 'ata_shipping_method_init' ); function add_ata_shipping_method( $methods ) { $methods[] = 'WC_Shipping_Paczkomatyinpost'; $methods[] = 'WC_Shipping_Kurier48'; $methods[] = 'WC_Shipping_Poleconyinpost'; $methods[] = 'WC_Shipping_Fedex'; return $methods; } add_filter( 'woocommerce_shipping_methods', 'add_ata_shipping_method' ); }
I’m using:
WooCommerce 2.4.8
WooCommerce Pay for Payment 1.3.7Screenshots with my notes:
https://3.1m.yt/lOPEyQK4n.jpgWebsite with problem:
https://goo.gl/On8gQOSorry for my english, but it is not my native language ??
- The topic ‘[Plugin: WooCommerce] when change shipping method, payment fee remains’ is closed to new replies.