HPOS启用后WooCommerce批量操作生成Dompdf PDF功能失效问题求助
HPOS启用后WooCommerce批量操作生成Dompdf PDF功能失效问题求助
各位好,我最近碰到个棘手的问题:在WooCommerce后台通过批量操作生成DomPdf格式的订单PDF,没启用HPOS(高性能订单存储)之前一切正常,但开启HPOS之后这个功能就完全失效了。
目前能确认的状态:
- 自定义的批量操作选项已经成功加到了订单页面的下拉菜单里
- 执行操作后,管理员通知也能正常弹出(显示“PDF downloaded”)
- 但核心的PDF文件下载完全没反应,浏览器没有任何下载提示
以下是我实现这个功能的完整代码,麻烦帮忙排查下问题出在哪:
$add_custom_download_action = function ( array $bulk_actions ) { return array_merge( $bulk_actions, [ 'custom_download_action' => 'Perform custom download action' ] ); }; $custom_download_action_handler = function ( string $redirect_to, string $action, array $post_ids ) { if ( $action !== 'custom_download_action' ) return $redirect_to; // Exit require WPO_WCPDF()->plugin_path() . '/vendor/autoload.php'; $dompdf = new Dompdf\Dompdf(); $dompdf->set_paper( 'letter' , 'landscape' ); $dompdf->loadHtml($content); //this variable is build up as an html string $dompdf->render(); $dompdf->stream('orders.pdf',array("Attachment"=>0)); return add_query_arg( 'bulk_action', 'custom-download-action-notice', $redirect_to ); }; $custom_download_action_notice = function () { if ( isset( $_GET['bulk_action'] ) && 'custom-download-action-notice' === $_GET['bulk_action'] ) { print '<div class="updated" style="border-left-color: #d7f"><p>PDF downloaded</p></div>'; } }; add_filter( 'bulk_actions-woocommerce_page_wc-orders', $add_custom_download_action); add_filter( 'handle_bulk_actions-woocommerce_page_wc-orders', $custom_download_action_handler, 10, 3 ); add_action( 'admin_notices', $custom_download_action_notice );
补充说明:$content变量是我提前拼接好的HTML字符串,在未启用HPOS的版本里验证过是正常可用的,应该不是HTML结构的问题。
备注:内容来源于stack exchange,提问作者K. Schouten
相关产品推荐
相关产品推荐

