WC_Product_CSV_Importer::parse_shipping_class_field()publicWC 1.0

Parse a shipping class field from a CSV.

Method of the class: WC_Product_CSV_Importer{}

No Hooks.

Return

Int.

Usage

$WC_Product_CSV_Importer = new WC_Product_CSV_Importer();
$WC_Product_CSV_Importer->parse_shipping_class_field( $value );
$value(string) (required)
Field value.

WC_Product_CSV_Importer::parse_shipping_class_field() code WC 8.7.0

public function parse_shipping_class_field( $value ) {
	if ( empty( $value ) ) {
		return 0;
	}

	$term = get_term_by( 'name', $value, 'product_shipping_class' );

	if ( ! $term || is_wp_error( $term ) ) {
		$term = (object) wp_insert_term( $value, 'product_shipping_class' );
	}

	if ( is_wp_error( $term ) ) {
		return 0;
	}

	return $term->term_id;
}