Home › Forums › General Issues › Use ACF image field from specific post ID as CSS Background › Reply To: Use ACF image field from specific post ID as CSS Background
I am assuming that post-32
refers to the post ID of the product. But, the classes you are using for targeting do not match those used in a standard WC product loop, so I could be completely wrong, but that could have something to do with the theme I’m looking at.
add_action('woocommerce_before_shop_loop_item_title', 'custom_product_css');
function custom_product_css() {
global $product;
?>
<style type="text/css">
.woocommerce .products .grid-common-col.post-<?php echo $product->id {
background-image: url(<?php the_field('my_image', $product->id); ?>);
}
</style>
<?php
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.