Adding author option to [products] woocommerce shortcode

Question

I am trying to modify the [products] shortcode usage:

https://docs.woocommerce.com/document/woocommerce-shortcodes/#section-11

What I am looking was passing the author id from short code e.g [products author=2] to the query.

With the reference of:
https://wordpress.org/support/topic/adding-a-special-product-attribute-to-the-products-shortcode/

But the sample was a true/false parameter to trigger the $query_args change, seems it’s not exactly my goal. And the function below is the only part I can put into use.

function htdat_woocommerce_shortcode_products_query( $query_args, $attributes ) {       
$query_args = array(
   //Receive the id//'author'    => '1',
   'post_status'    => 'publish',
   'post_type'      => 'product',
   'post_per_page'      => 12,
   );   
   
  return $query_args;
}
add_filter( 'woocommerce_shortcode_products_query', 'htdat_woocommerce_shortcode_products_query', 10, 2 );

If anyone could help, thank you.

0
Cwkin7 2 months 0 Answers 13 views 0

Leave an answer