Я ищу правильный код, который скроет цены для некоторых определенных категорий в Woocommerce.
У меня уже есть код, позволяющий скрыть цены на странице одного товара:
[code]add_action( 'wp', 'remove_prices_based_on_category' ); function remove_prices_based_on_category() { // On product single pages if ( is_product() ) { remove_product_price( get_the_ID() ); } }
function return_custom_price( $price, $instance ) { $price = 'Call our office [b]516.695.3110[/b] for prices.'; return $price; }
add_action( 'woocommerce_before_shop_loop_item', 'remove_product_price', 5, 1 ); // for each product on product listing page/shop page. function remove_product_price( $product_id ) { $product_id = get_the_ID(); $hidden_price_category_ids = array( '27419','27421' ); // Add Product Category IDs for which the product price should be hidden. $product_cat_ids = get_the_terms( $product_id, 'product_cat' ); // Getting all categories for this product. $cat_ids = wp_list_pluck( $product_cat_ids, 'term_id' ); // Getting all category ids for this product. $result = array_intersect( $hidden_price_category_ids, $cat_ids ); // Will match hidden price categories with product categories and the cat id in the array.