首页 > 解决方案 > 检测 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;
}`

标签: wordpresswoocommerce

解决方案


简单地说,你可以试试这个(测试:)在此处输入图像描述

//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 ); 

我希望这有帮助。祝你有美好的一天。


推荐阅读