Hook into Woocommerce restock refunded item - add custom export value
Budget: €30 – €250 EUR
I set up a shop for a client with woocommerce. I have to export the order once a day to the ERP system of the client and of course the refunded products/orders too. There is the case that, when I do a refund of a product I can choose that the product get refunded and the stock stays the same (product goes into the trash) or the stock goes up (the product gets back into the selling). "see attached picture"
So now I export the orders by the plugin "WP All Export". The plugin shows a lot of possabilities to create/fill the export XML file but I need something else then the standard export fields:
What I would like the plugin should do is, if the checkbox is unchecked and there shouldn`t be a restock, the letter "M" should be given out in the export table. When the checkbox is checked and there is a restock, the letter "R" should be given to the table.
The support of the plugin (which is very nice) gave me following answer to my problem:
Unfortunately, there is no straightforward way to get this value as this value not stored as a post meta for the order. To get this value, you'd need to hook into one of these:
do_action( 'woocommerce_restock_refunded_item', $product->get_id(), $old_stock, $new_stock, $order, $product );
Or this:
if ( ! apply_filters( 'woocommerce_can_restock_refunded_items', true, $order, $refunded_line_items ) ) { return; }
And save your own custom itemmeta to retrieve during the export. Unfortunately, I don't have any example code to share for this.
So I am asking you girls and guys how this hook has to look like that exports me the letters into the table. Maybe this is a help for the solution.. the plugin can add a custom field for the table: "see attached picture"
I think that is not a real huge work for someone who knows Woocommerce ;)
So now I export the orders by the plugin "WP All Export". The plugin shows a lot of possabilities to create/fill the export XML file but I need something else then the standard export fields:
What I would like the plugin should do is, if the checkbox is unchecked and there shouldn`t be a restock, the letter "M" should be given out in the export table. When the checkbox is checked and there is a restock, the letter "R" should be given to the table.
The support of the plugin (which is very nice) gave me following answer to my problem:
Unfortunately, there is no straightforward way to get this value as this value not stored as a post meta for the order. To get this value, you'd need to hook into one of these:
do_action( 'woocommerce_restock_refunded_item', $product->get_id(), $old_stock, $new_stock, $order, $product );
Or this:
if ( ! apply_filters( 'woocommerce_can_restock_refunded_items', true, $order, $refunded_line_items ) ) { return; }
And save your own custom itemmeta to retrieve during the export. Unfortunately, I don't have any example code to share for this.
So I am asking you girls and guys how this hook has to look like that exports me the letters into the table. Maybe this is a help for the solution.. the plugin can add a custom field for the table: "see attached picture"
I think that is not a real huge work for someone who knows Woocommerce ;)