Skip to content

Instantly share code, notes, and snippets.

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 damiencarbery/7afaa09b7a31e4d9105b9076543b077f to your computer and use it in GitHub Desktop.
Save damiencarbery/7afaa09b7a31e4d9105b9076543b077f to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Style a shipping method to highlight it
Plugin URI: https://www.damiencarbery.com/2020/05/style-a-shipping-method-to-highlight-it/
Description: Insert CSS selectors into the markup to highlight a specific shipping method.
Author: Damien Carbery
Version: 0.1
*/
// Style the collection option ('free shipping' shipping method) to make font smaller.
add_action( 'woocommerce_after_shipping_rate', 'dcwd_style_shipping_methods_label', 10, 2 );
function dcwd_style_shipping_methods_label( $method, $index ) {
if ( 'free_shipping' == $method->method_id ) {
$label_for = sprintf( 'shipping_method_%1$s_%2$s', $index, esc_attr( sanitize_title( $method->id ) ) );
?>
<style>
:root { --free-shipping-font-size: 60%; /* This should be defined elsewhere. It's here as a demo. */ }
label[for=<?php echo $label_for; ?>] { font-size: var(--free-shipping-font-size); }
</style>
<?
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment