Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
We have a case where we need to put the arrival estimative and price on the shipping service name that is shown on the checkout pane, like "My shipping service: 1 business day: $15.00", and a good approach could be to have a "display_title_callback" argument on hook_commerce_shipping_service_info(). Looking at the module code, looks that a patch on commerce_shipping_services function(http://api.drupalcommerce.org/api/Drupal%20Commerce/sites%21all%21module...) could add this.
Which way would be the best to address this question?
Comment | File | Size | Author |
---|---|---|---|
#3 | commerce_shipping-customize_display_title_for_shipping_services-1992734-3.patch | 1.05 KB | barraponto |
Comments
Comment #1
pedrorocha CreditAttribution: pedrorocha commentedLooking deeper, i think that the place to change is the function commerce_shipping_service_rate_options($order). As i don't know the module code as a whole, i don't know yet if the only place to change is this one.
Comment #2
barraponto CreditAttribution: barraponto commentedI think
hook_commerce_shipping_service_options_alter
should be enough to implement this. Of course, it could be made more friendly to data operations, like adding estimated time. I think it should at least take an array of strings and then implode them with a customizable separator. Because right now I have to assume what is the separator (usually:
) before manipulating the data. Not to mention the custom text from user-generated flat rate services that brings unpredictable strings to the table :PComment #3
barraponto CreditAttribution: barraponto commentedSo, it seems
shipping service
andprice
is still available as data at the timehook_commerce_shipping_line_item_new_alter
is called. But unfortunately,commerce_shipping_service_rate_options
will ignore$line_item->data
by callingcommerce_shipping_service_get_title
which loads from straight fromcommerce_shipping_service_info
. The fix is already in the current code: usecommerce_shipping_line_item_title
which considers$line_item->data
, falls back tohook_shipping_service_info
definitions and finally falls back to eventual custom$line_item->line_item_label
.Since we already have a
$line_item
incommerce_shipping_service_rate_options
, this change is swift.Comment #4
barraponto CreditAttribution: barraponto commentedHere's an example of adding shipping delivery estimates to the display title, made possible thanks to this patch: #1370874-5: Shipping Time.
Comment #5
Byfred CreditAttribution: Byfred commentedI've tested and the barraponto's patch worked just fine
Comment #6
googletorp CreditAttribution: googletorp commentedLooks good, sorry for the long wait time.
Committed to dev.
Comment #7
googletorp CreditAttribution: googletorp commentedForgot status update.