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

WC_API_Products::edit_product_shipping_class() public WC 2.5.0

Edit a 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->edit_product_shipping_class( $id, $data );
$id(int) (обязательный)
Product shipping class term ID
$data(массив) (обязательный)
Posted data

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

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

Код WC_API_Products::edit_product_shipping_class() WC 5.6.0

public function edit_product_shipping_class( $id, $data ) {
	global $wpdb;

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

		$id   = absint( $id );
		$data = $data['product_shipping_class'];

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

		$data           = apply_filters( 'woocommerce_api_edit_product_shipping_class_data', $data, $this );
		$shipping_class = $this->get_product_shipping_class( $id );

		if ( is_wp_error( $shipping_class ) ) {
			return $shipping_class;
		}

		$update = wp_update_term( $id, 'product_shipping_class', $data );
		if ( is_wp_error( $update ) ) {
			throw new WC_API_Exception( 'woocommerce_api_cannot_edit_product_shipping_class', __( 'Could not edit the shipping class', 'woocommerce' ), 400 );
		}

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

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