1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| $arr_categories = [
100 => 'VANAGON',
101 => 'AUDI',
102 => 'MERCEDEZ',
103 => 'VOLKS',
];
$checked_arr_type = $_POST['checkbox_categories'] ?? [];
$full_data = ['categories' => []];
foreach ($checked_arr_type as $category_id) {
if (!isset($arr_categories[$category_id])) { // Contrôle de cohérence
// Si ID inconnu, on ignore
continue;
}
$full_data['categories'][] = [
'id' => $category_id,
'name' => $arr_categories[$category_id],
'slug' => $arr_categories[$category_id],
];
}
$curl_postfields = json_encode($full_data);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://".$url."/wp-json/wc/v3/products?consumer_key=".$consumer_key."&consumer_secret=".$consumer_secret."&name=".$name."&type=simple®ular_price=".$regular_price."&description=".$description."&sku=".$sku."&manage_stock=true&backorders_allowed=true&backorders=notify&stock_quantity=0 ",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"'.$curl_postfields.'",
"weight": "'.$weight.'",
"dimensions": {
"length": "'.$length.'",
"width": "'.$width.'",
"height": "'.$height.'"
},
"meta_data": [
{
"key": "model_space",
"value": "'.$model_space.'"
},
{
"key": "model_horizontal",
"value": "'.$model_horizontal.'"
},
{
"key": "model_dot",
"value": "'.$model_dot.'"
},
{
"key": "model_oem",
"value": "'.$model_oem.'"
}
]
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Cookie: weglot_allow_private=1'
),
));
$response = curl_exec($curl); |
Partager