Custom Shipping Rate Descriptions

Adds custom descriptions to WooCommerce shipping rates.

PHP
/**
 * Snippet Name:     Custom Shipping Rate Descriptions
 * Snippet Author:   coding-bunny.com
 * Description:      Adds custom descriptions to WooCommerce shipping rates.
 */

add_action( 'woocommerce_after_shipping_rate', 'cb_shipping_rate_description' );

/**
 * Adds custom descriptions for specific WooCommerce shipping methods.
 *
 * @param WC_Shipping_Rate $method The shipping method instance.
 */
function cb_shipping_rate_description( $method ) {
    // Check if the shipping method is free shipping with ID 'free_shipping:11'
    if ( $method->id === 'free_shipping:11' ) { 
        echo '<p style="font-size: 11px; font-weight: 300;">Free delivery within 2-3 days.</p>';
    }
    
    // Check if the shipping method is flat rate with ID 'flat_rate:1'
    if ( $method->id === 'flat_rate:1' ) { 
        echo '<p style="font-size: 11px; font-weight: 300;">Delivery within 2-3 days.</p>';
    }
    
    // Check if the shipping method is flat rate with ID 'flat_rate:14'
    if ( $method->id === 'flat_rate:14' ) { 
        echo '<p style="font-size: 11px; font-weight: 300;">Delivery within 24 hours.</p>';
    }
}

How To Implement This Solution?

Leave a Reply