AidenPierce024
AidenPierce024

Reputation: 11

How do I make this custom function for WC WP?

I'm trying to create a custom function for WooCommerce where the function would take an array as an argument and print some products. The array would contain WooCommerce product tags.

<form id="form3" method="POST" action="">
<h4>Concerns</h4>
<div class="container-form">
  <input type="checkbox" name="concern1" checked="checked"
  <?php if (isset($concern1) && $concern1=="dryness") echo "checked";?>
  value="dryness"><div class="checkmark">Dryness</div>
 
</div>

<div class="container-form">
  <input type="checkbox" name="concern2"
  <?php if (isset($concern2) && $concern2=="dullness") echo "checked";?>
  value="male"><div class="checkmark">Male</div>
  <br>
</div>

<div class="container-form">
  <input type="checkbox" name="concern3"
  <?php if (isset($concern3) && $concern3=="other") echo "checked";?>
  value="other"><div class="checkmark">Other</div>
  <br>
</div>

<input type="submit" name="submit" class="submit" value="Submit"/>
 <?php
function pre_r($array){
  echo '<pre>';
  print_r($array);
  echo '</pre>';
}
?>

How do I make the function that would the array as an argument and show products according to those tags?

Upvotes: 1

Views: 62

Answers (1)

mujuonly
mujuonly

Reputation: 11861

// Get products with the "Excellent" or "Modern" tags.
$args = array(
    'tag' => array( 'excellent', 'modern' ),
);
$products = wc_get_products( $args );

Accepts an array: Limit results to products assigned to specific tags by slug.

More details can be found in the official WooCommerce docs

Upvotes: 1

Related Questions