• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WooCommerce a2z

WooCommerce a2z

WooCommerce

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / WC_REST_Shipping_Zones_V2_Controller::create_item() – Create a single Shipping Zone.

You appear to be a bot. Output may be restricted

Description

Create a single Shipping Zone.

Usage

$WP_REST_Request|WP_Error = WC_REST_Shipping_Zones_V2_Controller::create_item( $request );

Parameters

$request
( WP_REST_Request ) required – Full details about the request.

Returns

WP_REST_Request|WP_Error

Source

File name: woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-shipping-zones-v2-controller.php


Lines:

1 to 24 of 24
  public function create_item( $request ) {
    $zone = new WC_Shipping_Zone( null );

    if ( ! is_null( $request->get_param( 'name' ) ) ) {
      $zone->set_zone_name( $request->get_param( 'name' ) );
    }

    if ( ! is_null( $request->get_param( 'order' ) ) ) {
      $zone->set_zone_order( $request->get_param( 'order' ) );
    }

    $zone->save();

    if ( $zone->get_id() !== 0 ) {
      $request->set_param( 'id', $zone->get_id() );
      $response = $this->get_item( $request );
      $response->set_status( 201 );
      $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $zone->get_id() ) ) );
      return $response;
    } else {
      return new WP_Error( 'woocommerce_rest_shipping_zone_not_created', __( "Resource cannot be created. Check to make sure 'order' and 'name' are present.", 'woocommerce' ), array( 'status' => 500 ) );
    }
  }
 

 View on GitHub View on Trac

Published: 8th February 2020 | Last updated: 10th December 2020

Primary Sidebar

Information

Function name: WC_REST_Shipping_Zones_V2_Controller::create_item
Class ref: WC_REST_Shipping_Zones_V2_Controller
Plugin ref: WooCommerce
Version: 4.8.0
Sourcefile: includes/rest-api/Controllers/Version2/class-wc-rest-shipping-zones-v2-controller.php
File ref: includes/rest-api/Controllers/Version2/class-wc-rest-shipping-zones-v2-controller.php
Deprecated?: No
API Letters: R,S,V,W,Z

Footer

WooCommerce a2z
WooCommerce a2z
WooCommerce
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  woocommerce.wp-a2z.org
© Copyright WooCommerce a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites