تابع ووکامرسی wc_downloadable_file_permission گرفتن دسترسی از محصول دانلودی

تابع ووکامرسی wc_downloadable_file_permission – گرفتن دسترسی از محصول دانلودی بر اساس شناسه دانلود
Syntax – سینتکس
(int|bool) wc_downloadable_file_permission( (string) $download_id, (int|WC_Product) $product, (WC_Order) $order, (int) $qty = 1 );
Parameters – پارامتر ها (4)
- 1- $download_id (string)
- 2- $product (int|WC_Product)
- 3- $order (WC_Order)
- 4- $qty (int)
Returns – مقادیر بازگشتی (int|bool)
insert id or false on failure
Usage – نحوه استفاده
if ( !function_exists( 'wc_downloadable_file_permission' ) ) {
require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-order-functions.php';
}
// The download id.
$download_id = '';
// The product.
$product = null;
// The order.
$order = null;
// purchased
$qty = 1;
// NOTICE! Understand what this does before running.
$result = wc_downloadable_file_permission($download_id, $product, $order, $qty);
Defined – محل تعریف
/includes/wc-order-functions.php
function wc_downloadable_file_permission( $download_id, $product, $order, $qty = 1 ) {
if ( is_numeric( $product ) ) {
$product = wc_get_product( $product );
}
$download = new WC_Customer_Download();
$download->set_download_id( $download_id );
$download->set_product_id( $product->get_id() );
$download->set_user_id( $order->get_customer_id() );
$download->set_order_id( $order->get_id() );
$download->set_user_email( $order->get_billing_email() );
$download->set_order_key( $order->get_order_key() );
$download->set_downloads_remaining( 0 > $product->get_download_limit() ? '' : $product->get_download_limit() * $qty );
$download->set_access_granted( current_time( 'timestamp', true ) );
$download->set_download_count( 0 );
$expiry = $product->get_download_expiry();
if ( $expiry > 0 ) {
$from_date = $order->get_date_completed() ? $order->get_date_completed()->format( 'Y-m-d' ) : current_time( 'mysql', true );
$download->set_access_expires( strtotime( $from_date . ' + ' . $expiry . ' DAY' ) );
}
return $download->save();
}
versions – نسخه ها
از نسخه : 3.0.2
نسخه فعلی : 3.0.6
دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2
ارسال نظر