Last active
June 9, 2016 19:36
-
-
Save rayflores/9a3a162c7db57ba29c7d346db9d41655 to your computer and use it in GitHub Desktop.
loop getting two
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
https://gist.github.com/rayflores/9a3a162c7db57ba29c7d346db9d41655#file-twice-loop-php-L27
gives me this: http://screencast.com/t/E3QWKKXp