• Resolved aibonewt

    (@aibonewt)


    Hi All,

    First off, I have

      zero

    knowledge of PHP but have managed to wrangle the following snippet into displaying product dimensions under the Additional Information tab. Yes, it’s ugly, but it does the job.

    function tjn_woocommerce_display_product_attributes($product_attributes, $product){
    	$product_attributes['dimensions'] = [
    	'label' => __('Size (cm)', 'text-domain'),
    	'value' => get_post_meta($product->get_ID(), 'Widcm', true) . " x " . get_post_meta($product->get_ID(), 'Hgtcm', true) . " x " . get_post_meta($product->get_ID(), 'Depcm', true),
    	];
    	return $product_attributes;
    }
    add_filter('woocommerce_display_product_attributes', 'tjn_woocommerce_display_product_attributes', 20, 3);

    I’d really like to display the net weight of products too (already have meta: Wgtgm populated in my product database), but can’t figure out how to add two lines to the tab. Any ideas?

    Many thanks in advance

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @aibonewt

    Thanks for reaching out!

    If I understand you correctly, you would like to have two lines per row, is that correct?

    If so, you could add the breakline tag <br />.

    'value' => get_post_meta($product->get_ID(), 'Widcm', true) . " x <br />" . get_post_meta($product->get_ID(), 'Hgtcm', true) . " x " . get_post_meta($product->get_ID(), 'Depcm', true),

    This will be the output:

    Image Link: https://snipboard.io/Xibhu5.jpg

    Does this go in the right direction? Otherwise, if you could provide us a clear screenshot of what you would like to achieve here so that we could address you further?

    I’d recommend using https://snipboard.io or https://skitch.com/. You can share the direct link to the image as a response to this topic.

    Thread Starter aibonewt

    (@aibonewt)

    Hi

    That’s useful to know, thanks, but not quite what I was after.

    My code snippet adds an attribute containing a label and value pair, which results in an additional entry in the Additional Information tab.

    I’d like to know how to add TWO of these pairs in well-formed code, rather than just copy the whole function and duplicate it.

    Hi @aibonewt

    Thanks for providing more context to your inquiry here.

    These forums are meant for general support with the core functionality of WooCommerce itself. What you want to achieve is a bit complex and would require customization to do it. Since custom coding is outside our scope of support, I am leaving this thread open for a bit to see if anyone can chime in to help you out.

    For questions related to development and custom coding, your best bet is to ask on any of these channels for support. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, too.

    WooCommerce Developer Resources Portal
    WooCommerce Advanced Facebook group
    WooCommerce Community Forum
    WooCommerce Developer Slack Channel.
    – Hire a WooCommerce Expert

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Adding Multiple Lines to Additional Information Tab’ is closed to new replies.