<?php
/**
* Filter woocommerce product titles.
*
* @package Fix
*/
/**
* Filter the product title by category
*
* @param string $title The title.
* @param integer $id The id.
*
* @return string Filtered title.
*/
function woocommerce_category_title_filter( $title, $id ) {
$post_type = get_post_type();
if ( 'product' !== $post_type ) {
return $title;
}
$categories = wp_get_post_terms( $id, 'product_cat' );
if ( empty( $categories ) ) {
return $title;
}
$cat_ids = wp_list_pluck( $categories, 'term_id' );
if ( ! in_array( 18, $cat_ids, true ) ) { // 18 is the product category id being filtered
return $title;
}
return 'Per Day ' . $title;
}
add_filter( 'the_title', 'woocommerce_category_title_filter', 10, 2 );
]]>
Would it be the same case for the price too(as I’m wanting to add that after the price).
Cheers
]]>
<?php
//don't copy above opening tag if pasting into functions.php
//Add in text after price to certain products
function themeprefix_custom_price_message( $price ) {
global $post;
$product_id = $post->ID;
$my_product_array = array( 799,796,792 );//add in product IDs
if ( in_array( $product_id, $my_product_array )) {
$textafter = '( Upfront Paid in Full Price )'; //add your text
return $price . '<br /><span class="price-description">' . $textafter . '</span>';
}
else {
return $price;
}
}
add_filter( 'woocommerce_get_price_html', 'themeprefix_custom_price_message' );
]]>