WC_Product_Variable_Data_Store_CPT::child_has_dimensionspublicWC 3.0.0

Does a child have dimensions set?

Method of the class: WC_Product_Variable_Data_Store_CPT{}

No Hooks.

Returns

boolean.

Usage

$WC_Product_Variable_Data_Store_CPT = new WC_Product_Variable_Data_Store_CPT();
$WC_Product_Variable_Data_Store_CPT->child_has_dimensions( $product );
$product(WC_Product) (required)
Product object.

Changelog

Since 3.0.0 Introduced.

WC_Product_Variable_Data_Store_CPT::child_has_dimensions() code WC 11.1.1

public function child_has_dimensions( $product ) {
	global $wpdb;

	$has_dimensions = false;
	$child_ids      = $product->get_visible_children();
	if ( ! empty( $child_ids ) ) {
		$placeholders   = implode( ', ', array_fill( 0, count( $child_ids ), '%d' ) );
		$has_dimensions = (bool) $wpdb->get_var(
			$wpdb->prepare(
				// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
				"SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key IN ( '_length', '_width', '_height' ) AND meta_value > 0 AND post_id IN ( {$placeholders} ) LIMIT 1",
				$child_ids
			)
		);
	}

	return $has_dimensions;
}