Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashokrane/9de0f639106f867edd6f2f4010c6ae8a to your computer and use it in GitHub Desktop.
Save ashokrane/9de0f639106f867edd6f2f4010c6ae8a to your computer and use it in GitHub Desktop.
Print custom text on WooCommerce Thank You page based on product attribute id (variation id)
<?php
add_action( 'woocommerce_thankyou', 'show_custom_text_by_variation_id', 1 );
function show_custom_text_by_variation_id( $order_id ) {
$order = wc_get_order( $order_id );
foreach( $order->get_items() as $item ) {
// Add whatever variation id you want below here. My attributes are Cheddar, Mozarella & Swiss
if ( isset( $item[ 'variation_id' ] ) && $item[ 'variation_id' ] == 446 ) {
echo 'Thank you for choosing Cheddar cheese. Enjoy your Sandwich!<br/>';
}
}
}
@ZBytes0
Copy link

ZBytes0 commented Jun 19, 2022

Hi i need this for multipe products please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment