Skip to content

Instantly share code, notes, and snippets.

@rayflores
Last active June 9, 2016 19:36
Show Gist options
  • Save rayflores/9a3a162c7db57ba29c7d346db9d41655 to your computer and use it in GitHub Desktop.
Save rayflores/9a3a162c7db57ba29c7d346db9d41655 to your computer and use it in GitHub Desktop.
loop getting two
<?php
$customer_orders = get_posts( array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => wc_get_order_types(),
'post_status' => array_keys( wc_get_order_statuses() ),
) );
$nonPurchaseable = array();
foreach ($customer_orders as $customer_order){
$order = wc_get_order($customer_order->ID);
$refunded = 0;
$purchased_qty = 0;
foreach ($order->get_items() as $item_id => $item){
$variation_id = $item['variation_id'];
if ('try-before-you-buy' === $item['pa_buy-or-try'] ) {
$purchased_qty = (int)$item['qty'];
$refunded = (int)$order->get_qty_refunded_for_item($item_id);
$nonPurchaseable[$variation_id] = array('nonpurchaseable' => $variation_id, 'refunded' => $refunded, 'purchased' => $purchased_qty,'itemid' => $item_id);
}
} // end foreach
} // end foreach
print_r($nonPurchaseable);
foreach ($nonPurchaseable as $npKey => $npValue ){
$amount = $npValue['purchased'] - $npValue['refunded'];
if ($amount > 0){
$non_purchasable = $np_id['nonpurchaseable'];
print_r($amount . '-' . $np_id['itemid'] . '<br/>');
if ( $non_purchasable ) {
$purchasable = false;
}
} else {
$purchasable = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment