Support

Account

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 
    }