• Resolved slimschip

    (@slimschip)


    Hi,

    I am in the process of creating a program that talks to the WooCommerce REST API and I am trying to get the EAN data stored by this pluging via the “products” endpoint.

    It it possible to get this data using the REST API and can you tell me how?

    Kind regrads,

    Martijn

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author Emanuela Castorina

    (@kreamweb)

    Hello,
    the EAN code it is a custom field this is the name ‘_wpm_gtin_code’
    You should search how get custom fields with WooCommerce Rest API.

    Thread Starter slimschip

    (@slimschip)

    Hi Emanuela,

    When I search on how to get custom fields I run into circles and php code I do not understand (I’m a pyhon devoloper), but seem related to the way the php api works and how to handle the return data.

    when I do a get on “products?filter[meta]=true” I do get the “product_meta” but no _wpm_gtin_code, in some places I see that “protected” values (starting with “_”) are not shown.

    I have searched the API docs and tried google before I posted my question to you.

    I try to get the value in the response for a get. thats is all.

    Any hint beyond “search how to get custom fields” would be highly appreciated.

    Kind regards,

    Martijn

    • This reply was modified 6 years, 1 month ago by slimschip.
    Plugin Author Emanuela Castorina

    (@kreamweb)

    I’ve never worked with Rest API but I found this that you can try

    add_filter( 'woocommerce_rest_prepare_product', 'custom_products_api_data', 90, 2 );
    function custom_products_api_data( $response, $post ) {
    
    // retrieve a custom field and add it to API response
    $response->data['ean_code'] = get_post_meta( $post->ID, '_wpm_gtin_code', true );
    
    return $response;
    }

    https://wordpress.stackexchange.com/questions/308591/woocommerce-product-custom-field

    Thread Starter slimschip

    (@slimschip)

    I have found that one too, there is no reference on where to add that code ….

    As said I am not familiar with php development.

    To me the whole issue is with the “_” at the start of “_wpm_gtin_code” as a fieldname in the wp_postmeta as that is a “protected” field. in the first place.

    Martijn

    Plugin Author Emanuela Castorina

    (@kreamweb)

    Put the script in the file functions.php of your theme.

    Thread Starter slimschip

    (@slimschip)

    a bit off-topic, but wouldn’t that be overwitten by an update of the theme? that seems to be the case every time when there is a WC update.

    Plugin Author Emanuela Castorina

    (@kreamweb)

    for the moment you can try, if this script works I’ll add it to the plugin.

    Thread Starter slimschip

    (@slimschip)

    oh cool!

    Thread Starter slimschip

    (@slimschip)

    That did not work, as you scroll down on that page the is a reply from someone telling that and a suggested fix. but:

    I think this is close to what is needed:

    https://developer.www.ads-software.com/rest-api/extending-the-rest-api/modifying-responses/

    I guess the info on this page is for the correct integration with the REST API for getting and adding changing the value.

    It is that I am clueless about WP/WC/php… otherwise I would have hacked the plug-in to see if I could make it work.

    I’m happy to test though as I am familiar with the REST API of WC.

    Martijn

    Plugin Author Emanuela Castorina

    (@kreamweb)

    I made a test,
    I changed the file includes/class.product-gtin-wc.php
    with this code
    https://gist.github.com/kreamweb/0452907d3ad0121a6535eedad2f7a85a

    the ‘ean_code’ is present in the product detail:
    https://nimb.ws/df9tRk

    Let me know!

    Thread Starter slimschip

    (@slimschip)

    It works ! Thank you, I guess an update will just overwrite my hand made changes.

    You are a live saver and deserve a big kiss!

    Plugin Author Emanuela Castorina

    (@kreamweb)

    I’ll commit that file in the new release so you won’t lost these changes.
    This can be useful to other developer.

    If you have two minutes could you leave a review for this plugin?
    https://www.ads-software.com/support/plugin/product-gtin-ean-upc-isbn-for-woocommerce/reviews/

    Thank you!

    Would it be possible to link it also with: https://your-site.com/wc-api/v2/products? Our cash register system works with this.

    Thanks in advance!

    Hi,

    Do you know if the issue with using API to update the GTIN for the Product GTIN (EAN, UPC, ISBN) for WooCommerce plugin got resolved?

    I’m trying to update the GTIN using API Post Calls and can’t seem to figure out why i can’t update using that method, please let me know if it was fixed and how to resolve it on my end?

    Thanks.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘WooCommerce API’ is closed to new replies.