php - Check if user have permission or not to download any file in WooCommerce -
i want check whether user have permission or not download file. have product id , user id how can check?
i have explored lot on google , in woocommerce documentation didn't find solution.
any help?
thanks in advance.
here process information can use in function or hooked function in php files.
here code:
// current customer orders $customer_orders = wc_get_orders( $args = array( 'numberposts' => -1, 'meta_key' => '_customer_user', 'meta_value' => get_current_user_id(),// current user id 'post_status' => array_keys(wc_get_order_statuses()), ) ); // different loops downloadable products bought user foreach ( $customer_orders $customer_order ){ if (!empty($customer_orders)){ foreach ( $customer_orders $customer_order ){ if( !$customer_order->has_downloadable_item() && $customer_order->is_paid() ){ foreach( $customer_order->get_items() $item ){ $item_id = $item['product_id']; // product id // downloadable items below if($item->is_download_permitted()) { // because download permitted // can use different methods on $customer_product object: // downloadbles files (array): $downloadable_files_array = get_item_downloads( $item ); // display download links order item. $display_item_downloads = display_item_downloads( $item ); // download url of given $download_id // $download_url = get_download_url($item_id, $download_id ) } else { // because download not permitted } } } } } }
code goes in php file of active child theme (or theme) or in plugin php files.
this tested , functional.
reference: wc_abstract_order class - methods
Comments
Post a Comment