• Resolved pnbnsv

    (@pnbnsv)


    Hi there,

    I have been able to add a description to every shipping method that shows in the cart, but I need to assign it for a specific shipping method only and not for all of them.

    Please check the screenshot.

    Any help?

    Thanks.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator bcworkz

    (@bcworkz)

    Try the ‘woocommerce_cart_shipping_method_full_label’ filter. Your callback is passed the HTML that is output for the method and a $method object that contains information specific to each method, from which you can decide if the method is one you need to add a description to or not.

    Thread Starter pnbnsv

    (@pnbnsv)

    Thanks for the reply. I don’t know PHP enough to do that. Can you help? This is the code I am using now:

    // adds a notice after shipping rates
    function notice_pickup() {
    echo '<p id="pick">Deve seleccionar um ponto da Rede Pickup</p>';
    }
    add_action( 'woocommerce_after_shipping_rate', 'notice_pickup' );
    Moderator bcworkz

    (@bcworkz)

    I’m not entirely sure myself, I don’t know what the $method object looks like and what property to check against what value. The following is a start anyway. The ???????? parts need to be completed to identify your target shipping method. If you remove the comment marks //, you will get a bunch of debug output for each method from which you can determine the property and value required. Add comment marks to the if line to avoid syntax errors until the right replacements for ??????? are found.

    function notice_pickup_2( $label, $method ) {
      //$x = print_r( $method, true ); $label .= "<pre> $x </pre>\n";
      if ( '??????????'== $method->???????? )
        $label .= '<p id="pick">Deve seleccionar um ponto da Rede Pickup</p>';
      return $label
    }
    add_filter( 'woocommerce_cart_shipping_method_full_label', 'notice_pickup_2', 10, 2 );

    Thread Starter pnbnsv

    (@pnbnsv)

    Thanks a lot for your help.

    I am not sure if I did it right but I got this info about the shipping methods I need to add the description:

    [1] => Array
    (
    [title] => Ponto pickup Chronopost (24h)
    [identifier] => pickuppt-chronopost-24h
    [zone] => 1
    [zone_order] => 1
    [class] => *
    [class_priority] =>
    [cond] => weight
    [min] => 0
    [max] => 0.99
    [shiptype] => €
    [cost] => 5
    [bundle_qty] => 0
    [bundle_cost] => 0
    [default] => 0

    Is this useful?

    Moderator bcworkz

    (@bcworkz)

    Very useful, thanks! Changing that one line in question to this should do it (and comment out the print_r() line again):
    if ('pickuppt-chronopost-24h'== $method->identifier )

    I hope this does the job for you, it’s all untested.

    Thread Starter pnbnsv

    (@pnbnsv)

    Thanks for the reply.

    There is a ‘;’ missing after ‘return $label’ in your code. I missed that in the first place and wasn’t able to get the debug output. I tried the code and it doesn’t show the notice.

    Here is the debug output with your code:

    WC_Shipping_Rate Object
    (
    [id] => table_rate_shipping_pickuppt-chronopost-24h
    [label] => Ponto pickup Chronopost (24h)
    [cost] => 5.00
    [taxes] => Array
    (
    )

    [method_id] => table_rate_shipping
    [meta_data:WC_Shipping_Rate:private] => Array
    (
    )

    )

    I think it is a bit different from the previous one.

    Moderator bcworkz

    (@bcworkz)

    Ah, crap! Sorry about the missing ; , it’s a really bad (and now embarassing) habit I have.

    This should do it:
    if ('table_rate_shipping_pickuppt-chronopost-24h'== $method->id )

    Thread Starter pnbnsv

    (@pnbnsv)

    No problem about the missing ;. It happens to everyone!

    Here’s the good news: your code worked just fine!!

    Thank you very much for your help.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Adding a description to a specific shiping method’ is closed to new replies.