Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carriers are not being initialized when editing shipping method #200

Open
luzat opened this issue Mar 29, 2021 · 5 comments
Open

Carriers are not being initialized when editing shipping method #200

luzat opened this issue Mar 29, 2021 · 5 comments

Comments

@luzat
Copy link

luzat commented Mar 29, 2021

When editing shipping methods, there are none shown:
image

The problem seems to be one of the following two, not sure which one:

  1. WC_Shipcloud_Shipping::carriers is only initialized for the settings screen in init_settings_screen and thus is not available in init_settings_fields to in turn initialize $carriers_options for use in instance_form_fields' allowed_carriers field:
  	$this->instance_form_fields = array(
  		'allowed_carriers'                  => array(
  			'title'       => __( 'Shipping methods', 'shipcloud-for-woocommerce' ),
  			'type'        => 'multi_checkbox',
  			'description' => __( 'Select the carriers that you want to use in your shop.', 'shipcloud-for-woocommerce' ),
  			'desc_tip'    => true,
  			'options'     => $carriers_options
  		),
2. Alternatively or additionally, could it be that `allowed_carriers` should actually be initialized from `available_carriers` here?

Another thing that I noticed is, that `WC_Shipcloud_Shipping::init_allowed_carriers` does not initialize anything. Isn't it meant to at least assign `allowed_carriers` to some instance variable? Instead it seems that most methods seem to do this on their own. It's at least a misnomer.
@thd-fox
Copy link

thd-fox commented Mar 30, 2021

Same here! But I face this issue, when initially enter API key on new install.

@andrecedik
Copy link
Contributor

Yes I know. We previously had this update upon entering and saving the form. Unfortunately Wordpress always loads the shipping method (multiple times), resulting in multiple calls to the API, which is unnecessary and can get people to reach their request limits. Therefore you currently have to save your settings one more time after entering the API key for them to be loaded.

@thd-fox
Copy link

thd-fox commented Mar 30, 2021

Unfortunately this "...save your settings one more time after entering the API key..." doesn't work either.

@luzat
Copy link
Author

luzat commented Mar 30, 2021

For me, the carriers do display in settings, but not when editing shipping methods, which is because $this->carriers is only initialized in this code path:

if ( wcsc_is_settings_screen() ) {
  if ( ! $this->init_settings_screen() ) {
    return false;
  }
}

Given that shipping methods are not edited on the shipcloud settings screen, $this->carriers is always going to be [].

@andrecedik
Copy link
Contributor

Hmm, ok interesting. Will have to have a look at that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants