WC_Settings_Shipping::zone_methods_screen()protectedWC 1.0

Show method for a zone

Method of the class: WC_Settings_Shipping{}

No Hooks.

Return

null. Nothing.

Usage

// protected - for code of main (parent) or child class
$result = $this->zone_methods_screen( $zone_id );
$zone_id(int) (required)
Zone ID.

WC_Settings_Shipping::zone_methods_screen() code WC 7.5.1

protected function zone_methods_screen( $zone_id ) {
	if ( 'new' === $zone_id ) {
		$zone = new WC_Shipping_Zone();
	} else {
		$zone = WC_Shipping_Zones::get_zone( absint( $zone_id ) );
	}

	if ( ! $zone ) {
		wp_die( esc_html__( 'Zone does not exist!', 'woocommerce' ) );
	}

	$allowed_countries   = WC()->countries->get_shipping_countries();
	$shipping_continents = WC()->countries->get_shipping_continents();

	// Prepare locations.
	$locations = array();
	$postcodes = array();

	foreach ( $zone->get_zone_locations() as $location ) {
		if ( 'postcode' === $location->type ) {
			$postcodes[] = $location->code;
		} else {
			$locations[] = $location->type . ':' . $location->code;
		}
	}

	wp_localize_script(
		'wc-shipping-zone-methods',
		'shippingZoneMethodsLocalizeScript',
		array(
			'methods'                 => $zone->get_shipping_methods( false, 'json' ),
			'zone_name'               => $zone->get_zone_name(),
			'zone_id'                 => $zone->get_id(),
			'wc_shipping_zones_nonce' => wp_create_nonce( 'wc_shipping_zones_nonce' ),
			'strings'                 => array(
				'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ),
				'save_changes_prompt'     => __( 'Do you wish to save your changes first? Your changed data will be discarded if you choose to cancel.', 'woocommerce' ),
				'save_failed'             => __( 'Your changes were not saved. Please retry.', 'woocommerce' ),
				'add_method_failed'       => __( 'Shipping method could not be added. Please retry.', 'woocommerce' ),
				'yes'                     => __( 'Yes', 'woocommerce' ),
				'no'                      => __( 'No', 'woocommerce' ),
				'default_zone_name'       => __( 'Zone', 'woocommerce' ),
			),
		)
	);
	wp_enqueue_script( 'wc-shipping-zone-methods' );

	include_once dirname( __FILE__ ) . '/views/html-admin-page-shipping-zone-methods.php';
}