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 (null).

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 8.7.0

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

	$localized_object = array(
		'methods'                 => $zone->get_shipping_methods( false, 'json' ),
		'zone_name'               => $zone->get_zone_name(),
		'zone_id'                 => $zone->get_id(),
		'locations'               => $locations,
		'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' ),
			'remove_method_failed'                => __( 'Shipping method could not be removed. Please retry.', 'woocommerce' ),
			'yes'                                 => __( 'Yes', 'woocommerce' ),
			'no'                                  => __( 'No', 'woocommerce' ),
			'default_zone_name'                   => __( 'Zone', 'woocommerce' ),
			'delete_shipping_method_confirmation' => __( 'Are you sure you want to delete this shipping method?', 'woocommerce' ),
		),
	);

	if ( 0 !== $zone->get_id() ) {
		WCAdminAssets::register_script( 'wp-admin-scripts', 'shipping-settings-region-picker', true, array( 'wc-shipping-zone-methods' ) );
		$localized_object['region_options'] = $this->get_region_options( $allowed_countries, $shipping_continents );
	}

	wp_localize_script(
		'wc-shipping-zone-methods',
		'shippingZoneMethodsLocalizeScript',
		$localized_object,
	);
	wp_enqueue_script( 'wc-shipping-zone-methods' );

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