How to output Custom Fields with functions.php

Support General How to output Custom Fields with functions.phpResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #39088
    Michael KrautwasserMichael Krautwasser
    Participant

    Hello,

    I am new to Metabox.io and I am looking for a way to output custom fields to a Single product page (WooCommerce) below the short description text.

    I know how to output the custom field I created with Metabox.io directly in the template pages using:
    <?php $value = rwmb_meta( 'my_custom_field' ) ?>
    <p>Here comes the custom field: <?= $value ?></p>

    But is there a way to add a function in functions.php to output the custom field with the hook "woocommerce_before_add_to_cart_quantity"?

    By the way… I am using a Block Theme (Gutenberg).

    Thanks for help,
    Michael

    #39104
    PeterPeter
    Moderator

    Hello Michael,

    The helper function can help you to output the field value anywhere on the site, the main goal is to pass the field ID and post ID to the function, like this

    <?php $value = rwmb_meta( 'my_custom_field', '', $post_id ) ?>

    You can contact WooCommerce support or your theme support to ask for getting the post ID when using the hook.

    #39136
    Michael KrautwasserMichael Krautwasser
    Participant

    Okay, thanks. I will have a look at it.

    M.

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