• Resolved zcomputers

    (@zcomputers)


    I have an application which creates and updates products via the woocommerce API v1.

    I am trying to intercept the incoming data and modify it before it is processed by the woo API using woocommerce_rest_prepare_product, but I cannot modify any of the data values.

    Code I am using in functions.php:

    
    add_filter( 'woocommerce_rest_prepare_product', 'modify_products_api_data', 90, 2 );
    function modify_products_api_data( $response, $post ) {
        $response->data['name'] = 'modified';
        return $response;
    }
    

    I would expect this to change the post title to “modified” but it doesnt do anything at all.

    I have also tried with “woocommerce_rest_prepare_product_object”, however as I understand it because the application is using v1 it should be “woocommerce_rest_prepare_product” which is now deprecated in v2+.

    Anyone have any suggestions how I can intercept submitted data and be able to modify it before products are created or updated? So for example to overwrite the name of the product, or amend its description text?

    Thanks guys, spent many hours on this already and I’m not getting anywhere.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Daniyal Ahmed (a11n)

    (@daniyalahmedk)

    Hi there,

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Best,

    Thread Starter zcomputers

    (@zcomputers)

    Looks like nobody on here has any experience with this.

    So for anyone looking for a solution to the same problem; I simply couldn’t find one other than to attack the problem from a completely different angle…

    So now instead of intercepting the incoming data on API v1, I now instead hook into woocommerce_after_product_object_save to perform the actions I want to after the product has been inserted into wordpress.

    It’s far from ideal and somewhat hacky as it leaves a mess of redundant taxonomy behind… So if someone has any further information surrounding capturing and modifying incoming submissions on API v1 with woocommerce_rest_prepare_product / woocommerce_rest_prepare_product_object then please feel free to chime in and save the day.

    Thanks.

    Hi @zcomputers

    Looks like nobody on here has any experience with this.
    So for anyone looking for a solution to the same problem; I simply couldn’t find one other than to attack the problem from a completely different angle

    You are likely to get helpful inputs by posting your query in the development-oriented channels suggested above. Please try making use of the above resources.

    Cheers

    Thread Starter zcomputers

    (@zcomputers)

    Hi @margaretwporg

    Thanks for the suggestion however I don’t use Facebook due to privacy concerns surrounding the companies collection and handling of personal information, and I do not have access to the Slack application. Hence why I am posting on this public forum!

    Cheers

    Hi @zcomputers

    I don’t use Facebook due to privacy concerns surrounding the companies collection and handling of personal information, and I do not have access to the Slack application

    We can understand.

    But please be informed that support for custom coding is beyond the scope of support we are able to provide in this forum. This particular forum is for questions that are related to the WooCommerce core features.

    If you can get access to the Slack application, that may probably be helpful.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Intercept and modify product data sent to woo API V1’ is closed to new replies.