WordPress at Your Fingertips
function is not described

WC_Shipping_Zone::add_shipping_method() public WC 1.0

Add a shipping method to this zone.

{} It's a method of the class: WC_Shipping_Zone{}

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.

Code of WC_Shipping_Zone::add_shipping_method() WC 5.7.0

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;
}