by Anonymous » 23 Dec 2024, 15:32
Ich verwende Woocommerce-Produktdaten mithilfe der API PHP abrufen, aber es funktioniert nicht richtig.
Bitte finden Sie den Code unten.
Jede Hilfe wäre dankbar.
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
//Checking if any error occured while connecting
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}
//creating a query
$stmt = $conn->prepare("SELECT p.ID,p.post_title,p.post_status,p.post_name,pp.min_price,pp.max_price,
pi.meta_value FROM `wp_posts` p INNER JOIN `wp_wc_product_meta_lookup` pp ON pp.product_id = p.ID
INNER JOIN `wp_postmeta` pi ON pi.post_id=p.ID where p.post_status='publish' and pi.meta_key ='_wp_attached_file'
and `p.post_type`='product'GROUP BY p.ID;");
//executing the query
$stmt->execute();
//binding results to the query
$stmt->bind_result($post_id,$post_title, $post_status, $post_name,$min_price, $max_price , $meta_value);
$courses = array();
//traversing through all the result
while($stmt->fetch()){
$temp = array();
$temp['post_id'] = $post_id;
$temp['post_title'] = $post_title;
$temp['post_status'] = $post_status;
$temp['post_name'] = $post_name;
$temp['min_price'] = $min_price;
$temp['max_price'] = $max_price;
$temp['meta_value'] = $meta_value;
array_push($courses, $temp);
}
//echo count($courses);
//displaying the result in json format
echo json_encode($courses);
Ich verwende Woocommerce-Produktdaten mithilfe der API PHP abrufen, aber es funktioniert nicht richtig.
Bitte finden Sie den Code unten.
Jede Hilfe wäre dankbar.
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
//Checking if any error occured while connecting
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}
//creating a query
$stmt = $conn->prepare("SELECT p.ID,p.post_title,p.post_status,p.post_name,pp.min_price,pp.max_price,
pi.meta_value FROM `wp_posts` p INNER JOIN `wp_wc_product_meta_lookup` pp ON pp.product_id = p.ID
INNER JOIN `wp_postmeta` pi ON pi.post_id=p.ID where p.post_status='publish' and pi.meta_key ='_wp_attached_file'
and `p.post_type`='product'GROUP BY p.ID;");
//executing the query
$stmt->execute();
//binding results to the query
$stmt->bind_result($post_id,$post_title, $post_status, $post_name,$min_price, $max_price , $meta_value);
$courses = array();
//traversing through all the result
while($stmt->fetch()){
$temp = array();
$temp['post_id'] = $post_id;
$temp['post_title'] = $post_title;
$temp['post_status'] = $post_status;
$temp['post_name'] = $post_name;
$temp['min_price'] = $min_price;
$temp['max_price'] = $max_price;
$temp['meta_value'] = $meta_value;
array_push($courses, $temp);
}
//echo count($courses);
//displaying the result in json format
echo json_encode($courses);