WC_API_Products::get_product_shipping_classes()publicWC 2.5.0

Get a listing of product shipping classes.

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

Возвращает

Массив|WP_Error. List of product shipping classes if succeed, otherwise WP_Error will be returned

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

$WC_API_Products = new WC_API_Products();
$WC_API_Products->get_product_shipping_classes( $fields );
$fields(строка|null)
Fields to limit response to
По умолчанию: null

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

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

Код WC_API_Products::get_product_shipping_classes() WC 8.7.0

public function get_product_shipping_classes( $fields = null ) {
	try {
		// Permissions check
		if ( ! current_user_can( 'manage_product_terms' ) ) {
			throw new WC_API_Exception( 'woocommerce_api_user_cannot_read_product_shipping_classes', __( 'You do not have permission to read product shipping classes', 'woocommerce' ), 401 );
		}

		$product_shipping_classes = array();

		$terms = get_terms( 'product_shipping_class', array( 'hide_empty' => false, 'fields' => 'ids' ) );

		foreach ( $terms as $term_id ) {
			$product_shipping_classes[] = current( $this->get_product_shipping_class( $term_id, $fields ) );
		}

		return array( 'product_shipping_classes' => apply_filters( 'woocommerce_api_product_shipping_classes_response', $product_shipping_classes, $terms, $fields, $this ) );
	} catch ( WC_API_Exception $e ) {
		return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
	}
}