Automattic\WooCommerce\Internal\Caches
ProductVersionStringInvalidator::invalidate_products_with_attribute
Invalidate all products using a specific attribute taxonomy.
The list of entities associated with the taxonomy is cached for performance; the TTL can be customized via the woocommerce_version_string_invalidator_taxonomy_lookup_ttl
Метод класса: ProductVersionStringInvalidator{}
Хуки из метода
Возвращает
null. Ничего (null).
Использование
// private - только в коде основоного (родительского) класса $result = $this->invalidate_products_with_attribute( $taxonomy ): void;
- $taxonomy(строка) (обязательный)
- The attribute taxonomy slug.
Код ProductVersionStringInvalidator::invalidate_products_with_attribute() ProductVersionStringInvalidator::invalidate products with attribute WC 10.5.2
private function invalidate_products_with_attribute( string $taxonomy ): void {
global $wpdb;
$cache_key = 'wc_cache_inv_attr_' . $taxonomy;
$cached = wp_cache_get( $cache_key, 'woocommerce' );
if ( false === $cached ) {
$product_ids = $wpdb->get_col(
$wpdb->prepare(
"SELECT DISTINCT post_id FROM {$wpdb->postmeta}
WHERE meta_key = '_product_attributes'
AND meta_value LIKE %s",
'%' . $wpdb->esc_like( 's:' . strlen( $taxonomy ) . ':"' . $taxonomy . '"' ) . '%'
)
);
$variation_ids = $wpdb->get_col(
$wpdb->prepare(
"SELECT DISTINCT post_id FROM {$wpdb->postmeta}
WHERE meta_key = %s",
'attribute_' . $taxonomy
)
);
$cached = array(
'product_ids' => $product_ids,
'variation_ids' => $variation_ids,
);
// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment -- Documented above.
$ttl = apply_filters( 'woocommerce_version_string_invalidator_taxonomy_lookup_ttl', self::DEFAULT_TAXONOMY_LOOKUP_CACHE_TTL, 'product' );
wp_cache_set( $cache_key, $cached, 'woocommerce', $ttl );
}
foreach ( $cached['product_ids'] as $product_id ) {
$this->invalidate( (int) $product_id );
}
foreach ( $cached['variation_ids'] as $variation_id ) {
$this->invalidate_variation_and_parent( (int) $variation_id );
}
}