Created
May 4, 2020 08:40
-
-
Save damiencarbery/7afaa09b7a31e4d9105b9076543b077f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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