Home › Forums › Quform WordPress › Product Field › Reply To: Product Field
nvm i got chatGPT to write it for me
/* pull product data for claims form */
add_action(‘quform_pre_display_1’, function (Quform_Form $form) {
$element = $form->getElement(‘quform_1_17’);
if ($element instanceof Quform_Element_Multi) {
$options = array();
$args = array(
‘posts_per_page’ => -1,
‘post_type’ => ‘product’,
‘tax_query’ => array(
array(
‘taxonomy’ => ‘product_visibility’,
‘field’ => ‘name’,
‘terms’ => ‘exclude-from-catalog’,
‘operator’ => ‘NOT IN’,
),
),
);
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$product = wc_get_product(get_the_ID());
if ($product) {
$sku = $product->get_sku() ? ‘ (‘ . $product->get_sku() . ‘)’ : ”;
$options[] = array(‘label’ => get_the_title() . $sku, ‘value’ => get_the_title() . $sku, ‘id’ => get_the_ID());
}
}
wp_reset_postdata();
}
$element->setOptions($options);
}
});