When i add this code to the thankyou.php of woocommerce everything is working fine (without the hook of course). When i add it to my function.php on my child theme its not working at all.
function lwb_test() {
foreach ( $order->get_items() as $item_id => $item ) {
$product_id = $item->get_product_id();
$order_id = $order->get_id();
$new_product = new WC_Product( $product_id ); // create an object of WC_Product class
$product_attribut = $new_product->get_attribute( 'pa_lieferfrequenz' ); // call get_attribute method
//$product_attribut = '1week';
$date = date('d-m-Y', strtotime("+ $product_attribut "));
add_post_meta( $order_id, 'lwb_pickup_time_email_notification', $date );
}
}
add_action('woocommerce_thankyou', 'lwb_test');