Eric Groft
Eric Groft

Reputation: 21

WooCommerce ShipStation extention using billing address instead of shipping address

When using the ShipStation plugin extension for WooCommerce on WordPress, I ran into a problem where the address would be exported to ShipStation using the billing address instead of the default address (in my case the shipping address) from the WooCommerce settings.

Things I tried:

I was unable to find a proper solution when talking with Automatic support which suggested the normal course of disabling theme and plugin conflicts by disabling them and using Twenty-Seventeen as the theme.

No fault of theirs. Just normal need to check the basics. Given the lack of exposure for the eventual solution I thought I'd post my problem here as was a solution in the answers section - hoping that isn't some sort of a violation of policy for Stack Overflow. Answer follows:

Upvotes: 1

Views: 393

Answers (1)

Eric Groft
Eric Groft

Reputation: 21

What I found was that the plugin checks to see if there is a shipping country set for the user before deciding to send an address to Ship Station. This is often OK, but in my case, the countries were removed from the checkout form so that they were never set for the checkout customer. This meant the check would fail when the ShipStation was staging data for export to ShipStation.

My work around was to set the shipping and billing country to 'US' ( the country of origin for my client) when they were null or not defined before any data was exported to ShipStation. Since there did not appear to be any filter defined to make this alteration as the export occurred, I attached this update to another process that our client would run before each shipment day.

foreach ($users as $user=>$value) {
  $this_user = get_user_by('id',$user);
  if ($this_user->billing_country == null){
   update_user_meta($this_user->ID,'billing_country','US');
  }elseif (!$this_user->billing_country) {
    add_user_meta($this_user->ID,'billing_country','US');
  }
  if ($this_user->shipping_country == null){
    update_user_meta($this_user->ID,'shipping_country','US');
  }elseif (!$this_user->shipping_country) {
   add_user_meta($this_user->ID,'shipping_country','US');
  }
}

this updated the meta dataeach time the fulfillment reports were run so that there was always both a billing and shipping country.

This worked for my situation, but is a bit ineligant. I'm open to other approaches if this problem is common enough to warrant slicker alternatives.

Upvotes: 1

Related Questions