WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WC_API_Products::create_product_shipping_class() public WC 2.5.0

Create a new product shipping class.

{} Это метод класса: WC_API_Products{}

Возвращает

Массив|WP_Error. Product shipping class if succeed, otherwise WP_Error will be returned

Использование

$WC_API_Products = new WC_API_Products();
$WC_API_Products->create_product_shipping_class( $data );
$data(массив) (обязательный)
Posted data

Список изменений

С версии 2.5.0 Введена.

Код WC_API_Products::create_product_shipping_class() WC 5.6.0

public function create_product_shipping_class( $data ) {
	global $wpdb;

	try {
		if ( ! isset( $data['product_shipping_class'] ) ) {
			throw new WC_API_Exception( 'woocommerce_api_missing_product_shipping_class_data', sprintf( __( 'No %1$s data specified to create %1$s', 'woocommerce' ), 'product_shipping_class' ), 400 );
		}

		// Check permissions
		if ( ! current_user_can( 'manage_product_terms' ) ) {
			throw new WC_API_Exception( 'woocommerce_api_user_cannot_create_product_shipping_class', __( 'You do not have permission to create product shipping classes', 'woocommerce' ), 401 );
		}

		$defaults = array(
			'name'        => '',
			'slug'        => '',
			'description' => '',
			'parent'      => 0,
		);

		$data = wp_parse_args( $data['product_shipping_class'], $defaults );
		$data = apply_filters( 'woocommerce_api_create_product_shipping_class_data', $data, $this );

		// Check parent.
		$data['parent'] = absint( $data['parent'] );
		if ( $data['parent'] ) {
			$parent = get_term_by( 'id', $data['parent'], 'product_shipping_class' );
			if ( ! $parent ) {
				throw new WC_API_Exception( 'woocommerce_api_invalid_product_shipping_class_parent', __( 'Product shipping class parent is invalid', 'woocommerce' ), 400 );
			}
		}

		$insert = wp_insert_term( $data['name'], 'product_shipping_class', $data );
		if ( is_wp_error( $insert ) ) {
			throw new WC_API_Exception( 'woocommerce_api_cannot_create_product_shipping_class', $insert->get_error_message(), 400 );
		}

		$id = $insert['term_id'];

		do_action( 'woocommerce_api_create_product_shipping_class', $id, $data );

		$this->server->send_status( 201 );

		return $this->get_product_shipping_class( $id );
	} catch ( WC_API_Exception $e ) {
		return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
	}
}