Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Display a Custom Message for a Selected Shipping Method in WooCommerce?

Want to keep customers informed about additional costs or details related to their chosen shipping option?

This code snippet allows you to display a custom message to customers based on the chosen shipping method on the cart and the checkout page in WooCommerce.

add_action( 'woocommerce_cart_totals_after_shipping', 'ts_shipping_method_custom_notice' );
add_action( 'woocommerce_review_order_after_shipping', 'ts_shipping_method_custom_notice' );

function ts_shipping_method_custom_notice() {
    // HERE DEFINE YOUR TARGETED SHIPPING METHOD(S)
    $targeted_shipping_methods = array('flat_rate:4'); // Replace with the actual shipping method ID(s)

    // Get the chosen shipping methods
    $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );

    if ( ! empty( $chosen_methods ) ) {
        $chosen_method = reset( $chosen_methods );

        // Check if the chosen shipping method is in the targeted list
        if ( in_array( $chosen_method, $targeted_shipping_methods ) ) {
            echo '<tr class="shipping">
                <td colspan="2" style="text-align:center">' . sprintf(
                    __( "You'll be charged %s more for %s", "woocommerce"),
                    '<strong>10%</strong>',
                    '<strong>' . WC()->customer->get_shipping_postcode() . '</strong>'
                ) . '</td>
            </tr>';
        }
    }
}

Output

When a customer selects a shipping method (e.g., Flat Rate), a custom message is displayed under the shipping details on the cart or checkout page. The message informs the customer that an additional charge of 10% will be applied for the selected shipping method to the provided shipping postcode.

How to Display a Custom Message for a Selected Shipping Method in WooCommerce? - Tyche Softwares

A custom message helps customers to clearly notify the extra costs or additional details tied to specific methods or zones. Similar to the above custom message, you can also display custom message based on shipping zone in WooCommerce.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x