woocommerce update products
-
Hi everyone.
I need Help to add a function into “function.php” file in my site, for woocommerce update products from an “External API” (it is as a link to a source that works in POSTMAN OR INSOMNIA very well) that I already have.
I add this code into my file, but it didn’t work to me …
// Get Product Data From Accounting Software API
$sku = ‘product_id’;
$url = ‘https://{server-ip}:8080/api/Product?code=’.$sku;// Send Request To API
$request = wp_remote_get($url, array(
‘headers’ => array(‘Content-Type’ => ‘application/json; charset=utf-8’),
‘timeout’ => 120,
‘body’ => array(),
‘method’ => ‘GET’,
));// Check Connect Error
if (is_wp_error($request)) {
return false;
}// Get Body Of Request
$body = wp_remote_retrieve_body($request);
$array = json_decode($body, true);// Return Data
return $array;add_action(‘woocommerce_update_product’, ‘sync_on_product_save’, 10, 1);
function sync_on_product_save($product_id)
{
// Check Product has _SKU
$sku = get_post_meta($product_id, ‘_sku’, true);
if (!empty($sku)) {
// Connect To API
// Update in WooCommerce
}
}Could you help me in this problem?
Thanks of All
Best wishes
Amir.
- The topic ‘woocommerce update products’ is closed to new replies.