Here is my script :
require('../wp-load.php');
header("Pragma: no-cache");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Expires: 0");
$access = false;
if(isset($_SESSION['stock_control_access'])){
if($_SESSION['stock_control_access'] == "yes"){
$access = true;
}
}
if($access == false){
exit("accessdenied");
}
if(!isset($_GET['item_id'])){
exit("Mauvaise requête");
}
$cat_id = $_GET['item_id'];
wp_set_current_user(null, "user");
$request = new WP_REST_Request('GET', "/wc/v3/products");
$request->set_query_params(["per_page" => "100", "category" => $cat_id]);
$response = rest_do_request($request);
$server = rest_get_server();
$products = $server->response_to_data($response, false);
$output = '';
$output .= "<ul class='product_list' id='{$cat_id}'>" . PHP_EOL;
foreach ($products as $product) {
if($product['type'] == 'simple'){
$output .= "<li class='product' data-id='{$product['id']}' data-type='simple' data-stock='{$product['stock_quantity']}' data-open='closed'><a href='{$product['images'][0]['src']}' target='_blank'><img src='{$product['images'][0]['src']}'></a>{$product['name']}-{$product['id']} $text</li>";
} else {
$output .= "<li class='product' data-id='{$product['id']}' data-open='closed'><a href='{$product['images'][0]['src']}' target='_blank'><img src='{$product['images'][0]['src']}'></a>{$product['name']}-{$product['id']}</li>";
}
$output .= PHP_EOL;
}
$output .= '</ul>';
echo $output;
?>
I'd like to add within the li my custom text with $text. So, i've tried something like this:
if($product['id'] == ('8499' || '5348'|| '5389' || '7331')) {
$text = "test1"
}
if($product['id'] == ('8494' || '5368'|| '5339' || '5331')) {
$text = "test2"
}
With no luck, can someone help me implement these two pieces of code?
Aucun commentaire:
Enregistrer un commentaire