weymeels weymeels - 1 month ago 8
Ajax Question

how put my product->get_image in js

i need to put my $product->get_image in ajax but i don t know how to do

i want to put my $product->get_image(...) to $details = Array("..., "img"=>"$imgL");

here s my code

<?php

define('WP_USE_THEMES', false);
require_once('wp-load.php');
global $qode_options_theme16;
global $wp_query;

$sku=$_POST['id'];

$args = array('post_type' => 'product','meta_value' => $sku);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
$i=0;
while ( $loop->have_posts() ) : $loop->the_post(); global $product;



$imgL=$product->get_image( $size = 'shop_large', $attr = array(), $placeholder = true );
$prix = $product->get_price();
$nom = $product->get_formatted_name();





endwhile;


}

$details = Array("prix"=>"$prix", "nom"=>"$nom", "sku"=>"$sku", "img"=>"$imgL");
echo json_encode($details);

?>


thanks in advance

Answer

Please call the code like this:

 $imgL=$product->get_image( 'shop_large', array(), true );