WC_Product_Variable_Data_Store_CPT::child_has_weight │ public │ WC 3.0.0

Does a child have a weight set?

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

Хуков нет.

Возвращает

boolean.

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

$WC_Product_Variable_Data_Store_CPT = new WC_Product_Variable_Data_Store_CPT();
$WC_Product_Variable_Data_Store_CPT->child_has_weight( $product );
$product(WC_Product) (обязательный)
Product object.

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

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

Код WC_Product_Variable_Data_Store_CPT::child_has_weight() WC 11.2.2

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

	$has_weight = false;
	$child_ids  = $product->get_visible_children();
	if ( ! empty( $child_ids ) ) {
		$placeholders = implode( ', ', array_fill( 0, count( $child_ids ), '%d' ) );
		$has_weight   = (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 = '_weight' AND meta_value > 0 AND post_id IN ( {$placeholders} ) LIMIT 1",
				$child_ids
			)
		);
	}

	return $has_weight;
}