• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wc_downloadable_file_permission函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中wc_downloadable_file_permission函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_downloadable_file_permission函数的具体用法?PHP wc_downloadable_file_permission怎么用?PHP wc_downloadable_file_permission使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了wc_downloadable_file_permission函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: save_downloadable_product_permissions

 /**
  * Save the download permissions on the individual subscriptions as well as the order. Hooked into
  * 'woocommerce_grant_product_download_permissions', which is strictly after the order received all the info
  * it needed, so we don't need to play with priorities.
  *
  * @param integer $order_id the ID of the order. At this point it is guaranteed that it has files in it and that it hasn't been granted permissions before
  */
 public static function save_downloadable_product_permissions($order_id)
 {
     global $wpdb;
     $order = wc_get_order($order_id);
     if (wcs_order_contains_subscription($order, 'any')) {
         $subscriptions = wcs_get_subscriptions_for_order($order, array('order_type' => array('any')));
     } else {
         return;
     }
     foreach ($subscriptions as $subscription) {
         if (sizeof($subscription->get_items()) > 0) {
             foreach ($subscription->get_items() as $item) {
                 $_product = $subscription->get_product_from_item($item);
                 if ($_product && $_product->exists() && $_product->is_downloadable()) {
                     $downloads = $_product->get_files();
                     $product_id = wcs_get_canonical_product_id($item);
                     foreach (array_keys($downloads) as $download_id) {
                         // grant access on subscription if it does not already exist
                         if (!$wpdb->get_var($wpdb->prepare("SELECT download_id FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE `order_id` = %d AND `product_id` = %d AND `download_id` = '%s'", $subscription->id, $product_id, $download_id))) {
                             wc_downloadable_file_permission($download_id, $product_id, $subscription, $item['qty']);
                         }
                         self::revoke_downloadable_file_permission($product_id, $order_id, $order->user_id);
                     }
                 }
             }
         }
         update_post_meta($subscription->id, '_download_permissions_granted', 1);
     }
 }
开发者ID:ltdat287,项目名称:id.nhomdichvu,代码行数:36,代码来源:class-wcs-download-handler.php


示例2: maybe_remove_or_add_item_to_subscription

 /**
  * Process the remove or re-add a line item from a subscription request.
  *
  * @since 2.0
  */
 public static function maybe_remove_or_add_item_to_subscription()
 {
     if (isset($_GET['subscription_id']) && (isset($_GET['remove_item']) || isset($_GET['undo_remove_item'])) && isset($_GET['_wpnonce'])) {
         $subscription = wcs_is_subscription($_GET['subscription_id']) ? wcs_get_subscription($_GET['subscription_id']) : false;
         $undo_request = isset($_GET['undo_remove_item']) ? true : false;
         $item_id = $undo_request ? $_GET['undo_remove_item'] : $_GET['remove_item'];
         if (false === $subscription) {
             wc_add_notice(sprintf(_x('Subscription #%d does not exist.', 'hash before subscription ID', 'woocommerce-subscriptions'), $_GET['subscription_id']), 'error');
             wp_safe_redirect(wc_get_page_permalink('myaccount'));
             exit;
         }
         if (self::validate_remove_items_request($subscription, $item_id, $undo_request)) {
             if ($undo_request) {
                 // handle undo request
                 $removed_item = WC()->session->get('removed_subscription_items', array());
                 if (!empty($removed_item[$item_id]) && $subscription->id == $removed_item[$item_id]) {
                     // restore the item
                     wc_update_order_item($item_id, array('order_item_type' => 'line_item'));
                     unset($removed_item[$item_id]);
                     WC()->session->set('removed_subscription_items', $removed_item);
                     // restore download permissions for this item
                     $line_items = $subscription->get_items();
                     $line_item = $line_items[$item_id];
                     $_product = $subscription->get_product_from_item($line_item);
                     $product_id = wcs_get_canonical_product_id($line_item);
                     if ($_product && $_product->exists() && $_product->is_downloadable()) {
                         $downloads = $_product->get_files();
                         foreach (array_keys($downloads) as $download_id) {
                             wc_downloadable_file_permission($download_id, $product_id, $subscription, $line_item['qty']);
                         }
                     }
                     // translators: 1$: product name, 2$: product id
                     $subscription->add_order_note(sprintf(_x('Customer added "%1$s" (Product ID: #%2$d) via the My Account page.', 'used in order note', 'woocommerce-subscriptions'), wcs_get_line_item_name($line_item), $product_id));
                 } else {
                     wc_add_notice(__('Your request to undo your previous action was unsuccessful.', 'woocommerce-subscriptions'));
                 }
             } else {
                 // handle remove item requests
                 WC()->session->set('removed_subscription_items', array($item_id => $subscription->id));
                 // remove download access for the item
                 $line_items = $subscription->get_items();
                 $line_item = $line_items[$item_id];
                 $product_id = wcs_get_canonical_product_id($line_item);
                 WCS_Download_Handler::revoke_downloadable_file_permission($product_id, $subscription->id, $subscription->get_user_id());
                 // remove the line item from subscription but preserve its data in the DB
                 wc_update_order_item($item_id, array('order_item_type' => 'line_item_removed'));
                 // translators: 1$: product name, 2$: product id
                 $subscription->add_order_note(sprintf(_x('Customer removed "%1$s" (Product ID: #%2$d) via the My Account page.', 'used in order note', 'woocommerce-subscriptions'), wcs_get_line_item_name($line_item), $product_id));
                 // translators: placeholders are 1$: item name, and, 2$: opening and, 3$: closing link tags
                 wc_add_notice(sprintf(__('You have successfully removed "%1$s" from your subscription. %2$sUndo?%3$s', 'woocommerce-subscriptions'), $line_item['name'], '<a href="' . esc_url(self::get_undo_remove_url($subscription->id, $item_id, $subscription->get_view_order_url())) . '" >', '</a>'));
             }
         }
         $subscription->calculate_totals();
         wp_safe_redirect($subscription->get_view_order_url());
         exit;
     }
 }
开发者ID:ltdat287,项目名称:id.nhomdichvu,代码行数:62,代码来源:class-wcs-remove-item.php


示例3: grant_access_to_download

 /**
  * Grant download permissions via ajax function
  */
 public static function grant_access_to_download()
 {
     check_ajax_referer('grant-access', 'security');
     if (!current_user_can('edit_shop_orders')) {
         die(-1);
     }
     global $wpdb;
     $wpdb->hide_errors();
     $order_id = intval($_POST['order_id']);
     $product_ids = $_POST['product_ids'];
     $loop = intval($_POST['loop']);
     $file_counter = 0;
     $order = wc_get_order($order_id);
     if (!is_array($product_ids)) {
         $product_ids = array($product_ids);
     }
     foreach ($product_ids as $product_id) {
         $product = wc_get_product($product_id);
         $files = $product->get_files();
         if (!$order->billing_email) {
             die;
         }
         if ($files) {
             foreach ($files as $download_id => $file) {
                 if ($inserted_id = wc_downloadable_file_permission($download_id, $product_id, $order)) {
                     // insert complete - get inserted data
                     $download = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE permission_id = %d", $inserted_id));
                     $loop++;
                     $file_counter++;
                     if (isset($file['name'])) {
                         $file_count = $file['name'];
                     } else {
                         $file_count = sprintf(__('File %d', 'woocommerce'), $file_counter);
                     }
                     include 'admin/meta-boxes/views/html-order-download-permission.php';
                 }
             }
         }
     }
     die;
 }
开发者ID:JodiWarren,项目名称:woocommerce,代码行数:44,代码来源:class-wc-ajax.php


示例4: wc_downloadable_product_permissions

/**
 * Order Status completed - GIVE DOWNLOADABLE PRODUCT ACCESS TO CUSTOMER
 *
 * @access public
 * @param int $order_id
 * @return void
 */
function wc_downloadable_product_permissions($order_id)
{
    if (get_post_meta($order_id, '_download_permissions_granted', true) == 1) {
        return;
        // Only do this once
    }
    $order = wc_get_order($order_id);
    if ($order->has_status('processing') && get_option('woocommerce_downloads_grant_access_after_payment') == 'no') {
        return;
    }
    if (sizeof($order->get_items()) > 0) {
        foreach ($order->get_items() as $item) {
            $_product = $order->get_product_from_item($item);
            if ($_product && $_product->exists() && $_product->is_downloadable()) {
                $downloads = $_product->get_files();
                foreach (array_keys($downloads) as $download_id) {
                    wc_downloadable_file_permission($download_id, $item['variation_id'] > 0 ? $item['variation_id'] : $item['product_id'], $order, $item['qty']);
                }
            }
        }
    }
    update_post_meta($order_id, '_download_permissions_granted', 1);
    do_action('woocommerce_grant_product_download_permissions', $order_id);
}
开发者ID:amusiiko,项目名称:armo,代码行数:31,代码来源:wc-order-functions.php


示例5: woocommerce_downloadable_file_permission

/**
 * @deprecated
 */
function woocommerce_downloadable_file_permission($download_id, $product_id, $order)
{
    return wc_downloadable_file_permission($download_id, $product_id, $order);
}
开发者ID:nayemDevs,项目名称:woocommerce,代码行数:7,代码来源:wc-deprecated-functions.php


示例6: process_product_file_download_paths

 /**
  * Grant downloadable file access to any newly added files on any existing
  * orders for this product that have previously been granted downloadable file access
  *
  * @param int $product_id product identifier
  * @param int $variation_id optional product variation identifier
  * @param array $downloadable_files newly set files
  */
 public function process_product_file_download_paths($product_id, $variation_id, $downloadable_files)
 {
     global $wpdb;
     if ($variation_id) {
         $product_id = $variation_id;
     }
     $product = wc_get_product($product_id);
     $existing_download_ids = array_keys((array) $product->get_files());
     $updated_download_ids = array_keys((array) $downloadable_files);
     $new_download_ids = array_filter(array_diff($updated_download_ids, $existing_download_ids));
     $removed_download_ids = array_filter(array_diff($existing_download_ids, $updated_download_ids));
     if (!empty($new_download_ids) || !empty($removed_download_ids)) {
         // determine whether downloadable file access has been granted via the typical order completion, or via the admin ajax method
         $existing_permissions = $wpdb->get_results($wpdb->prepare("SELECT * from {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE product_id = %d GROUP BY order_id", $product_id));
         foreach ($existing_permissions as $existing_permission) {
             $order = wc_get_order($existing_permission->order_id);
             if (!empty($order->id)) {
                 // Remove permissions
                 if (!empty($removed_download_ids)) {
                     foreach ($removed_download_ids as $download_id) {
                         if (apply_filters('woocommerce_process_product_file_download_paths_remove_access_to_old_file', true, $download_id, $product_id, $order)) {
                             $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE order_id = %d AND product_id = %d AND download_id = %s", $order->id, $product_id, $download_id));
                         }
                     }
                 }
                 // Add permissions
                 if (!empty($new_download_ids)) {
                     foreach ($new_download_ids as $download_id) {
                         if (apply_filters('woocommerce_process_product_file_download_paths_grant_access_to_new_file', true, $download_id, $product_id, $order)) {
                             // grant permission if it doesn't already exist
                             if (!$wpdb->get_var($wpdb->prepare("SELECT 1=1 FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE order_id = %d AND product_id = %d AND download_id = %s", $order->id, $product_id, $download_id))) {
                                 wc_downloadable_file_permission($download_id, $product_id, $order);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:vkolova,项目名称:bgscena,代码行数:48,代码来源:class-wc-admin-post-types.php


示例7: wc_downloadable_product_permissions

/**
 * Order Status completed - GIVE DOWNLOADABLE PRODUCT ACCESS TO CUSTOMER.
 *
 * @param int $order_id
 */
function wc_downloadable_product_permissions($order_id, $force = false)
{
    $order = wc_get_order($order_id);
    if (!$order || $order->get_data_store()->get_download_permissions_granted($order) && !$force) {
        return;
    }
    if ($order->has_status('processing') && 'no' === get_option('woocommerce_downloads_grant_access_after_payment')) {
        return;
    }
    if (sizeof($order->get_items()) > 0) {
        foreach ($order->get_items() as $item) {
            $product = $item->get_product();
            if ($product && $product->exists() && $product->is_downloadable()) {
                $downloads = $product->get_downloads();
                foreach (array_keys($downloads) as $download_id) {
                    wc_downloadable_file_permission($download_id, $product, $order, $item->get_quantity());
                }
            }
        }
    }
    $order->get_data_store()->set_download_permissions_granted($order, true);
    do_action('woocommerce_grant_product_download_permissions', $order_id);
}
开发者ID:woocommerce,项目名称:woocommerce,代码行数:28,代码来源:wc-order-functions.php


示例8: grant_access_to_download

 /**
  * Grant download permissions via ajax function.
  */
 public static function grant_access_to_download()
 {
     check_ajax_referer('grant-access', 'security');
     if (!current_user_can('edit_shop_orders')) {
         die(-1);
     }
     global $wpdb;
     $wpdb->hide_errors();
     $order_id = intval($_POST['order_id']);
     $product_ids = $_POST['product_ids'];
     $loop = intval($_POST['loop']);
     $file_counter = 0;
     $order = wc_get_order($order_id);
     if (!is_array($product_ids)) {
         $product_ids = array($product_ids);
     }
     foreach ($product_ids as $product_id) {
         $product = wc_get_product($product_id);
         $files = $product->get_downloads();
         if (!$order->get_billing_email()) {
             die;
         }
         if (!empty($files)) {
             foreach ($files as $download_id => $file) {
                 if ($inserted_id = wc_downloadable_file_permission($download_id, $product_id, $order)) {
                     $download = new WC_Customer_Download($inserted_id);
                     $loop++;
                     $file_counter++;
                     if ($file->get_name()) {
                         $file_count = $file->get_name();
                     } else {
                         $file_count = sprintf(__('File %d', 'woocommerce'), $file_counter);
                     }
                     include 'admin/meta-boxes/views/html-order-download-permission.php';
                 }
             }
         }
     }
     die;
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:43,代码来源:class-wc-ajax.php


示例9: grant_new_file_product_permissions

 /**
  * Grant downloadable file access to any newly added files on any existing subscriptions
  * which don't have existing permissions.
  *
  * @param int $product_id
  * @param int $variation_id
  * @param array $downloadable_files product downloadable files
  * @since 2.0.18
  */
 public static function grant_new_file_product_permissions($product_id, $variation_id, $downloadable_files)
 {
     global $wpdb;
     $product_id = $variation_id ? $variation_id : $product_id;
     $product = wc_get_product($product_id);
     $existing_download_ids = array_keys((array) $product->get_files());
     $downloadable_ids = array_keys((array) $downloadable_files);
     $new_download_ids = array_filter(array_diff($downloadable_ids, $existing_download_ids));
     if (!empty($new_download_ids)) {
         $existing_permissions = $wpdb->get_col($wpdb->prepare("SELECT order_id from {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE product_id = %d GROUP BY order_id", $product_id));
         $subscriptions = wcs_get_subscriptions_for_product($product_id);
         foreach ($subscriptions as $subscription_id) {
             // only grant permissions to subscriptions which have no permissions for this product
             if (!in_array($subscription_id, $existing_permissions)) {
                 $subscription = wcs_get_subscription($subscription_id);
                 foreach ($new_download_ids as $download_id) {
                     if ($subscription && apply_filters('woocommerce_process_product_file_download_paths_grant_access_to_new_file', true, $download_id, $product_id, $subscription)) {
                         wc_downloadable_file_permission($download_id, $product_id, $subscription);
                     }
                 }
             }
         }
     }
 }
开发者ID:DustinHartzler,项目名称:TheCLEFT,代码行数:33,代码来源:class-wcs-download-handler.php


示例10: grant_access_to_download

 /**
  * Grant download permissions via ajax function
  *
  * @access public
  * @return void
  */
 function grant_access_to_download()
 {
     check_ajax_referer('grant-access', 'security');
     global $wpdb;
     $order_id = intval($_POST['order_id']);
     $product_ids = $_POST['product_ids'];
     $loop = intval($_POST['loop']);
     $file_counter = 0;
     $order = new WC_Order($order_id);
     if (!is_array($product_ids)) {
         $product_ids = array($product_ids);
     }
     foreach ($product_ids as $product_id) {
         $product = get_product($product_id);
         $files = $product->get_files();
         if (!$order->billing_email) {
             die;
         }
         if ($files) {
             foreach ($files as $download_id => $file) {
                 if ($inserted_id = wc_downloadable_file_permission($download_id, $product_id, $order)) {
                     // insert complete - get inserted data
                     $download = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE permission_id = %d", $inserted_id));
                     $loop++;
                     $file_counter++;
                     if (isset($file['name'])) {
                         $file_count = $file['name'];
                     } else {
                         $file_count = sprintf(__('File %d', 'woocommerce'), $file_counter);
                     }
                     include dirname(dirname(__FILE__)) . '/templates/orders/order-download-permission-html.php';
                 }
             }
         }
     }
     die;
 }
开发者ID:uwitec,项目名称:findgreatmaster,代码行数:43,代码来源:ajax.php


示例11: woo_vou_insert_downloadable_files

 /**
  * Insert pdf voucher files
  *
  * Handles to insert pdf voucher
  * files in database
  *
  * @package WooCommerce - PDF Vouchers
  * @since   1.0.0
  */
 public function woo_vou_insert_downloadable_files($order_id)
 {
     $prefix = WOO_VOU_META_PREFIX;
     $downloadable_files = array();
     //Get Order
     $order = new WC_Order($order_id);
     if (sizeof($order->get_items()) > 0) {
         //Get all items in order
         foreach ($order->get_items() as $item_id => $item) {
             //Product Data
             $_product = $order->get_product_from_item($item);
             // Taking variation id
             $variation_id = !empty($item['variation_id']) ? $item['variation_id'] : '';
             if ($_product && $_product->exists()) {
                 // && $_product->is_downloadable()
                 //get product id from prduct data
                 $product_id = isset($_product->id) ? $_product->id : '';
                 // If product is variable product take variation id else product id
                 $data_id = !empty($variation_id) ? $variation_id : $product_id;
                 if ($this->model->woo_vou_check_enable_voucher($product_id, $variation_id)) {
                     //Check voucher is enabled or not
                     //Get vouchers downlodable pdf files
                     $downloadable_files = $this->woo_vou_get_vouchers_download_key($order_id, $data_id, $item_id);
                     foreach (array_keys($downloadable_files) as $download_id) {
                         //Insert pdf vouchers in downloadable table
                         wc_downloadable_file_permission($download_id, $data_id, $order);
                     }
                 }
             }
         }
     }
     // Status update from pending to publish when voucher is get completed or processing
     $args = array('post_status' => array('pending'), 'meta_query' => array(array('key' => $prefix . 'order_id', 'value' => $order_id)));
     // Get vouchers code of this order
     $purchased_vochers = $this->model->woo_vou_get_voucher_details($args);
     if (!empty($purchased_vochers)) {
         // If not empty voucher codes
         //For all possible vouchers
         foreach ($purchased_vochers as $vocher) {
             // Get voucher data
             $current_post = get_post($vocher['ID'], 'ARRAY_A');
             //Change voucher status
             $current_post['post_status'] = 'publish';
             //Update voucher post
             wp_update_post($current_post);
         }
     }
 }
开发者ID:flasomm,项目名称:Montkailash,代码行数:57,代码来源:class-woo-vou-public.php


示例12: wc_downloadable_product_permissions

/**
 * Order Status completed - GIVE DOWNLOADABLE PRODUCT ACCESS TO CUSTOMER
 *
 * @access public
 * @param int $order_id
 * @return void
 */
function wc_downloadable_product_permissions($order_id)
{
    if (get_post_meta($order_id, '_download_permissions_granted', true) == 1) {
        return;
    }
    // Only do this once
    $order = new WC_Order($order_id);
    if (sizeof($order->get_items()) > 0) {
        foreach ($order->get_items() as $item) {
            $_product = $order->get_product_from_item($item);
            if ($_product && $_product->exists() && $_product->is_downloadable()) {
                $downloads = $_product->get_files();
                foreach (array_keys($downloads) as $download_id) {
                    wc_downloadable_file_permission($download_id, $item['variation_id'] > 0 ? $item['variation_id'] : $item['product_id'], $order);
                }
            }
        }
    }
    update_post_meta($order_id, '_download_permissions_granted', 1);
    do_action('woocommerce_grant_product_download_permissions', $order_id);
}
开发者ID:hoonio,项目名称:PhoneAfrika,代码行数:28,代码来源:wc-order-functions.php


示例13: HandleFiles

 public static function HandleFiles($ID, &$downloadable_files)
 {
     global $wpdb;
     $product_id = $ID;
     $existing_download_ids = array_keys((array) get_post_meta($ID, '_downloadable_files', true));
     $updated_download_ids = array_keys((array) $downloadable_files);
     $new_download_ids = array_filter(array_diff($updated_download_ids, $existing_download_ids));
     $removed_download_ids = array_filter(array_diff($existing_download_ids, $updated_download_ids));
     if ($new_download_ids || $removed_download_ids) {
         // determine whether downloadable file access has been granted via the typical order completion, or via the admin ajax method
         $existing_permissions = $wpdb->get_results($wpdb->prepare("SELECT * from {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE product_id = %d GROUP BY order_id", $product_id));
         foreach ($existing_permissions as $existing_permission) {
             //				$order = new WC_Order( $existing_permission->order_id );
             if ($wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->prefix}posts WHERE ID = %d", $existing_permission->order_id))) {
                 // Remove permissions
                 if ($removed_download_ids) {
                     foreach ($removed_download_ids as $download_id) {
                         if (apply_filters('woocommerce_process_product_file_download_paths_remove_access_to_old_file', true, $download_id, $product_id, $order)) {
                             $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE order_id = %d AND product_id = %d AND download_id = %s", $existing_permission->order_id, $product_id, $download_id));
                         }
                     }
                 }
                 // Add permissions
                 if ($new_download_ids) {
                     foreach ($new_download_ids as $download_id) {
                         if (apply_filters('woocommerce_process_product_file_download_paths_grant_access_to_new_file', true, $download_id, $product_id, $order)) {
                             // grant permission if it doesn't already exist
                             if (!$wpdb->get_var($wpdb->prepare("SELECT 1 FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE order_id = %d AND product_id = %d AND download_id = %s", $existing_permission->order_id, $product_id, $download_id))) {
                                 if (function_exists('wc_downloadable_file_permission')) {
                                     wc_downloadable_file_permission($download_id, $product_id, $existing_permission->order_id);
                                 } else {
                                     self::copied_wc_downloadable_file_permission($download_id, $product_id, $existing_permission->order_id);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:baden03,项目名称:access48,代码行数:41,代码来源:ajax_handler.php


示例14: process_shop_order_meta

 /**
  * Called when an order is updated from the admin, creates a new voucher if
  * a voucher item was added, and updates the voucher expiration and redeem
  * item meta.
  *
  * @since 1.2
  * @param int $post_id the post identifier
  * @param object $post the order post object
  *
  * @return array order item data to persist
  */
 public function process_shop_order_meta($post_id, $post)
 {
     // get the order
     $order = wc_get_order($post_id);
     $order_items = $order->get_items();
     // loop through any order items by id
     if (isset($_POST['order_item_id'])) {
         foreach ($_POST['order_item_id'] as $item_id) {
             $item_id = absint($item_id);
             if (!isset($order_items[$item_id]) || !$order_items[$item_id]) {
                 continue;
             }
             $order_item = $order_items[$item_id];
             $product_id = $order_item['variation_id'] ? $order_item['variation_id'] : $order_item['product_id'];
             $product = wc_get_product($product_id);
             // if we have a voucher product, but no voucher set for the order item, this is likely an item newly added from the admin, so create a default voucher
             if ($product && $product->is_downloadable() && WC_PDF_Product_Vouchers_Product::has_voucher($product) && (!isset($order_item['voucher_id']) || !$order_item['voucher_id'])) {
                 $voucher = WC_PDF_Product_Vouchers_Product::get_voucher($product);
                 $voucher_number = WC_PDF_Product_Vouchers_Voucher::generate_voucher_number();
                 wc_add_order_item_meta($item_id, '_voucher_image_id', $voucher->get_image_id());
                 wc_add_order_item_meta($item_id, '_voucher_id', $voucher->id);
                 wc_add_order_item_meta($item_id, '_voucher_redeem', array_pad(array(), $order_item['qty'], null));
                 // TODO: need to handle the order item quantity being changed from the admin
                 wc_add_order_item_meta($item_id, '_voucher_number', $voucher_number);
                 // if download permissions have already been granted, grant permission to the newly created voucher
                 if (isset($order->download_permissions_granted[0]) && 1 == $order->download_permissions_granted[0]) {
                     wc_downloadable_file_permission('wc_vouchers_' . $voucher_number, $product_id, $order);
                 }
             }
             if (isset($_POST['voucher_expiration'][$item_id])) {
                 wc_update_order_item_meta($item_id, '_voucher_expiration', $_POST['voucher_expiration'][$item_id]);
             }
             if (isset($_POST['voucher_redeem'][$item_id])) {
                 wc_update_order_item_meta($item_id, '_voucher_redeem', $_POST['voucher_redeem'][$item_id]);
             }
         }
     }
 }
开发者ID:reti-senza-frontiere,项目名称:WP-Plugins,代码行数:49,代码来源:class-wc-pdf-product-vouchers-admin-orders.php



注:本文中的wc_downloadable_file_permission函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wc_downloadable_product_permissions函数代码示例发布时间:2022-05-23
下一篇:
PHP wc_delete_shop_order_transients函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap