WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Получай пассивный доход от сайта с помощью браузерных PUSH уведомлений
функция не описана

Automattic\WooCommerce\Admin\API

ProductAttributes::get_custom_attributes() protected WC 1.0

Query custom attributes by name or slug.

{} Это метод класса: ProductAttributes{}

Хуков нет.

Возвращает

Массив. Matching attributes, formatted for response.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_custom_attributes( $args );
$args(строка) (обязательный)
Search arguments, either name or slug.

Код ProductAttributes::get_custom_attributes() WC 5.2.2

<?php
protected function get_custom_attributes( $args ) {
	global $wpdb;

	$args = wp_parse_args(
		$args,
		array(
			'name' => '',
			'slug' => '',
		)
	);

	if ( empty( $args['name'] ) && empty( $args['slug'] ) ) {
		return array();
	}

	$mode = $args['name'] ? 'name' : 'slug';

	if ( 'name' === $mode ) {
		$name = $args['name'];
		// Get as close as we can to matching the name property of custom attributes using SQL.
		$like = '%"name";s:%:"%' . $wpdb->esc_like( $name ) . '%"%';
	} else {
		$slug = sanitize_title_for_query( $args['slug'] );
		// Get as close as we can to matching the slug property of custom attributes using SQL.
		$like = '%s:' . strlen( $slug ) . ':"' . $slug . '";a:6:{%';
	}

	// Find all serialized product attributes with names like the search string.
	$query_results = $wpdb->get_results(
		$wpdb->prepare(
			"SELECT meta_value
			FROM {$wpdb->postmeta}
			WHERE meta_key = '_product_attributes'
			AND meta_value LIKE %s
			LIMIT 100",
			$like
		),
		ARRAY_A
	);

	$custom_attributes = array();

	foreach ( $query_results as $raw_product_attributes ) {

		$meta_attributes = maybe_unserialize( $raw_product_attributes['meta_value'] );

		if ( empty( $meta_attributes ) || ! is_array( $meta_attributes ) ) {
			continue;
		}

		foreach ( $meta_attributes as $meta_attribute_key => $meta_attribute_value ) {
			$meta_value = array_merge(
				array(
					'name'        => '',
					'is_taxonomy' => 0,
				),
				(array) $meta_attribute_value
			);

			// Skip non-custom attributes.
			if ( ! empty( $meta_value['is_taxonomy'] ) ) {
				continue;
			}

			// Skip custom attributes that didn't match the query.
			// (There can be any number of attributes in the meta value).
			if ( ( 'name' === $mode ) && ( false === stripos( $meta_value['name'], $name ) ) ) {
				continue;
			}

			if ( ( 'slug' === $mode ) && ( $meta_attribute_key !== $slug ) ) {
				continue;
			}

			// Skip already matched attributes.
			if ( isset( $custom_attributes[ $meta_attribute_key ] ) ) {
				continue;
			}

			// Mimic the structure of a taxonomy-backed attribute for response.
			$data = array(
				'id'           => $meta_attribute_key,
				'name'         => $meta_value['name'],
				'slug'         => $meta_attribute_key,
				'type'         => 'select',
				'order_by'     => 'menu_order',
				'has_archives' => false,
			);

			$response = rest_ensure_response( $data );
			$response->add_links( $this->prepare_links( (object) array( 'attribute_id' => $meta_attribute_key ) ) );
			$response = $this->prepare_response_for_collection( $response );

			$custom_attributes[ $meta_attribute_key ] = $response;
		}
	}

	return array_values( $custom_attributes );
}