WC_AJAX::shipping_zone_methods_save_settings()public staticWC 1.0

Save method settings

Method of the class: WC_AJAX{}

Return

null. Nothing (null).

Usage

$result = WC_AJAX::shipping_zone_methods_save_settings();

WC_AJAX::shipping_zone_methods_save_settings() code WC 9.0.1

public static function shipping_zone_methods_save_settings() {
	if ( ! isset( $_POST['wc_shipping_zones_nonce'], $_POST['instance_id'], $_POST['data'] ) ) {
		wp_send_json_error( 'missing_fields' );
		wp_die();
	}

	if ( ! wp_verify_nonce( wp_unslash( $_POST['wc_shipping_zones_nonce'] ), 'wc_shipping_zones_nonce' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
		wp_send_json_error( 'bad_nonce' );
		wp_die();
	}

	if ( ! current_user_can( 'manage_woocommerce' ) ) {
		wp_send_json_error( 'missing_capabilities' );
		wp_die();
	}

	$instance_id     = absint( $_POST['instance_id'] );
	$zone            = WC_Shipping_Zones::get_zone_by( 'instance_id', $instance_id );
	$shipping_method = WC_Shipping_Zones::get_shipping_method( $instance_id );
	/**
	 * Notify that a non-option setting has been updated.
	 *
	 * @since 7.8.0
	 */
	do_action( 'woocommerce_update_non_option_setting', array( 'id' => 'zone_method_settings' ) );
	$shipping_method->set_post_data( wp_unslash( $_POST['data'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized

	global $current_tab;
	$current_tab = 'shipping';
	/**
	 * Completes the saving process for options.
	 *
	 * @since 7.8.0
	 */
	do_action( 'woocommerce_update_options' );
	$shipping_method->process_admin_options();

	WC_Cache_Helper::get_transient_version( 'shipping', true );

	wp_send_json_success(
		array(
			'zone_id'   => $zone->get_id(),
			'zone_name' => $zone->get_zone_name(),
			'methods'   => $zone->get_shipping_methods( false, 'json' ),
			'errors'    => $shipping_method->get_errors(),
		)
	);
}