Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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