Skip to content

Instantly share code, notes, and snippets.

@denchev
Created June 16, 2016 05:53
Show Gist options
  • Save denchev/58d79661dd3b760f033f2d185bb6b977 to your computer and use it in GitHub Desktop.
Save denchev/58d79661dd3b760f033f2d185bb6b977 to your computer and use it in GitHub Desktop.
Get a list of all WooCommerce orders that have fees negative applied.
<?php
/**
* Get a list of all WooCommerce orders that have negative fees applied.
* Installation: Just put it in your root folder (where wp-config.php is). Execute the file /fee-orders.php.
*
*/
require_once "wp-load.php";
function get_all_orders_with_negative_fees() {
global $wpdb, $table_prefix;
$query = "SELECT items.order_id FROM `" . $table_prefix . "woocommerce_order_itemmeta` itemmeta INNER JOIN `" . $table_prefix . "woocommerce_order_items` items ON items.order_item_id = itemmeta.order_item_id WHERE itemmeta.meta_key = '_line_subtotal' AND itemmeta.meta_value < 0";
$results = $wpdb->get_results($query, OBJECT);
return $results;
}
$orders = get_all_orders_with_negative_fees();
?>
<ul>
<?php
foreach($orders as $order) :
$edit_url = sprintf('/wp-admin/post.php?post=%d&action=edit', $order->order_id);
?>
<li><a href="<?php echo $edit_url; ?>" target="_blank">Edit order #<?php echo $order->order_id ?></a></li>
<?php endforeach ?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment