Skip to content

Instantly share code, notes, and snippets.

@clifgriffin
Last active April 3, 2024 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clifgriffin/c9fbe2474eae670a04926dc4c9e01969 to your computer and use it in GitHub Desktop.
Save clifgriffin/c9fbe2474eae670a04926dc4c9e01969 to your computer and use it in GitHub Desktop.
Show shipping method in CheckoutWC totals table.
<?php
// Do NOT include opening PHP tag above (<?php)
add_filter( 'cfw_cart_totals_shipping_label', function( $label ) {
$chosen_shipping_methods_labels = array();
$packages = WC()->shipping->get_packages();
foreach ( $packages as $i => $package ) {
$chosen_method = WC()->session->get( 'chosen_shipping_methods' )[ $i ] ?? false;
if ( $chosen_method ) {
$available_methods = $package['rates'];
$chosen_shipping_methods_labels[] = $available_methods[ $chosen_method ]->get_label();
}
}
$chosen_shipping_methods_labels = apply_filters( 'cfw_payment_method_address_review_shipping_method', $chosen_shipping_methods_labels );
if ( empty( $chosen_shipping_methods_labels ) ) {
return $label;
}
$label = $label . ' (' . join( ', ', $chosen_shipping_methods_labels ) . ')';
return $label;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment