Skip to content

Instantly share code, notes, and snippets.

@dangoodman
Created January 4, 2018 15:05
Show Gist options
  • Save dangoodman/72c3d74eec2d7e235b1e98c9688f28a0 to your computer and use it in GitHub Desktop.
Save dangoodman/72c3d74eec2d7e235b1e98c9688f28a0 to your computer and use it in GitHub Desktop.
WooCommerce: cut shipping option ids if they exceed 50-chars length
<?php
// Paste everything below this line to your child-theme's functions.php file.
// Cut shipping option ids if they exceed 50-chars length.
add_filter('woocommerce_package_rates', function ($rates) {
$shortened = array();
foreach ($rates as $rate_id => $rate) {
$rate_id = substr($rate_id, 0, 50);
$rate->id = $rate_id;
$shortened[$rate_id] = $rate;
}
return $shortened;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment