Здравствуйте, как цикл заставить работать внутри массива?
<?php
$arr_tovar = $result->products;
$api_response = wp_remote_post( $url_site.'/wp-json/wc/v3/products', array(
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( 'admin:123123123' )
),
/*
'body' => array(
'name' => 'My test2',
'status' => 'pending',
'categories' => array(
array(
'id' => 15
)
),
'regular_price' => '9.99'
// more params http://woocommerce.github.io/woocommerce-rest-api-docs/?shell#product-properties
)*/
for ($i = 1; $i <= count($result->products); $i++)
{
$hi_products[$i] = array(
'name' => $arr_tovar[$i]->name,
'status' => 'pending',
'categories' => array(
array(
'id_iiko_категории' => $arr_tovar[$i]->productCategoryId
)
),
'regular_price' => $arr_tovar[$i]->price );
}
) );
$body = json_decode( $api_response['body'] );
if( wp_remote_retrieve_response_message( $api_response ) === 'Created' ) {
echo 'The product ' . $body->name . ' has been created';
}
print_r( $body );
?>