meta_is_product_attribute( string $name, string $value, int $product_id )

Returns true when the passed meta name is a product attribute.


Description Description


Parameters Parameters

$name

(Required) of the attribute.

$value

(Required) of the attribute.

$product_id

(Required) to check for attribute.


Top ↑

Return Return

(bool)


Top ↑

Source Source

File: includes/wc-conditional-functions.php

	function meta_is_product_attribute( $name, $value, $product_id ) {
		$product = wc_get_product( $product_id );

		if ( $product && method_exists( $product, 'get_variation_attributes' ) ) {
			$variation_attributes = $product->get_variation_attributes();
			$attributes           = $product->get_attributes();
			return ( in_array( $name, array_keys( $attributes ), true ) && in_array( $value, $variation_attributes[ $attributes[ $name ]['name'] ], true ) );
		} else {
			return false;
		}
	}


Top ↑

User Contributed Notes User Contributed Notes

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