wordpress - 检测 WooCommerce 报告选项卡是否处于活动状态
问题描述
是否有功能可以知道我是否在 woocommerce 报告页面中?
我希望仅在用户单击此选项卡时执行该功能
在此选项卡中具体说明
http://localhost/zumra/wordpress/wp-admin/admin.php?page=wc-reports&tab=reports
当我在页面`add_filter(
'woocommerce_admin_reports', 'add_report_tab' );
function add_report_tab( $reports ) {
$orders = wc_get_orders( array('limit' => -1, 'type' => 'shop_order') );
// Get Orders With Discount on Them
foreach( $orders as $order ){
if (sizeof($order->get_used_coupons()) > 0) {
$order_data = $order->get_data(); // The Order data
$discounted_orders .=
'<tr><td>' . $order->get_order_number() . '</td>' .
'<td>' . $order->get_status() . '</td>' .
'<td>' . $order->get_date_created()->date('Y-m-d H:i:s') . '</td>' .
'<td>' . $order->get_total() . '</td>' .
'<td>' . $order->get_billing_first_name() . '</td>' .
'<td>' . $order->get_billing_email() . '</td>' .
'<td>' . $order->get_billing_phone() . '</td>' .
'<td>' . $order->get_total_discount() . '</td>' .
'<td>' . $order_payment_method = $order_data['payment_method_title'] . '</td></tr>';
}
}
$reports['reports'] = array(
'title' => __( 'Zumra', 'woocommerce' ),
'reports' => array(
"sales_by_code" => array(
'title' => __( 'Discounted Orders', 'woocommerce' ),
'description' => '<table id="hm_sbp_table" style="width:100%; text-align: center;">
<tr>
<th>#</th>
<th>Status</th>
<th>Creation Date</th>
<th>Total</th>
<th>Customer Username</th>
<th>Customer E-Mail</th>
<th>Customer Phone</th>
<th>Total Discount</th>
<th>Payment Method</th>
</tr>' . $discounted_orders . '<button type="submit" id="button-a" class="button-primary" name="hm_sbp_download" value="1" return true;">Download Report</button>' ,
'hide_title' => false,
'callback' => '',
)
return $reports;
}`
解决方案
//define the wc_admin_reports_path callback
function filter_wc_admin_reports_path( $reports_class_wc_report_name_php, $name, $class ) {
//run your code here
return $reports_class_wc_report_name_php;
};
//add the filter
add_filter( 'wc_admin_reports_path', 'filter_wc_admin_reports_path', 10, 3 );
更好的过滤器:
// define the woocommerce_reports_charts callback
function filter_woocommerce_reports_charts( $reports ) {
echo "test<br>";
echo "test 1<br>";
echo "test 2<br>";
echo "test 3<br>";
return $reports;
};
// add the filter
add_filter( 'woocommerce_reports_charts', 'filter_woocommerce_reports_charts', 10, 1 );
我希望这有帮助。祝你有美好的一天。
推荐阅读
- javascript - 在对象中传递 JSX 以响应子组件?
- docker - CentOS 7 上的 Docker - DNS 在容器中不起作用
- r - 使用此符号重写代码百分比的另一种方法 >
- javascript - XMLHttpRequest javascript
- flutter - “int”类型不是“double”类型颤振的子类型
- apache-spark - Spark中内部连接的分区数是如何计算的?
- apache-spark - 排序对在火花中连接两个数据框有什么影响
- php - 在 PHP 中删除部分字符串
- c++ - 为 Winapi 制作 typedef 时无法将 INVALID_HANDLE_VALUE 分配给 constexpr HANDLE
- bash - 检查 getops 参数是否属于某种类型