Support

Account

Home Forums Front-end Issues Image field in woocommerce product bundle plugin

Unread

Image field in woocommerce product bundle plugin

  • Hi there!

    I’m using ACF on my WooCommerce shop and found one issue. Each product has a custom acf image field for size chart. It is added to woocommerce/product-attributes.php file like this:

    <?php
    
    defined( 'ABSPATH' ) || exit;
    
    if ( ! $product_attributes ) {
    	return;
    }
    ?>
    <table class="woocommerce-product-attributes shop_attributes">
    	<?php foreach ( $product_attributes as $product_attribute_key => $product_attribute ) : ?>
    		<tr class="woocommerce-product-attributes-item woocommerce-product-attributes-item--<?php echo esc_attr( $product_attribute_key ); ?>">
    			<th class="woocommerce-product-attributes-item__label"><?php echo wp_kses_post( $product_attribute['label'] ); ?></th>
    			<td class="woocommerce-product-attributes-item__value"><?php echo wp_kses_post( $product_attribute['value'] ); ?></td>
    		</tr>
    	<?php endforeach; ?>
    </table>
    <?php
    $sizechart = get_field('size_chart');
    if($sizechart):?>
        <div class="size-chart">
                <h4>Size chart</h4>
            <a href="<?php echo $sizechart['url'];?>">
                <img src="<?php echo $sizechart['url'];?>" alt="Tabela rozmiarów">
            </a>
        </div>
    <?php endif;?>
    

    It’s working just fine. However, recently I started using WooCommerce Product Bundles plugin which gives me the ability to create a new product type – bundle, containing other products from the store. It is created as a separate product.

    As you probably know, woocommerce product page contains informations about its attributes, like all available sizes, colours etc. It is displayed in “Additional informations” tab on product page, just under Description tab.

    Size chart that I added displays right under those attributes. Here is a picture:
    Size chart on additional informations tab

    Product bundle plugin displays the same informations for each product in a bundle like this:
    Bundle additiomal informations

    The problem is, that custom fields are not displayed on product bundles. Oddly enough, if bundle itself has a size-chart added, it’s displayed repeatedly for all products in a bundle. Here is a photo:
    Repeat size-chart in product bundle

    My question is this – how to force the bundle plugin to take size-chart field value from each product in a bundle? Plugin code looks like this:

    // Exit if accessed directly.
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    }
    
    ?>
    <h4 class="bundled_product_attributes_title"><?php echo $title; ?></h4>
    <?php
    wc_get_template( 'single-product/product-attributes.php', array(
    	'product'            => $product,
    	'attributes'         => $attributes,
    	'display_dimensions' => $display_dimensions,
    	'product_attributes' => $product_attributes
    ) );
    

    It seems to me, that the args array that is given to wc_get_template function loops though certain fields on each product. These are built-in woocommerce product field. I tried my best to add size_chart field to that array but no luck so far. Is there a way to force this plugin to also take size_chart field from each product that is in the bundle?

    I hope my explanation wasn’t too long, I tried to fully express the issue. 😀 Thank you in advnance!

    //EDIT: Photos doesn’t seem to be loading. Here is imgur link to all images: https://imgur.com/a/HuDLwaf

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.