get_order_key() 공개 메소드

Get order key.
부터: 2.7.0
public get_order_key ( string $context = 'view' ) : string
$context string
리턴 string
예제 #1
0
 /**
  * Test: get_checkout_order_received_url
  */
 function test_get_checkout_order_received_url()
 {
     $object = new WC_Order();
     $object->set_order_key('xxx');
     $id = $object->save();
     $this->assertEquals('http://example.org?order-received=' . $id . '&key=' . $object->get_order_key(), $object->get_checkout_order_received_url());
 }
 /**
  * Get a list of download IDs for a specific item from an order.
  *
  * @since 2.7.0
  * @param WC_Order_Item $item
  * @param WC_Order $order
  * @return array
  */
 public function get_download_ids($item, $order)
 {
     global $wpdb;
     return $wpdb->get_col($wpdb->prepare("SELECT download_id FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE user_email = %s AND order_key = %s AND product_id = %d ORDER BY permission_id", $order->get_billing_email(), $order->get_order_key(), $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id()));
 }
/**
 * Grant downloadable product access to the file identified by $download_id.
 *
 * @param  string $download_id file identifier
 * @param  int|WC_Product $product
 * @param  WC_Order $order the order
 * @param  int $qty purchased
 * @return int|bool insert id or false on failure
 */
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'));
    $download->set_download_count(0);
    $expiry = $product->get_download_expiry();
    if ($expiry > 0) {
        $order_completed_date = date_i18n("Y-m-d", $order->get_date_completed());
        $download->set_access_expires(strtotime($order_completed_date . ' + ' . $expiry . ' DAY'));
    }
    return $download->save();
}
예제 #4
0
/**
 * Grant downloadable product access to the file identified by $download_id.
 *
 * @access public
 * @param string $download_id file identifier
 * @param int $product_id product identifier
 * @param WC_Order $order the order
 * @param  int $qty purchased
 * @return int|bool insert id or false on failure
 */
function wc_downloadable_file_permission($download_id, $product_id, $order, $qty = 1)
{
    global $wpdb;
    $user_email = sanitize_email($order->get_billing_email());
    $limit = trim(get_post_meta($product_id, '_download_limit', true));
    $expiry = trim(get_post_meta($product_id, '_download_expiry', true));
    $limit = empty($limit) ? '' : absint($limit) * $qty;
    // Default value is NULL in the table schema
    $expiry = empty($expiry) ? null : absint($expiry);
    if ($expiry) {
        $order_completed_date = date_i18n("Y-m-d", strtotime($order->completed_date));
        $expiry = date_i18n("Y-m-d", strtotime($order_completed_date . ' + ' . $expiry . ' DAY'));
    }
    $data = apply_filters('woocommerce_downloadable_file_permission_data', array('download_id' => $download_id, 'product_id' => $product_id, 'user_id' => absint($order->get_user_id()), 'user_email' => $user_email, 'order_id' => $order->get_id(), 'order_key' => $order->get_order_key(), 'downloads_remaining' => $limit, 'access_granted' => current_time('mysql'), 'download_count' => 0));
    $format = apply_filters('woocommerce_downloadable_file_permission_format', array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d'), $data);
    if (!is_null($expiry)) {
        $data['access_expires'] = $expiry;
        $format[] = '%s';
    }
    // Downloadable product - give access to the customer
    $result = $wpdb->insert($wpdb->prefix . 'woocommerce_downloadable_product_permissions', $data, $format);
    do_action('woocommerce_grant_product_download_access', $data);
    return $result ? $wpdb->insert_id : false;
}