skip to Main Content

Is it possible to use custom field value for product name when using Woocommerce REST API?
I have added a key for DHL in REST API settings. Now I want to add a custom field on every product (it will be short names) so it will be used when sending API request for DHL, instead of original product names.

2

Answers


  1. You can use the SKU field of the product.

    WooCommerce API allows you to GET products via the SKU field for example – add to your GET products (without a product id) params &sku=DD1213 and your will receive said product – I don’t recall if Woocommerce allows SKU duplicates but if it does… than don’t! 🙂

    So that means you can GET a product via SKU query example (PHP Curl):

    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => 'https://www.yourwebsite.com/wp-json/wc/v3/products?consumer_key=somekind_of_key&consumer_secret=your_secret&sku=DD1213',
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'GET',
    ));
    
    $response = curl_exec($curl);
    
    curl_close($curl);
    echo $response;
    

    This is only for the GET purposes – for updating and others you will need to use the product ID endpoint.

    Login or Signup to reply.
  2. I found a number of other developers with solutions for this on github, here is one, yes I know it is for secondary SKU, but it should be fairly trivial to modify it to cater for a secondary Product Name.

    https://github.com/pmgarman/wc-international-sku

    Add a secondary SKU to products that is used for orders shipping
    outside of the base country of WooCommerce (international orders).

    == Description == Sometimes orders being shipped internationally require shipping a slightly different variation of your product (for
    various legal/regulatory reasons). This plugin will allow for products
    to have two SKUs, one for domestic orders and one for international
    orders. The SKU returned on order items in orders via the API and
    dashboard will be filtered to return the international SKU when the
    shipping address varies from the shop base address

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search