Dear Team,
We want to write a function which will replace product featured image with brand image incase there is no product featured image present.
I have found this code snippet, can you suggest what changes would be required in the same to make it work with the xstore theme?
Snippet:
// run the function on only product pages and category pages
add_action(‘init’, ‘dwd_run_brands_on_product_and_categories_only’);
function dwd_run_brands_on_product_and_categories_only() {
if ( (!is_admin()) && (is_product() || is_product_category())) {
add_filter(‘woocommerce_placeholder_img_src’,’dwd_replace_placeholder_image_with_brand’);
}
}
// Add brand image to products that have no image
function dwd_replace_placeholder_image_with_brand() {
global $product;
$productImage = wp_get_attachment_url( $product->get_image_id() );
if (empty($productImage) && (is_product_category() || is_product())) {
$productBrands = wp_get_object_terms( $product->get_id(), ‘pwb-brand’ );
foreach( $productBrands as $brand ) {
$brandLogo = get_term_meta( $brand->term_id, ‘pwb_brand_image’, true );
$brandLogo = wp_get_attachment_url( $brandLogo );
return $brandLogo;
}
}
}