How do I modify the main loop of WooCommerce to filter based on a logged in user's ACF field? I have added a new field to the user profile using ACF, it pulls a select list from a product attribute (Vehicle Year). I want to make it so products only show up for the user based on what vehicle year they've chosen. I can't figure out how to modify the loop so no matter what WooCommerce page the customer views it will be filtered to only show products with the attribute that matches the Vehicle Year selected in their user profile.
I added the following code to the archive-products.php page to check for the logged in user. If you have a better idea, I'm open.
if ( is_user_logged_in() ) {
echo 'Welcome, registered user!';
$user = new WP_User(get_current_user_id());
$uid = $user->ID;
$year = get_field("vehicle-year", "user_$uid");
echo $year->name;
}
This helped me confirm I can get the ACF field based on the user logged in.
I know I need something that has something like this, I'm just not sure how to make it replace/attach to the main WooCommerce loop so it's always filtering the products.
'tax_query' => array(
'relation'=>'AND',
array(
'taxonomy' => 'pa_year-2',
'field' => 'name',
'terms' => '1970'
)
)
Appreciate any help you can offer.