-
-
Save yratof/8fb32d303919917106185d057eff65e9 to your computer and use it in GitHub Desktop.
WooCommerce Product Category Swatches
This file contains hidden or 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 | |
function display_product_colors() { | |
$colors = array(); | |
$options = get_post_meta(get_the_ID(), '_swatch_type_options', true); | |
foreach($options as $option) { | |
foreach($option as $item) { | |
foreach($item as $att) { | |
$colors[] = $att['color']; | |
} | |
} | |
} | |
$colors = array_unique($colors); | |
foreach($colors as $color) { ?> | |
<div class="archive-swatch" style="background-color:<?php echo $color; ?>"></div> | |
<?php } ?> | |
<style> | |
.archive-swatch { | |
display: inline-block; | |
width: 20px; | |
height: 20px; | |
outline: solid 1px #ccc; | |
} | |
</style> | |
<?php | |
} | |
add_action('woocommerce_after_shop_loop_item', 'display_product_colors'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment