检测WooCommerce的“报告”标签是否处于活动状态

时间:2019-07-29 14:29:56

标签: wordpress woocommerce

是否可以知道我是否在woocommerce报告页面中?

我希望仅在用户单击此选项卡时执行该功能

enter image description here

在此标签中具体说明

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;
}`

1 个答案:

答案 0 :(得分:1)

简而言之,您可以尝试一下(已测试:enter image description here):

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

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