SHARE
TWEET

Dominykas

a guest Sep 21st, 2017 312 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. http://dominykasgel.com/woocommerce-rest-api-import-products-json/
  2.  
  3. Explanation: This allows you import an image to a simple product.
  4.  
  5. Add "image" to products.json file.
  6.  
  7. ------------------------------------------------------------------  
  8.  
  9. {
  10.     "product_id": 100,
  11.     "type": "simple",
  12.     "name": "My product 1",
  13.     "description": "My product description 1",
  14.     "regular_price": 100,
  15.     "manage_stock": 1,
  16.     "stock": 3,
  17.     "weight": 0,
  18.     "has_variations": 0,
  19.     "image": "http://localhost/my-image.png"
  20. },
  21.  
  22. ------------------------------------------------------------------
  23.  
  24. In get_products_and_variations_from_json() function, below this line: if ( $pre_product['type'] == 'simple' ) :
  25.  
  26. Add this code:
  27.  
  28. ------------------------------------------------------------------
  29.  
  30. if ( $pre_product['image'] ) {
  31.     $product[$key]['images'][] = array(
  32.       'src' => (string) $pre_product['image'],
  33.       'position' => 0
  34.     );
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top