Skip to content

Instantly share code, notes, and snippets.

@adicuco
Last active July 25, 2018 08:05
Show Gist options
  • Select an option

  • Save adicuco/3cee170c6a63599f1ddd335b37bd9970 to your computer and use it in GitHub Desktop.

Select an option

Save adicuco/3cee170c6a63599f1ddd335b37bd9970 to your computer and use it in GitHub Desktop.
<?php
$user_id = get_current_user_id();
$codes = array();
global $wpdb;
$querystr = "SELECT * FROM wp_wcg_codes";
$wcg_codes = $wpdb->get_results( $querystr, ARRAY_A);
foreach($wcg_codes as $row){
$order_id = $row['order_id'];
$order = wc_get_order( $order_id );
$order_user_id = $order->customer_id;
if($user_id == $order_user_id){
$car = $row['car_brand'] . " " . $row['car_model'];
$subscription_type = $wpdb->get_var("SELECT order_item_name FROM wp_woocommerce_order_items WHERE order_id = $order_id");
$code = $row['code'];
$code_row = array($car, $subscription_type, $code);
$codes[] = $code_row;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment