skip to Main Content

I am using ACF to add fields to my vendors’ dashboard profile pages. I currently have a test ACF field loading the field from only the WP Admin profile page on all the vendors’ product listing page using this simple hook in my child theme’s functions.php:

add_action( 'woocommerce_archive_description', 'vendor_profile', 7 );

function vendor_profile() { ?>
    <?php if(get_field('founded_on')) { ?>

        <?php the_field('founded_on'); ?>

    <?php }
}

Perhaps I’m pulling the wrong hook, but I can’t seem to find the right hook in the Product Vendor frontend page.

I need help customizing it so that when you are on a vendor’s product page, it pulls the ACF fields from that particular vendor’s profile. Currently, it partially works; however it only pulls the WP main admin’s data for all the different vendors’.

I know there is a way to pull the vendor’s ID for each particular vendor’s page and have it load their data for their page, but my php knowledge is very limited. I usually just hunt for existing code and tweak it. Unfortunately I haven’t found any solutions that have worked, and this is the closest I’ve come to getting custom fields to work on a vendor’s page.

Or if anyone can point me to a better solution to allow me to create customer fields for a vendor to fill out that will be loaded on their front end page, that would be great. I’ve tried Nicola Mustone’s solution ( here ), which would have been perfect, except I couldn’t get it to load the new custom fields on the vendor’s store profile form page, nor have it load the fields into that vendor’s storefront page. Based on comments, it only shows up for the site’s Admin and only they can edit it. There’s no visible way to have it load on the storefront, which defeats the purpose.

2

Answers


  1. I imagine that the providers are users with a certain level within the WordPress system?

    Considering that this is your case, the ACF fields need some additional parameters to become visible:

    $post_id = false; // current post
    $post_id = 1; // post ID = 1
    $post_id = "user_2"; // user ID = 2
    $post_id = "category_3"; // category term ID = 3
    $post_id = "event_4"; // event (custom taxonomy) term ID = 4
    $post_id = "option"; // options page
    $post_id = "options"; // same as above
    
    $value1 = the_field( 'my_field', $post_id );
    $value2 = get_field( 'my_field', $post_id );
    

    take some examples found in the ACF documentation, but in your particular case you have to pass the user’s ID

    the_field('founded_on', 'user_' . $user->ID );
    echo get_field('founded_on', 'user_' . $user->ID );
    
    

    function documentation the_field()

    Login or Signup to reply.
  2. You need to pull the user ID of the user and then use the format user_{$user->ID} for the post ID as the second parameter of the ACF field.

    If I understand your question, then this should work.

    add_action( 'woocommerce_archive_description', 'vendor_profile', 7 );
    
    function vendor_profile() {
        $user = wp_get_current_user();
        if ( get_field( 'founded_on', 'user_' . $user->ID ) ) {
            the_field( 'founded_on', 'user_' . $user->ID );
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search