Show products based on meta query

PHOTO EMBED

Tue Mar 15 2022 14:03:42 GMT+0000 (UTC)

Saved by @zildjianjaxolis #wordpress #php #woocommerce

<?php

add_filter( 'woocommerce_product_query_meta_query', 'show_only_products_with_specific_metakey', 10, 2 );
function show_only_products_with_specific_metakey( $meta_query, $query ) {
    // Only on shop pages
    if( ! is_shop() ) return $meta_query;

    $meta_query[] = array(
        'key'     => '_allowed_user',
        'value'   => get_current_user_id(),
    );
    return $meta_query;
}
content_copyCOPY