Skip to content

Instantly share code, notes, and snippets.

@dangoodman
Created April 10, 2020 17:46
Show Gist options
  • Save dangoodman/cae2e6d75e2582ba9714fdf33beab894 to your computer and use it in GitHub Desktop.
Save dangoodman/cae2e6d75e2582ba9714fdf33beab894 to your computer and use it in GitHub Desktop.
WooCommerce: allow HTML in shipping option labels
<?php
// Paste everything below this line to your child-theme's functions.php file.
// Cancel sanitizing for all shipping option labels starting with 'HTML:'.
remove_filter('woocommerce_shipping_rate_label', 'sanitize_text_field');
add_filter('woocommerce_shipping_rate_label', function($label) {
if (substr_compare($label, 'HTML:', 0, 5) === 0) {
$label = ltrim(substr($label, 5));
}
else {
$label = sanitize_text_field($label);
}
return $label;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment