Product::modifiers()

Summary

No summary available.

Source

File: src/BigCommerce/Post_Types/Product/Product.php

	public function modifiers() {
		$data = json_decode( get_post_meta( $this->post_id(), self::MODIFIER_DATA_META_KEY, true ), true );
		if ( empty( $data ) || ! is_array( $data ) ) {
			return [];
		}

		// ensure we have all the fields we expect for each option
		$data = array_map( function ( $option ) {
			return wp_parse_args( $option, [
				'id'            => 0,
				'display_name'  => '',
				'type'          => '',
				'sort_order'    => 0,
				'required'      => false,
				'config'        => [],
				'option_values' => [],
			] );
		}, $data );


		// respect the sorting set by the user
		usort( $data, function ( $a, $b ) {
			if ( $a['sort_order'] === $b['sort_order'] ) {
				return ( $a['display_name'] < $b['display_name'] ) ? - 1 : 1;
			}

			return ( $a['sort_order'] < $b['sort_order'] ) ? - 1 : 1;
		} );

		return $data;
	}


User Contributed Notes

You must log in before being able to contribute a note or feedback.