dsg56465 2016-08-24 06:19
浏览 59
已采纳

仅在woocommerce中下载重定向

I would like to customize the function that handles the redirect to the virtual product purchase page.

This is the method:

/**
 * Redirect to a file to start the download
 * @param  string $file_path
 * @param  string $filename
 */
public static function download_file_redirect( $file_path, $filename = '' ) {
    header( 'Location: ' . $file_path );
    exit;
}

How can I update this without modify the core class in this way?

public static function download_file_redirect( $file_path, $filename = '' ) {
    header( 'Location: ' . $file_path . '&order=' . $_GET['order'] );
    exit;
}

Updating the class works as I would like. But I will not change the woocommerce core. Is there a way to filter this method? So you do not have any time to modify the core with each update

  • 写回答

1条回答 默认 最新

  • dongzhi9574 2016-08-24 06:28
    关注

    Hooks are available in woocommerce for same, I hope below code will help you.

      // define the woocommerce_download_product callback 
        function action_woocommerce_download_product( $download_data_user_email, $download_data_order_key, $download_data_product_id, $download_data_user_id, $download_data_download_id, $download_data_order_id ) { 
            // make action magic happen here... 
        }; 
    
        // add the action 
        add_action( 'woocommerce_download_product', 'action_woocommerce_download_product', 10, 6 ); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CSS实现渐隐虚线框
  • ¥15 有没有帮写代码做实验仿真的
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真