I'm trying to add a message to the order-received (Thank You) page, only if the order is using Free Shipping. The message can either replace the standard "Thank you..." message, or can be in addition to.
Here is the code I'm working with. It's based off of the answer here: Customize Order received page based on shipping method in WooCommerce
//add message to order received if outside delivery area
add_filter( 'woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 20, 2 );
function woo_change_order_received_text( $thankyou_text, $order ) {
if ( is_wc_endpoint_url( 'order-received' ) ) {
global $wp;
$order_id = absint( $wp->query_vars['order-received'] );
$order_key = isset( $_GET['key'] ) ? wc_clean( $_GET['key'] ) : '';
$method_title_names = array();
if( in_array( 'Free shipping', $method_title_names ) ) {
return sprintf( __("%s <div class=\"outside-delivery-checkout\"><b>PLEASE NOTE:</b><br />Your shipping destination is outside of our normal delivery area. Our team will call you to calculate an additional fuel surcharge.</div>", "woocommerce"),
$thankyou_text
);
}
}
return $thankyou_text;
}
I can't get it to work correctly, and not sure what's wrong. Any help is greatly appreciated.
You need simply the following (where "Free shipping" is the name of your free shipping method):
Similar: Code goes in function.php file of your active child theme (or active theme). Tested and works.
Customize Order received page based on shipping method in WooCommerce