Я нашел этот кусок кода, и он прекрасно работает. Я хотел бы видеть, что это также работает на подкатегориях. Я надеюсь, что кто-то может помочь мне с этим.
// Simple, grouped and external products
add_filter('woocommerce_product_get_price', 'conditional_custom_price', 99, 2 );
add_filter('woocommerce_product_get_regular_price', 'conditional_custom_price', 99, 2 );
// Variable
add_filter('woocommerce_product_variation_get_regular_price', 'conditional_custom_price', 99, 2 );
add_filter('woocommerce_product_variation_get_price', 'conditional_custom_price', 99, 2 );
function conditional_custom_price( $price, $product ) {
global $post;
if( has_term( 'test', 'product_cat', $post->ID )){
// Delete product cached price (if needed uncomment it)
// wc_delete_product_transients($product->get_id());
$price = $price * 2.1;
}
return $price;
}