Layout builder – color icons based on ACF repeater color field

mgibbs189

{{gist file=”functions.php” lang=”php”}}
<?php

add_filter( ‘facetwp_builder_item_value’, function( $value, $item ) {
if ( ‘phone-colors’ == $item[‘settings’][‘name’] ) {
if ( is_array( $value ) ) {
$temp = ‘<style>.color-square { display: inline-block; width: 20px; height: 20px; border: 1px solid #000; border-radius: 50%; margin-right:5px; }</style>’;
$value = wp_list_pluck( $value, ‘color’ );
foreach ( $value as $val ) {
$temp .= ‘<div class=”color-square” style=”background-color:’ . $val . ‘”></div>’;
}
$value = $temp;
}
}
return $value;
}, 10, 2 );

{{/gist}}