Adds a field connection in Beaver Builder Themer to allow use of a product Category Image within the single product template. For use as background image or image module.
– Add to functions.php –
function get_woo_cat_img() {
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ){
$category_name = $term->name;
$category_thumbnail = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true);
$image = wp_get_attachment_url($category_thumbnail);
return $image;
}
}
add_action( 'fl_page_data_add_properties', function() {
FLPageData::add_site_property( 'woo_cat_img_connection', array(
'label' => 'Single Product Category Image',
'group' => 'woocommerce',
'type' => 'photo',
'getter' => 'get_woo_cat_img'
) );
} );