Woocommerce. Как можно добавить еще одну переменную в код?

На сайте есть категория товаров "Распродажа". У этих товаров есть обычная цена, к ним нужно добавить sale price по формуле (обычная цена * 1,5).

Как добавить еще одну категорию в данный код?

/**
 * Calculate regular price.
 *
 * @param mixed      $price   Price.
 * @param WC_Product $product Product.
 *
 * @return mixed
 */
function calc_regular_price( $price, $product ) {
    $cat_id  = 5;
    $cat_ids = $product->get_category_ids();

    if ( ! in_array( $cat_id, $cat_ids, true ) ) {
        return $price;
    }

    return $price * 1.5;
}

add_filter( 'woocommerce_product_get_regular_price', 'calc_regular_price', 10, 2 );

/**
 * Calculate sale price.
 *
 * @param mixed      $price   Price.
 * @param WC_Product $product Product.
 *
 * @return mixed
 */
function calc_sale_price( $price, $product ) {
    $cat_id  = 5;
    $cat_ids = $product->get_category_ids();

    if ( ! in_array( $cat_id, $cat_ids, true ) ) {
        return $price;
    }

    remove_filter( 'woocommerce_product_get_regular_price', 'calc_sale_price', 10, 2 );
    $price = $product->get_regular_price();
    add_filter( 'woocommerce_product_get_regular_price', 'calc_sale_price', 10, 2 );

    return $price;
}

add_filter( 'woocommerce_product_get_sale_price', 'calc_sale_price', 10, 2 );

Ответы (1 шт):

Автор решения: WP Punk

Меняете $cat_id на массив. Затем с помощью array_intersect ищите пересечения массивов:

...
$sale_cat_ids = [ 5, 10 ];
$cat_ids      = $product->get_category_ids();

if ( ! array_intersect( $sale_cat_ids, $cat_ids ) ) {
    return $price;
}
...
→ Ссылка