To show a specific notice on Thankyou page when an order item is from a specific product category, you can use the following code that will check on each order item for your specific product category (displaying a custom notice):
add_filter( 'woocommerce_thankyou_order_received_text', 'custom_thankyou_order_received_text', 20, 2 );
function custom_thankyou_order_received_text( $thankyou_text, $order ){
// Loop through order items
foreach ( $order->get_items() as $item ) {
// Get the Product ID from WC_Order_Item_Product order item
$product_id = $item->get_product_id();
// We check for 'media' product category on each order item
if ( has_term( 'media', 'product_cat', $product_id ) ) {
$thankyou_text = __( 'Your custom message goes here.', 'woocommerce' );
break; // We can stop the loop now.
}
}
return $thankyou_text;
}
Code goes in functions.php file of your active child theme (or active theme). It should work.
Related: