Wordpress教程 2024年09月20日
0 收藏 0 点赞 254 浏览 1144 个字

// 为 Legacy CPT-based 订单添加自定义列
add_filter('manage_edit-shop_order_columns', 'wprs_add_custom_order_columns');

// 为 HPOS-based 订单添加自定义列
add_filter('manage_woocommerce_page_wc-orders_columns', 'wprs_add_custom_order_columns');

function wprs_add_custom_order_columns($columns) {
    // 在“总计”列之前添加自定义列
    $columns = array_slice($columns, 0, 4, true) // 4 列之前
    + array(
        'order_products' => __('购买产品', 'woocommerce') // 自定义列标题
    )
    + array_slice($columns, 4, NULL, true);

    return $columns;
}

// 为 Legacy CPT-based 订单显示自定义列数据
add_action('manage_shop_order_posts_custom_column', 'wprs_populate_custom_order_columns', 25, 2);

// 为 HPOS-based 订单显示自定义列数据
add_action('manage_woocommerce_page_wc-orders_custom_column', 'wprs_populate_custom_order_columns', 25, 2);

function wprs_populate_custom_order_columns($column_name, $order_or_order_id) {
    // 兼容 Legacy CPT-based 订单
    $order = $order_or_order_id instanceof WC_Order ? $order_or_order_id : wc_get_order($order_or_order_id);

    if ('order_products' === $column_name) {
        $items = $order->get_items();
        if (!is_wp_error($items)) {
            foreach ($items as $item_id => $item) {
                echo esc_html($item->get_quantity()) . ' × <a href="' . esc_url(get_edit_post_link($item->get_product_id())) . '" rel="external nofollow" >' . esc_html($item->get_name()) . '</a><br />';
            }
        }
    }
}

 

微信扫一扫

支付宝扫一扫

版权: 转载请注明出处:https://www.mizhanw.com/blog/4954.html

相关推荐
WordPress去除/禁止后台侧栏插件-主题-版本更新提示
今天使用了张戈修改的nginx-help插件修改版,官方版并无自动重启功能,因此不能更新。但是这WordPress后台一直有更新提示,这可真…
日期:2024-12-30 点赞:0 阅读:44
WordPress网站js防扒代码-禁止右键/F12/调试自动关闭窗口
网站防扒老生常谈了,今天老白博客@老白也给大家分享一下从网上看到的“WordPress网站防扒代码/禁止F12调试教程-以7b2主题为例” …
日期:2024-12-30 点赞:0 阅读:59
WordPress优化加速之导航菜单栏缓存Menu Cache
今天老白博客@老白给大家分享又一个WordPress优化加速教程:“导航菜单栏缓存WordPress插件Menu Cache”。我们都知道数…
日期:2024-12-30 点赞:0 阅读:45
2024基于网站性能测试的WordPress优化指南
老白博客WordPress优化高级教程:在如今5G遍地走,千兆多如狗的高速网络时代,如果你访问网站,还出现转圈圈的情况,那么你十有八九是要关…
日期:2024-12-30 点赞:0 阅读:50
WP网站用户行为监测回放插件nicen-replay
在数字营销的世界里,了解用户行为是提升用户体验和转化率的关键。老白推荐一款炫酷的WordPress插件:nicen-replay 。它能够让…
日期:2024-12-30 点赞:0 阅读:48
2024新WordPress缓存插件atec Cache APCu
WordPress插件atec Cache APCu 是一款2024年才投入使用的的高效缓存插件,与其他内存缓存选项(如 Redis 和 M…
日期:2024-12-30 点赞:0 阅读:65
发表评论
暂无评论

还没有评论呢,快来抢沙发~