I am trying to create a IF condition with product_id by getting it from order_id, when a new order is placed.
I tried it like:
add_action('woocommerce_new_order', 'wc_send_order_to_mypage');
function wc_send_order_to_mypage($order_id)
{
$order = wc_get_order( $order_id );
foreach ($order->get_items() as $item_key => $item )
{
$product_id = $item->get_product_id();
if ( $product_id == 29 ) {
$url = "https://www.abc.de";
}
}
//do something with $url
}
But each time when I want to place the order, woocommerce is giving me the error message "Internal Server error".
I tried to use code from this answer but somehow it does not work: How to get WooCommerce order details
What is not working here? Thank you very much for your help.
Best regards,
Thomas