WooCommerce REST API Custom Fields

后端 未结 2 1891
轮回少年
轮回少年 2021-02-08 04:54

Is it possible to access custom fields for orders, products, customers via WooCommerce REST API? If not natively, then what plugins or workarounds or hacks are out there that wo

2条回答
  •  南笙
    南笙 (楼主)
    2021-02-08 05:45

    As mentioned in the comment after WooCommerce creates an order via the API it will fire woocommerce_api_create_order hook, you can make use of it.

    Add the following code to your theme's functions.php file

    add_action( 'woocommerce_api_create_order', 'my_woocommerce_api_create_order', 10, 2);
    
    function my_woocommerce_api_create_order( $order_id, $data ) {
    
         // $data contains the data was posted, add code to extract the required
         // fields and process it as required
    
    }
    

    Similarly look at the code in plugins/woocommerce/includes/api/*.php files, find the suitable action or filter hook for the end point and use it.

提交回复
热议问题