$api_response = wp_remote_post( 'http://localhost/ecler/wp-json/wc/v3/products', array(
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( 'ЛОГИН:ПАРОЛЬ' )
),
'body' => array(
'name' => 'My test2', // product title
'status' => 'publish', // product status, default: publish
'categories' => array(
array(
'id' => 15 // each category in a separate array
),
// array(
// 'id' => 10
// )
),
'regular_price' => '9.99' // product price
// more params http://woocommerce.github.io/woocommerce-rest-api-docs/?shell#product-properties
)
) );
$body = json_decode( $api_response['body'] );
//print_r( $body );
if( wp_remote_retrieve_response_message( $api_response ) === 'Created' ) {
echo 'The product ' . $body->name . ' has been created';
}
print_r( $body );
// print_r( $api_response );
<?php
$args = array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
);
$product_categories = get_terms( $args );
$count = count($product_categories);
if ( $count > 0 ){
foreach ( $product_categories as $product_category ) {
$thumbnail_id = get_woocommerce_term_meta( $product_category->term_id, 'thumbnail_id', true );
echo '<div class="col-md-6 col-sm-12 col-xs-12">';
echo '<article class="type-post">';
echo '<div class="entry-cover" style="width: 388px; height: 295px;">';
echo '<a href="' . get_term_link( $product_category ) . '"><img style="background-image: url('. wp_get_attachment_url( $thumbnail_id ) .')!important;background-size: 100%;background-repeat: no-repeat;background-size: cover; width: 100%; height: 100%;" /></a>';
echo '</div>';
echo '<div class="entry-block">';
echo '<div class="entry-title">';
echo '<a href="' . get_term_link( $product_category ) . '" title="' . $product_category->name . '"><h3>' . $product_category->name . '</h3></a>';
echo '</div>';
echo '<hr>';
echo '<div class="entry-content">';
echo '<p>' . $product_category->description . '</p>';
echo '</div>';
echo '</div>';
echo '</article>';
echo '</div>';
}
}
?>