本文整理汇总了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());
}
示例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;
}