我想要得到退款的交易数据与产品的所有细节,如产品id和退款的数量。
是否可以以数组格式获取所有详细信息?
发布于 2014-09-30 19:07:59
首先,你的问题是+1。从WooCommerce 2.2开始,如果您的支付网关允许,WooCommerce将直接支持退款。退款方式有两种:通过支付网关自动退款或手动退款。有关更多信息,请参阅页面:http://docs.woothemes.com/document/woocommerce-refunds/。如果您想获取退款详情,请使用此页面中列出的方法:http://docs.woothemes.com/wc-apidocs/class-WC_Order.html。
发布于 2015-07-07 04:46:32
我还没有找到一种合适的方法来使用内置的WooCommerce类(is...close中的报表)来实现这一点。我深入研究了WooCommerce用来拉取报告数据的查询,并提出了以下内容来获得退款订单项目:
<?php
global $wpdb;
// TODO: time zones, better ranges, etc.
$date_start = new DateTime('-7 days');
$date_end = new DateTime('now');
$sql_reports_refunded = <<<SQL
SELECT
product_id.meta_value AS product_id,
variation_id.meta_value AS variation_id,
order_items.order_item_name AS product_name,
product_sku.meta_value AS product_SKU,
variation_sku.meta_value AS variation_SKU,
SUM(quantity.meta_value) AS quantity
FROM {$wpdb->prefix}posts AS posts
LEFT JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_items.order_id
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS quantity ON order_items.order_item_id = quantity.order_item_id AND quantity.meta_key = '_qty'
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS variation_id ON order_items.order_item_id = variation_id.order_item_id AND variation_id.meta_key = '_variation_id'
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS product_id ON order_items.order_item_id = product_id.order_item_id AND product_id.meta_key = '_product_id'
LEFT JOIN {$wpdb->prefix}postmeta AS product_sku ON product_id.meta_value = product_sku.post_id AND product_sku.meta_key = '_sku'
LEFT JOIN {$wpdb->prefix}postmeta AS variation_sku ON variation_id.meta_value = variation_sku.post_id AND variation_sku.meta_key = '_sku'
WHERE posts.post_status IN ('wc-completed', 'wc-refunded')
AND posts.post_type IN ('shop_order_refund')
AND posts.post_date >= '{$date_start->format('Y-m-d')}'
AND posts.post_date < '{$date_end->format('Y-m-d')}'
AND order_items.order_item_type = 'line_item'
AND order_items.order_id IS NOT NULL
GROUP BY product_id, variation_id
ORDER BY quantity DESC, product_name ASC
SQL;
return $wpdb->get_results($sql_reports_refunded);
?>它与WC用来获取各种报告数据的工具非常接近。在我写这篇文章的时候,我建议,如果你需要来自WooCommerce的自定义报告,你可能需要自己通过自定义查询或WC_Admin_Report中的get_order_report_data来完成。
发布于 2016-04-29 03:29:17
我知道这几乎是几年前的事情了,但这是我发现的关于获得退款数据的唯一讨论。Anoop的答案是正确的,但为了更好地澄清,WC_Order的退款方法应该返回what's neededL https://docs.woothemes.com/wc-apidocs/class-WC_Order.html
例如:我正在建立一个事件式产品的“与会者”列表。参会者的数量取决于该产品/活动的采购订单数量。数量退款实际上不会调整订单的数量,而是将退还的商品数量存储在这里:
WC_Order()->get_item_count_refunded();一般退款详情可通过以下方式获取:
WC_Order()->get_refunds();https://stackoverflow.com/questions/26118745
复制相似问题