本文整理匯總了PHP中WC_Coupon::set_props方法的典型用法代碼示例。如果您正苦於以下問題:PHP WC_Coupon::set_props方法的具體用法?PHP WC_Coupon::set_props怎麽用?PHP WC_Coupon::set_props使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類WC_Coupon
的用法示例。
在下文中一共展示了WC_Coupon::set_props方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: save
/**
* Save meta box data.
*
* @param int $post_id
* @param WP_Post $post
*/
public static function save($post_id, $post)
{
global $wpdb;
// Check for dupe coupons
$coupon_code = apply_filters('woocommerce_coupon_code', $post->post_title);
$id_from_code = wc_get_coupon_id_by_code($coupon_code, $post_id);
if ($id_from_code) {
WC_Admin_Meta_Boxes::add_error(__('Coupon code already exists - customers will use the latest coupon with this code.', 'woocommerce'));
}
$coupon = new WC_Coupon($post_id);
$coupon->set_props(array('code' => $post->post_title, 'discount_type' => wc_clean($_POST['discount_type']), 'amount' => wc_format_decimal($_POST['coupon_amount']), 'date_expires' => wc_clean($_POST['expiry_date']), 'individual_use' => isset($_POST['individual_use']), 'product_ids' => array_filter(array_map('intval', explode(',', $_POST['product_ids']))), 'excluded_product_ids' => array_filter(array_map('intval', explode(',', $_POST['exclude_product_ids']))), 'usage_limit' => absint($_POST['usage_limit']), 'usage_limit_per_user' => absint($_POST['usage_limit_per_user']), 'limit_usage_to_x_items' => absint($_POST['limit_usage_to_x_items']), 'free_shipping' => isset($_POST['free_shipping']), 'product_categories' => array_filter(array_map('intval', (array) $_POST['product_categories'])), 'excluded_product_categories' => array_filter(array_map('intval', (array) $_POST['exclude_product_categories'])), 'exclude_sale_items' => isset($_POST['exclude_sale_items']), 'minimum_amount' => wc_format_decimal($_POST['minimum_amount']), 'maximum_amount' => wc_format_decimal($_POST['maximum_amount']), 'email_restrictions' => array_filter(array_map('trim', explode(',', wc_clean($_POST['customer_email']))))));
$coupon->save();
do_action('woocommerce_coupon_options_save', $post_id);
}