How to hide Sold Out items?

Shopify Partner
13 0 0

In the product API reference for Shopify, there is a published parameter, which I keep changing to "false", however this does not do anything to hide the desired products.

I have also tried to change the published date to 'null', which does not work and also tried to change this date to a date in the future, which also does not work (i.e. publish it later in the month).

My last attempt, which worked, was to use tags and the Shopify theme files with regex, however this technique does not generalise well to every Shopify theme and only works with debut.

It can't be this hard to make a product sold out using the API!!! Any ideas guys?

0 Likes
Explorer
83 0 23

Hi Kyle,

You can do this by setting the value of published_at to null or empty value

In Python:

product = shopify.Product.find(123456789)
product.published_at = None
product.save()

In Ruby:

product = ShopifyAPI::Product.find(123456789)
product.published_at = nil
product.save

In PHP using cURL:

$data = array(
            'product' => array(
                               'id' => 123456789,                                       
                               'published_at' => '')
          );
$url = "https://$api_key:$api_pass@$store_handle.myshopify.com/admin/products/123456789.json";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($curl);       
curl_close($curl);

 

I hope this helps!

1 Like
Shopify Partner
13 0 0

Thank you very much...and uh...how do I put it back on the store?? Hahahaha

0 Likes
Explorer
83 0 23

Anytime! You can just set that same value as the publish days date in ISO 8601 format and that should make it published again

0 Likes