本文整理汇总了PHP中WC_Coupon::exclude_sale_items方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Coupon::exclude_sale_items方法的具体用法?PHP WC_Coupon::exclude_sale_items怎么用?PHP WC_Coupon::exclude_sale_items使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Coupon
的用法示例。
在下文中一共展示了WC_Coupon::exclude_sale_items方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepare_item_for_response
/**
* Prepare a single coupon output for response.
*
* @param WP_Post $post Post object.
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response $data
*/
public function prepare_item_for_response($post, $request)
{
global $wpdb;
// Get the coupon code.
$code = $wpdb->get_var($wpdb->prepare("SELECT post_title FROM {$wpdb->posts} WHERE id = %s AND post_type = 'shop_coupon' AND post_status = 'publish'", $post->ID));
$coupon = new WC_Coupon($code);
$data = array('id' => $coupon->id, 'code' => $coupon->code, 'date_created' => wc_rest_prepare_date_response($post->post_date_gmt), 'date_modified' => wc_rest_prepare_date_response($post->post_modified_gmt), 'discount_type' => $coupon->type, 'description' => $post->post_excerpt, 'amount' => wc_format_decimal($coupon->coupon_amount, 2), 'expiry_date' => !empty($coupon->expiry_date) ? wc_rest_prepare_date_response($coupon->expiry_date) : null, 'usage_count' => (int) $coupon->usage_count, 'individual_use' => 'yes' === $coupon->individual_use, 'product_ids' => array_map('absint', (array) $coupon->product_ids), 'exclude_product_ids' => array_map('absint', (array) $coupon->exclude_product_ids), '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->limit_usage_to_x_items, 'free_shipping' => $coupon->enable_free_shipping(), 'product_categories' => array_map('absint', (array) $coupon->product_categories), 'excluded_product_categories' => array_map('absint', (array) $coupon->exclude_product_categories), 'exclude_sale_items' => $coupon->exclude_sale_items(), 'minimum_amount' => wc_format_decimal($coupon->minimum_amount, 2), 'maximum_amount' => wc_format_decimal($coupon->maximum_amount, 2), 'email_restrictions' => $coupon->customer_email, 'used_by' => $coupon->get_used_by());
$context = !empty($request['context']) ? $request['context'] : 'view';
$data = $this->add_additional_fields_to_object($data, $request);
$data = $this->filter_response_by_context($data, $context);
// Wrap the data in a response object.
$response = rest_ensure_response($data);
$response->add_links($this->prepare_links($post));
/**
* Filter the data for a response.
*
* The dynamic portion of the hook name, $this->post_type, refers to post_type of the post being
* prepared for the response.
*
* @param WP_REST_Response $response The response object.
* @param WP_Post $post Post object.
* @param WP_REST_Request $request Request object.
*/
return apply_filters("woocommerce_rest_prepare_{$this->post_type}", $response, $post, $request);
}
示例2: get_coupon
/**
* Get the coupon for the given ID
*
* @since 2.1
* @param int $id the coupon ID
* @param string $fields fields to include in response
* @return array|WP_Error
*/
public function get_coupon($id, $fields = null)
{
global $wpdb;
$id = $this->validate_request($id, 'shop_coupon', 'read');
if (is_wp_error($id)) {
return $id;
}
// get the coupon code
$code = $wpdb->get_var($wpdb->prepare("SELECT post_title FROM {$wpdb->posts} WHERE id = %s AND post_type = 'shop_coupon' AND post_status = 'publish'", $id));
if (is_null($code)) {
return new WP_Error('woocommerce_api_invalid_coupon_id', __('Invalid coupon ID', 'woocommerce'), array('status' => 404));
}
$coupon = new WC_Coupon($code);
$coupon_post = get_post($coupon->id);
$coupon_data = array('id' => $coupon->id, 'code' => $coupon->code, 'type' => $coupon->type, 'created_at' => $this->server->format_datetime($coupon_post->post_date_gmt), 'updated_at' => $this->server->format_datetime($coupon_post->post_modified_gmt), 'amount' => wc_format_decimal($coupon->amount, 2), 'individual_use' => 'yes' === $coupon->individual_use, 'product_ids' => array_map('absint', (array) $coupon->product_ids), 'exclude_product_ids' => array_map('absint', (array) $coupon->exclude_product_ids), '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->limit_usage_to_x_items, 'usage_count' => (int) $coupon->usage_count, 'expiry_date' => $this->server->format_datetime($coupon->expiry_date), 'apply_before_tax' => $coupon->apply_before_tax(), 'enable_free_shipping' => $coupon->enable_free_shipping(), 'product_category_ids' => array_map('absint', (array) $coupon->product_categories), 'exclude_product_category_ids' => array_map('absint', (array) $coupon->exclude_product_categories), 'exclude_sale_items' => $coupon->exclude_sale_items(), 'minimum_amount' => wc_format_decimal($coupon->minimum_amount, 2), 'customer_emails' => $coupon->customer_email);
return array('coupon' => apply_filters('woocommerce_api_coupon_response', $coupon_data, $coupon, $fields, $this->server));
}