JSFiddle - React, Tailwind, and code Playground
by AshThakur
HTML
<pre class="theCode" >function flatbike_get_product_detail() {
$product_id = $_POST['product_id'];
$args = array(
'post_type' =&gt; 'product',
'p' =&gt; $product_id,
);
$query = new WP_Query( $args );
if ($query-&gt;have_posts()) :
while ($query-&gt;have_posts()) : $query-&gt;the_post();
wc_get_template_part( 'content', 'single-product' );
endwhile;
else :
echo "There were no posts found";
endif;
wp_reset_query();
wp_die();
}
add_action('wp_ajax_get_product_detail', 'flatbike_get_product_detail');
add_action('wp_ajax_nopriv_get_product_detail', 'flatbike_get_product_detail');</pre>