WordPress broken after wpdb in functions.php

I am working on a little function in the functions.php of my theme to redirect to a another url and send some data with POST when a user completes a order.
But I need to send the quantities of a item.
When I comment out the wpdb funtion it works and if I uncomment it , it will break the website.

whats wrong ?

add_action( 'template_redirect', 'wc_custom_redirect_after_purchase' ); 
function wc_custom_redirect_after_purchase() {

global $wpdb;
global $wp;
global $woocommerce, $post;
$order = new WC_Order($post->ID);
$order_id = trim(str_replace('#', '', $order->get_order_number()));


//$result = $wpdb->get_results( "SELECT $wpdb-    >woocommerce_order_itemmeta.meta_value FROM $wpdb->woocommerce_order_itemmeta INNER JOIN $wpdb->woocommerce_order_items ON $wpdb->woocommerce_order_itemmeta.order_item_id=$wpdb->woocommerce_order_items.order_item_id WHERE $wpdb->woocommerce_order_itemmeta.meta_key="_qty" AND $wpdb->woocommerce_order_items.order_id=155 " );


$base_url = "http://URL.com/";

$location =  $base_url . "wcq=" . $result ;

if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
              wp_redirect($location);
    exit;
}
}

endif;


Source: wpdb

Leave a Reply