Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save IanMisnerThough/831009ca9e6483eed1c780253bc22935 to your computer and use it in GitHub Desktop.

Select an option

Save IanMisnerThough/831009ca9e6483eed1c780253bc22935 to your computer and use it in GitHub Desktop.
CheckoutWC - allows you to change the order summary text for specific products (used for gift cards or digital products)
/**
* Name: Custom CheckoutWC Thank You Page Messages for Specific/Special Products
* Description: Overrides CheckoutWC order updates and local pickup messages when specific products are in the order.
* Author: Kestrel
* Date: 2025-11-12
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* -------------------------------------------------------
* CONFIGURATION (EDIT THESE)
* -------------------------------------------------------
*/
// One or more product IDs that should trigger custom text. Replace the value in the array with your product IDs.
define( 'CFWTHANKYOUPAGE_SPECIAL_PRODUCT_IDS', array( 127 ) );
// Custom heading text (HTML allowed, sanitized with wp_kses_post)
define( 'CFWTHANKYOUPAGE_HEADING_TEXT', 'Your custom heading goes here' );
// Custom message HTML to display in lieu of the standard Thank You Page messaging (HTML allowed, sanitized with wp_kses_post).
define( 'CFWTHANKYOUPAGE_SPECIAL_MESSAGE_HTML', 'Your custom text goes here' );
/**
* -------------------------------------------------------
* HELPER FUNCTIONS
* -------------------------------------------------------
*/
/**
* Check if the order contains any "special" product IDs.
*/
function cfwthankyoupage_has_special_product( $order ) {
if ( ! $order instanceof WC_Order ) {
return false;
}
foreach ( $order->get_items() as $item ) {
if ( in_array( $item->get_product_id(), CFWTHANKYOUPAGE_SPECIAL_PRODUCT_IDS, true ) ) {
return true;
}
}
return false;
}
/**
* Return sanitized custom message HTML.
*/
function cfwthankyoupage_special_message_html() {
return wp_kses_post( CFWTHANKYOUPAGE_SPECIAL_MESSAGE_HTML );
}
/**
* Return sanitized heading HTML.
*/
function cfwthankyoupage_heading_html() {
return wp_kses_post( CFWTHANKYOUPAGE_HEADING_TEXT );
}
/**
* -------------------------------------------------------
* FILTER OVERRIDES
* -------------------------------------------------------
*/
/**
* 1) Override generic "order updates" message (non–local pickup orders)
*/
add_filter( 'cfw_order_updates_text', function( $text, $order ) {
return cfwthankyoupage_has_special_product( $order )
? cfwthankyoupage_special_message_html()
: $text;
}, 10, 2 );
/**
* 2) Override Local Pickup heading
*/
add_filter( 'cfw_order_updates_heading', function( $heading, $order ) {
return cfwthankyoupage_has_special_product( $order )
? cfwthankyoupage_heading_html()
: $heading;
}, 10, 2 );
/**
* 3) Override Local Pickup instructions
*/
add_filter( 'cfw_pickup_instructions_text', function( $text, $order ) {
return cfwthankyoupage_has_special_product( $order )
? cfwthankyoupage_special_message_html()
: $text;
}, 10, 2 );
/**
* 4) Override Local Pickup address block
* - Return empty string to hide address completely
*/
add_filter( 'cfw_local_pickup_thank_you_address', function( $address, $raw_address, $order ) {
return cfwthankyoupage_has_special_product( $order )
? '' // or: cfwthankyoupage_special_message_html()
: $address;
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment