本文整理汇总了PHP中WC_Coupon::set_discount_type方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Coupon::set_discount_type方法的具体用法?PHP WC_Coupon::set_discount_type怎么用?PHP WC_Coupon::set_discount_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Coupon
的用法示例。
在下文中一共展示了WC_Coupon::set_discount_type方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_post_meta_fields
/**
* Add post meta fields.
*
* @param WP_Post $post
* @param WP_REST_Request $request
* @return bool|WP_Error
*/
protected function add_post_meta_fields($post, $request)
{
$data = array_filter($request->get_params());
$defaults = array('discount_type' => 'fixed_cart', 'amount' => 0, 'individual_use' => false, 'product_ids' => array(), 'exclude_product_ids' => array(), 'usage_limit' => '', 'usage_limit_per_user' => '', 'limit_usage_to_x_items' => '', 'usage_count' => '', 'expiry_date' => '', 'free_shipping' => false, 'product_categories' => array(), 'excluded_product_categories' => array(), 'exclude_sale_items' => false, 'minimum_amount' => '', 'maximum_amount' => '', 'email_restrictions' => array(), 'description' => '');
$data = wp_parse_args($data, $defaults);
if (!empty($post->post_title)) {
$coupon = new WC_Coupon($post->post_title);
// Set coupon meta.
$coupon->set_discount_type($data['discount_type']);
$coupon->set_amount($data['amount']);
$coupon->set_individual_use($data['individual_use']);
$coupon->set_product_ids($data['product_ids']);
$coupon->set_excluded_product_ids($data['exclude_product_ids']);
$coupon->set_usage_limit($data['usage_limit']);
$coupon->set_usage_limit_per_user($data['usage_limit_per_user']);
$coupon->set_limit_usage_to_x_items($data['limit_usage_to_x_items']);
$coupon->set_usage_count($data['usage_count']);
$coupon->set_expiry_date($data['expiry_date']);
$coupon->set_free_shipping($data['free_shipping']);
$coupon->set_product_categories($data['product_categories']);
$coupon->set_excluded_product_categories($data['excluded_product_categories']);
$coupon->set_exclude_sale_items($data['exclude_sale_items']);
$coupon->set_minimum_amount($data['minimum_amount']);
$coupon->set_maximum_amount($data['maximum_amount']);
$coupon->set_email_restrictions($data['email_restrictions']);
$coupon->save();
}
return true;
}