wc_delete_related_product_transients()
Устарела с версии 10.1.0 This function is deprecated and will be removed in a future version.. Больше не поддерживается и может быть удалена. Рекомендуется заменить эту функцию на аналог.
Delete all related products transients when a product is updated/created. This is necessary because changing one product affects all related products too.
Хуков нет.
Возвращает
null. Ничего (null).
Использование
wc_delete_related_product_transients( $post_id );
- $post_id(int) (обязательный)
- The product ID updated/created.
Список изменений
| С версии 9.8.0 | Введена. |
| Устарела с 10.1.0 | This function is deprecated and will be removed in a future version. |
Код wc_delete_related_product_transients() wc delete related product transients WC 10.8.1
function wc_delete_related_product_transients( $post_id ) {
wc_deprecated_function( 'wc_delete_related_product_transients', '10.1.0', 'This function is deprecated and will be removed in a future version.' );
if ( ! is_numeric( $post_id ) ) {
return;
}
$transient_name = 'wc_related_' . $post_id;
$old_transient = get_transient( $transient_name );
$old_related_product_ids = array();
if ( is_array( $old_transient ) && ! empty( $old_transient ) ) {
$old_related_product_ids = $old_transient[ array_key_first( $old_transient ) ];
}
// Delete current product transient so that it can be refreshed below.
delete_transient( $transient_name );
// Gets new related products and sets current product transient.
$new_related_product_ids = wc_get_related_products( $post_id, 1000 );
// Combine all product IDs that need their transients cleared.
$related_product_ids = array_unique(
array_merge(
$old_related_product_ids,
$new_related_product_ids
)
);
if ( empty( $related_product_ids ) ) {
return;
}
// Create the list of transient names to delete.
$related_product_transients = array_map(
function ( $id ) {
return 'wc_related_' . $id;
},
$related_product_ids
);
_wc_delete_transients( $related_product_transients );
}