Custom Flat Rate Description Text in Woocommerce c

2019-07-26 01:28发布

I have two flat rate shipping methods set up within Shipping Zones. At the checkout both of these shipping methods are available.

I'd like to display a text description under each flat rate shipping option. There doesn't seem to be any options to do this in WooCommerce.

I have tried the following code but needless to say it doesn't work:

add_filter( 'woocommerce_page_title', 'woo_shop_page_title');
function wc_get_shipping_zone( $package ) {

    if( $package == 'flat_rate:1') {
    return "<p>Arriving on your chosen date between 9am - 1pm Perfect for business addresses & special occasions</p>";
    }
    if( $package == 'flat_rate:2') {
    return "<p>Arriving on your chosen date between 9am - 7pm Perfect for residential addresses</p>";
    }
}

Could anyone help to make this work?

This is what I would like the description to look like in the checkout:

enter image description here

1条回答
三岁会撩人
2楼-- · 2019-07-26 02:24

The correct hooked function to add additional information to your shipping "flat rate" methods is:

add_action( 'woocommerce_after_shipping_rate', 'action_after_shipping_rate', 20, 2 );
function action_after_shipping_rate ( $method, $index ) {
    // Targeting checkout page only:
    if( is_cart() ) return; // Exit on cart page

    if( 'flat_rate:1' === $method->id ) {
        echo __("<p>Arriving on your chosen date between 9am - 1pm Perfect for business addresses & special occasions</p>");
    }
    if( 'flat_rate:2' === $method->id ) {
        echo __("<p>Arriving on your chosen date between 9am - 7pm Perfect for residential addresses</p>");
    }
}

This code goes on function.php file of your active child theme (or active theme). tested and works.

查看更多
登录 后发表回答