• totogigi

    (@totogigi)


    hi, I created three additional fields for the products (artist, serial, year). To view them in the woocommerce product grid I inserted this code into functions.php:

    add_action('woocommerce_after_shop_loop_item_title', function() {
    global $WCFM, $WCFMmp, $product;

    if( !$product ) return;

    $product_id = $product->get_id();
    $artist_name = get_post_meta( $product_id, 'artist_name', true )['post_title'];

    if( $artist_name ) {
    echo "

    ". $artist_name ."";
    }
    }, 50 );

    add_action('woocommerce_after_shop_loop_item_title', function() {
    global $WCFM, $WCFMmp, $product;

    if( !$product ) return;

    $product_id = $product->get_id();
    $serial = get_post_meta( $product_id, 'serial', true )['post_title'];

    if( $serial ) {
    echo "

    ". $serial ."";
    }
    }, 50 );

    add_action('woocommerce_after_shop_loop_item_title', function() {
    global $WCFM, $WCFMmp, $product;

    if( !$product ) return;

    $product_id = $product->get_id();
    $year = get_post_meta( $product_id, 'year', true )['post_title'];

    if( $year ) {
    echo "

    ". $year ."";
    }
    }, 50 );

    the problem is that I see the artist’s name correctly, but not the serial and year, I only see the first letter or the first number. Where am I wrong?
    Thanks for any help

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter totogigi

    (@totogigi)

    Any help?

    Alberto

    Plugin Support Paul Clark

    (@pdclark)

    Try removing ['post_title'] after the get_post_meta() calls, or run:

    echo '<pre>Content of serial:';
    var_dump( get_post_meta( $product_id, 'serial' ) );
    echo '</pre>';

    To see what is stored in the meta field.

    Pods can be configured on Pods Admin > Settings to filter calls to get_post_meta() , where if the field is a relationship, the function will return an array representing the related post instead of what is actually stored, the post ID.

    If the field is not a relationship, the information returned is likely not an array. The notation ['post_title'] means “find the value for key post_title in the preceeding array”. If the post_meta does not return an array, ['post_title'] will not provide expected results.

    So try

    $serial = get_post_meta( $product_id, 'serial', true );

    …or use the echo / var_dump / echo debug code above to see the exact data type and value stored in serial.

    Thread Starter totogigi

    (@totogigi)

    Hi Paul, removing [‘post_title’] it works, thanks a lot!
    I have another issue: i have set a css class to the three new fields into advanced settings, but i can’t see the class into the console (and the relative custom css doesn’t work). Perhaps must i add something into the functions.php code?
    Regards
    Alberto

    Thread Starter totogigi

    (@totogigi)

    Hi, any help?

    Regards

    Alberto

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