當前位置: 首頁>>代碼示例>>PHP>>正文


PHP WC_Coupon::read方法代碼示例

本文整理匯總了PHP中WC_Coupon::read方法的典型用法代碼示例。如果您正苦於以下問題:PHP WC_Coupon::read方法的具體用法?PHP WC_Coupon::read怎麽用?PHP WC_Coupon::read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在WC_Coupon的用法示例。


在下文中一共展示了WC_Coupon::read方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: time

 /**
  * Test coupon reading from the DB.
  * @since 2.7.0
  */
 function test_coupon_read()
 {
     $code = 'coupon-' . time();
     $coupon = new WC_Coupon();
     $coupon->set_code($code);
     $coupon->set_description('This is a test coupon.');
     $coupon->set_usage_count(5);
     $coupon->create();
     $coupon_id = $coupon->get_id();
     $coupon_read = new WC_Coupon();
     $coupon_read->read($coupon_id);
     $this->assertEquals(5, $coupon_read->get_usage_count());
     $this->assertEquals($code, $coupon_read->get_code());
     $this->assertEquals('This is a test coupon.', $coupon_read->get_description());
 }
開發者ID:Korkey128k,項目名稱:woocommerce,代碼行數:19,代碼來源:crud.php

示例2: format_posts_to_items

 /**
  * Format posts from WP_Query result to items in which each item contain
  * common properties of item, for instance `post_title` will be `code`.
  *
  * @since  2.5.0
  * @param  array $posts Array of post
  * @return array Items
  */
 protected function format_posts_to_items($posts)
 {
     $items = array();
     foreach ($posts as $post) {
         $coupon = new WC_Coupon();
         $coupon->read($post->ID);
         $coupon_usage_limit = $coupon->get_usage_limit();
         $coupon_usage_limit_per_user = $coupon->get_usage_limit_per_user();
         $coupon_date_expires = $coupon->get_date_expires();
         $items[] = array('id' => $post->ID, 'code' => $post->post_title, 'type' => $coupon->get_discount_type(), 'created_at' => $this->format_datetime($post->post_date_gmt), 'updated_at' => $this->format_datetime($post->post_modified_gmt), 'amount' => wc_format_decimal($coupon->get_amount(), 2), 'individual_use' => $coupon->get_individual_use(), 'product_ids' => implode(', ', is_array($coupon->get_product_ids()) ? $coupon->get_product_ids() : array()), 'exclude_product_ids' => implode(', ', is_array($coupon->get_excluded_product_ids()) ? $coupon->get_excluded_product_ids() : array()), 'usage_limit' => !empty($coupon_usage_limit) ? $coupon_usage_limit : null, 'usage_limit_per_user' => !empty($coupon_usage_limit_per_user) ? $coupon_usage_limit_per_user : null, 'limit_usage_to_x_items' => (int) $coupon->get_limit_usage_to_x_items(), 'usage_count' => (int) $coupon->get_usage_count(), 'expiry_date' => !empty($coupon_date_expires) ? $this->format_datetime($coupon_date_expires) : null, 'free_shipping' => $coupon->get_free_shipping(), 'product_category_ids' => implode(', ', is_array($coupon->get_product_categories()) ? $coupon->get_product_categories() : array()), 'exclude_product_category_ids' => implode(', ', is_array($coupon->get_excluded_product_categories()) ? $coupon->get_excluded_product_categories() : array()), 'exclude_sale_items' => $coupon->get_exclude_sale_items(), 'minimum_amount' => wc_format_decimal($coupon->get_minimum_amount(), 2), 'maximum_amount' => wc_format_decimal($coupon->get_maximum_amount(), 2), 'customer_emails' => implode(', ', is_array($coupon->get_email_restrictions()) ? $coupon->get_email_restrictions() : array()), 'description' => $post->post_excerpt);
     }
     return $items;
 }
開發者ID:Korkey128k,項目名稱:woocommerce,代碼行數:21,代碼來源:class-wc-cli-coupon.php


注:本文中的WC_Coupon::read方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。