New Landing How can we help? Atelier Atelier, Advanced Custom Fields, and WooCommerce Products

Viewing 3 posts - 1 through 3 (of 3 total)
  • Posted in: Atelier
  • #187185
    terrysmith
    Member
    Post count: 48

    I’m looking at using Advanced Custom Fields (ACF) to add custom fields to some products (probably based on category). I don’t need help with ACF but rather was wondering if there is a better way to do this than copy and change the product PHP template? Are there function hooks I can use to insert the read-only fields into the product description? Ideally, where you list SKU and Category to the right of the product image I would like to insert other attributes. I also want to add one or more tabs on the bottom.

    Thanks,
    Terry

    #187190
    terrysmith
    Member
    Post count: 48

    I’m mostly there with this code. I think I can add a tab as well.

    add_action( ‘woocommerce_product_meta_start’, “ACF_product_meta_content”, 10 );

    function ACF_product_meta_content() {
    if (get_field(‘dimensions’))
    {
    echo the_field(‘dimensions’);
    }
    }

    Unfortunately, the SKU and Category meta are not being output in structured HTML that is easy to style and match to:

    <span class=”sku_wrapper”>SKU: <span class=”sku” itemprop=”sku”>TestProduct</span>.</span>

    Is there an easy way to override the meta output completely?

     

    #188066
    David Martin – Support
    Moderator
    Post count: 20834

    Hey,

    Sure, are you using a child theme?

    You will want to create a file called meta.php in this location: atelier theme folder woocommerce/single-product/meta.php. (Ideally in your child theme)

    Then add this code to the new file:

    <?php
    /**
     * Single Product Meta
     *
     * @author 		WooThemes
     * @package 	WooCommerce/Templates
     * @version     1.6.4
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit; // Exit if accessed directly
    }
    
    global $post, $product;
    
    $cat_count = sizeof( get_the_terms( $post->ID, 'product_cat' ) );
    $tag_count = sizeof( get_the_terms( $post->ID, 'product_tag' ) );
    
    ?>
    <div class="product_meta">
    
    	<?php do_action( 'woocommerce_product_meta_start' ); ?>
    
    	<?php if ( wc_product_sku_enabled() && ( $product->get_sku() || $product->is_type( 'variable' ) ) ) : ?>
    
    		<span class="sku_wrapper"><?php _e( 'SKU:', 'woocommerce' ); ?> <span class="sku" itemprop="sku"><?php echo ( $sku = $product->get_sku() ) ? $sku : __( 'N/A', 'woocommerce' ); ?></span></span>
    
    	<?php endif; ?>
    
    	<?php echo $product->get_categories( ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', $cat_count, 'woocommerce' ) . ' ', '</span>' ); ?>
    
    	<?php echo $product->get_tags( ', ', '<span class="tagged_as">' . _n( 'Tag:', 'Tags:', $tag_count, 'woocommerce' ) . ' ', '</span>' ); ?>
    
    	<?php do_action( 'woocommerce_product_meta_end' ); ?>
    
    </div>

    You can then edit the output to match your needs 🙂

    Thanks,
    David.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register