Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #378593

    Hi,

    I’m trying to get a Custom Field called “Product Code” to appear on my product pages. It appears when the 2012 theme is activated but as soon as I switch to Enfold, it goes away. I have added this code (via WooCommerce Support) to the functions.php Child Theme file:

    add_action( 'woocommerce_single_product_summary', 'add_custom_field', 31 );
    
    function add_custom_field() {
        global $post;
    
        echo get_post_meta( $post->ID, 'Product Code', true );
    
        return true;
    }

    You can see how I want each product page to look here (this was with 2012 activated): http://cld.wthms.co/1hfmt

    #379117

    Hey imagemakerswi!

    Try switching the first line to this.

    add_action( 'woocommerce_after_single_product_summary', 'add_custom_field', 0 );
    

    That will have it display above our tabs and after the summary.

    Regards,
    Elliott

    #379755

    Below is the code that I have in my child theme’s functions.php file & it didn’t change anything on the product pages…
    -CT

    <?php
    
    /*
    * Add your own functions here. You can also copy some of the theme functions into this file. 
    * WordPress will use those functions instead of the original functions then.
    */
    
    add_action( 'woocommerce_after_single_product_summary', 'add_custom_field', 0 );
    
    function add_custom_field() {
        global $post;
    
        echo get_post_meta( $post->ID, 'meta:Product Code', true );
    
        return true;
    }
    #380249

    Hey!

    Are you sure the meta name is correct? If you change the line to this.

    echo 'testing testing';
    

    Then you’ll see it’s the correct spot to display the post meta.

    Cheers!
    Elliott

    #381134
    This reply has been marked as private.
    #381135
    This reply has been marked as private.
    #381436

    Hi!

    Try to replace the code with this:

    add_action( 'woocommerce_after_single_product_summary', 'add_custom_field', 0 );
    
    function add_custom_field() {
        global $post;
     
    	echo "<div class='prod-code'>Product Code: ";
    	echo get_post_meta( $post->ID, 'Product Code', true );
    	echo "</div>";
    
        return true;
    }

    Add this on Quick CSS to adjust the position of the product code:

    .prod-code {
    position: absolute;
    margin-top: -23px;
    right: 20%;
    }

    Best regards,
    Ismael

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.