wc_get_customer_available_downloads دریافت لینک های دانلود قابل دسترسی مشتری

تابع ووکامرسی wc_get_customer_available_downloads – دریافت لینک های دانلود قابل دسترسی مشتری
Syntax – سینتکس
(array) wc_get_customer_available_downloads( (int) $customer_id );
Parameters – پارامتر ها (1)
- 1- $customer_id (int)
Usage – نحوه استفاده
if ( !function_exists( 'wc_get_customer_available_downloads' ) ) {
require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-user-functions.php';
}
// The customer id.
$customer_id = -1;
// NOTICE! Understand what this does before running.
$result = wc_get_customer_available_downloads($customer_id);
Defined – محل تعریف
/includes/wc-user-functions.php
function wc_get_customer_available_downloads( $customer_id ) {
$downloads = array();
$_product = null;
$order = null;
$file_number = 0;
// Get results from valid orders only
$results = wc_get_customer_download_permissions( $customer_id );
if ( $results ) {
foreach ( $results as $result ) {
if ( ! $order || $order->get_id() != $result->order_id ) {
// new order
$order = wc_get_order( $result->order_id );
$_product = null;
}
// Make sure the order exists for this download
if ( ! $order ) {
continue;
}
// Downloads permitted?
if ( ! $order->is_download_permitted() ) {
continue;
}
$product_id = intval( $result->product_id );
if ( ! $_product || $_product->get_id() != $product_id ) {
// new product
$file_number = 0;
$_product = wc_get_product( $product_id );
}
// Check product exists and has the file
if ( ! $_product || ! $_product->exists() || ! $_product->has_file( $result->download_id ) ) {
continue;
}
$download_file = $_product->get_file( $result->download_id );
// Download name will be 'Product Name' for products with a single downloadable file, and 'Product Name - File X' for products with multiple files.
$download_name = apply_filters(
'woocommerce_downloadable_product_name',
$_product->get_name() . ' – ' . $download_file['name'],
$_product,
$result->download_id,
$file_number
);
$downloads[] = array(
'download_url' => add_query_arg(
array(
'download_file' => $product_id,
'order' => $result->order_key,
'email' => urlencode( $result->user_email ),
'key' => $result->download_id,
),
home_url( '/' )
),
'download_id' => $result->download_id,
'product_id' => $_product->get_id(),
'product_name' => $_product->get_name(),
'download_name' => $download_name,
'order_id' => $order->get_id(),
'order_key' => $order->get_order_key(),
'downloads_remaining' => $result->downloads_remaining,
'access_expires' => $result->access_expires,
'file' => array(
'name' => $download_file->get_name(),
'file' => $download_file->get_file(),
),
);
$file_number++;
}
}
return apply_filters( 'woocommerce_customer_available_downloads', $downloads, $customer_id );
}
versions – نسخه ها
از نسخه : 3.0.2
نسخه فعلی : 3.0.6
دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2
ارسال نظر