WC_Shipping_Zone::add_shipping_method()
Add a shipping method to this zone.
Method of the class: WC_Shipping_Zone{}
Hooks from the method
Return
Int
. new instance_id, 0 on failure
Usage
$WC_Shipping_Zone = new WC_Shipping_Zone(); $WC_Shipping_Zone->add_shipping_method( $type );
- $type(string) (required)
- shipping method type.
WC_Shipping_Zone::add_shipping_method() WC Shipping Zone::add shipping method code WC 9.4.2
public function add_shipping_method( $type ) { if ( null === $this->get_id() ) { $this->save(); } $instance_id = 0; $wc_shipping = WC_Shipping::instance(); $allowed_classes = $wc_shipping->get_shipping_method_class_names(); $count = $this->data_store->get_method_count( $this->get_id() ); if ( in_array( $type, array_keys( $allowed_classes ), true ) ) { $instance_id = $this->data_store->add_method( $this->get_id(), $type, $count + 1 ); } if ( $instance_id ) { do_action( 'woocommerce_shipping_zone_method_added', $instance_id, $type, $this->get_id() ); } WC_Cache_Helper::get_transient_version( 'shipping', true ); return $instance_id; }