Created
June 24, 2020 09:47
-
-
Save webdados/5d433cafa7704198c3dc337c881a6e92 to your computer and use it in GitHub Desktop.
Add WooCommerce order meta if there's a product on backorder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'woocommerce_checkout_update_order_meta', function( $order_id, $data ) { | |
foreach ( WC()->cart->cart_contents as $item ) { | |
if ( $item['data']->is_on_backorder() ) { | |
$order = wc_get_order( $order_id ); | |
$order->update_meta_data( '_has_backorder_product', 1 ); | |
$order->save(); | |
break; | |
} | |
} | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment