本文整理汇总了PHP中wc_get_coupon_types函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_get_coupon_types函数的具体用法?PHP wc_get_coupon_types怎么用?PHP wc_get_coupon_types使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wc_get_coupon_types函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rf_meta_box
/**
* Creates the Referfriend Meta Box in the admin control panel when in the Giftcard Post Type. Allows you to create a giftcard manually.
* @param [type] $post
* @return [type]
*/
function rf_meta_box($post)
{
global $woocommerce;
wp_nonce_field('woocommerce_save_data', 'woocommerce_meta_nonce');
?>
<style type="text/css">
#edit-slug-box, #minor-publishing-actions { display:none }
.form-field input, .form-field textarea { width:100%;}
input[type="checkbox"], input[type="radio"] { float: left; width:16px;}
</style>
<div class="panel woocommerce_options_panel">
<?php
woocommerce_wp_select(array('id' => 'rf_coupon_type', 'label' => __('Coupon Type', 'mg_referfriend'), 'placeholder' => '', 'description' => __('Coupon Type', 'mg_referfriend'), 'options' => wc_get_coupon_types()));
woocommerce_wp_text_input(array('id' => 'rf_coupon_amount', 'label' => __('Coupon Amount', 'mg_referfriend'), 'placeholder' => '', 'description' => __('Coupon Amount', 'mg_referfriend'), 'type' => 'number', 'custom_attributes' => array('step' => 'any', 'min' => '0')));
woocommerce_wp_select(array('id' => 'rf_type', 'label' => __('Type', 'mg_referfriend'), 'placeholder' => '', 'options' => array('' => '', '1' => 'Refered by Email', '2' => 'Refered by share link')));
// Description
woocommerce_wp_textarea_input(array('id' => 'rf_description', 'label' => __('Description', 'rpgiftcards'), 'placeholder' => '', 'description' => __('Description', 'rpgiftcards')));
woocommerce_wp_text_input(array('id' => 'rf_product_id', 'label' => __('Product IDs', 'mg_referfriend'), 'placeholder' => '', 'description' => __('Product IDs', 'mg_referfriend'), 'type' => 'number'));
woocommerce_wp_text_input(array('id' => 'rf_usage', 'label' => __('Usage', 'mg_referfriend'), 'placeholder' => '', 'description' => __('Usage', 'mg_referfriend')));
woocommerce_wp_text_input(array('id' => 'rf_limit', 'label' => __('Limit', 'mg_referfriend'), 'placeholder' => '', 'description' => __('Limit', 'mg_referfriend')));
woocommerce_wp_text_input(array('id' => 'rf_expiry_date', 'label' => __('Expiry Date', 'mg_referfriend'), 'placeholder' => '', 'description' => __('Expiry Date', 'mg_referfriend')));
echo '</div>';
}
示例2: wc_get_coupon_type
/**
* Get a coupon type's name.
*
* @param string $type (default: '')
* @return string
*/
function wc_get_coupon_type($type = '')
{
$types = wc_get_coupon_types();
if (isset($types[$type])) {
return $types[$type];
}
return '';
}
示例3: wc_get_coupon_types
/**
* @since 1.1.0 of SA_WC_Compatibility
*/
public static function wc_get_coupon_types()
{
if (self::is_wc_21()) {
return wc_get_coupon_types();
} else {
global $woocommerce;
return $woocommerce->get_coupon_discount_types();
}
}
示例4: rf_genaral_setting
/**
* Get settings array
*
* @return array
*/
public function rf_genaral_setting($current_section = '')
{
$options = '';
$options = apply_filters('woocommerce_rf_genaral_setting', array(array('title' => __('Refer a Friend', 'mg_referfriend'), 'type' => 'title'), array('title' => __('Allow invite a friend', 'mg_referfriend'), 'id' => 'rf_enable_invitation', 'default' => 1, 'type' => 'checkbox'), array('title' => __('Allow share link', 'mg_referfriend'), 'id' => 'rf_enable_sharelink', 'default' => 1, 'type' => 'checkbox'), array('title' => __('Cookie of referral will expire after x days', 'mg_referfriend'), 'id' => 'rf_cookie_duration', 'default' => '30', 'type' => 'text'), array('title' => __('Reward affiliate and send notification email when status of order', 'mg_referfriend'), 'id' => 'magenest_rf_reward_when', 'type' => 'select', 'options' => array('completed' => __('Completed', 'mg_referfriend'), 'processing' => __('Processing', 'mg_referfriend'), 'on-hold' => __('On hold', 'mg_referfriend'), 'pending' => __('Pending', 'mg_referfriend')), 'autoload' => false), array('title' => __('Give bonus to referfal for friend registration', 'mg_referfriend'), 'id' => 'rf_bonus_signup', 'default' => 1, 'type' => 'checkbox'), array('name' => __('Coupon Amount for friend sign up', 'mg_referfriend'), 'desc' => __('This is the amount for the coupon sent after a friend received invitation and sign up', 'mg_referfriend'), 'id' => 'rf_coupon_sign_up_amount', 'type' => 'text'), array('type' => 'sectionend', 'id' => 'account_registration_options'), array('title' => __('Invitation Coupon Settings', 'mg_referfriend'), 'type' => 'title', 'desc' => __('Coupon is automatically insert in invitation email')), array('title' => __('Coupon Type', 'mg_referfriend'), 'id' => 'rf_invite_coupon_type', 'default' => 1, 'type' => 'select', 'options' => wc_get_coupon_types()), array('name' => __('Coupon Amount (in local currency)', 'mg_referfriend'), 'desc' => __('This is the amount for the coupon sent as a reward', 'mg_referfriend'), 'id' => 'rf_invite_coupon_amount', 'type' => 'text'), array('name' => __('Coupon Minimum Amount', 'mg_referfriend'), 'desc' => __('You can set minimum amount for the order', 'mg_referfriend'), 'id' => 'rf_invite_coupon_minimum_amount', 'type' => 'text'), array('name' => __('Coupon Duration', 'mg_referfriend'), 'desc' => __('Coupon duration is mandatory. Value is the number of days beginning on the coupong creation.', 'mg_referfriend'), 'id' => 'rf_invite_coupon_duration', 'type' => 'text'), array('title' => __('Individual Use', 'mg_referfriend'), 'desc' => __('individual use', 'mg_referfriend'), 'id' => 'rf_invite_individual_use', 'default' => 'no', 'type' => 'checkbox', 'autoload' => true), array('title' => __('Apply before tax', 'mg_referfriend'), 'desc' => __('Apply before tax', 'mg_referfriend'), 'id' => 'rf_invite_apply_before_tax', 'default' => 'no', 'type' => 'checkbox', 'autoload' => true), array('type' => 'sectionend', 'id' => 'product_referfriend_options'), array('title' => __('Reward Coupon Settings', 'mg_referfriend'), 'type' => 'title', 'desc' => __('Coupon is rewarded to referral after a friend received invitation email or follow the referral link and place order')), array('title' => __('Coupon Type', 'mg_referfriend'), 'id' => 'rf_reward_coupon_type', 'default' => 1, 'type' => 'select', 'options' => wc_get_coupon_types()), array('name' => __('Coupon Amount', 'mg_referfriend'), 'desc' => __('This is the amount for the coupon sent as a reward', 'mg_referfriend'), 'id' => 'rf_reward_coupon_amount', 'type' => 'text'), array('name' => __('Coupon Minimum Amount', 'mg_referfriend'), 'desc' => __('You can set minimum amount for the order', 'mg_referfriend'), 'id' => 'rf_reward_coupon_minimum_amount', 'type' => 'text'), array('name' => __('Coupon Duration', 'mg_referfriend'), 'desc' => __('Coupon duration is mandatory. Value is the number of days beginning on the coupong creation.', 'mg_referfriend'), 'id' => 'rf_reward_coupon_duration', 'type' => 'text'), array('title' => __('Individual Use', 'mg_referfriend'), 'desc' => __('individual use', 'mg_referfriend'), 'id' => 'rf_reward_individual_use', 'default' => 'no', 'type' => 'checkbox', 'autoload' => true), array('title' => __('Apply before tax', 'mg_referfriend'), 'desc' => __('Apply before tax', 'mg_referfriend'), 'id' => 'rf_reward_apply_before_tax', 'default' => 'no', 'type' => 'checkbox', 'autoload' => true), array('type' => 'sectionend', 'id' => 'product_referfriend_options')));
return apply_filters('rf_general_setting', $options);
}
示例5: get_editables_data
/**
* @see CACIE_Editable_Model::get_editables_data()
* @since 1.0
*/
public function get_editables_data()
{
$data = array('author' => array('type' => 'select2_dropdown', 'property' => 'post_author', 'ajax_populate' => true), 'categories' => array('type' => 'select2_tags'), 'date' => array('type' => 'date', 'property' => 'post_date'), 'tags' => array('type' => 'select2_tags'), 'title' => array('type' => 'text', 'property' => 'post_title', 'js' => array('selector' => 'a.row-title'), 'display_ajax' => false), 'column-author_name' => array('type' => 'select2_dropdown', 'property' => 'post_author', 'ajax_populate' => true), 'column-attachment' => array('type' => 'media', 'attachment' => array('disable_select_current' => true), 'multiple' => true), 'column-comment_status' => array('type' => 'togglable', 'property' => 'comment_status', 'options' => array('closed', 'open')), 'column-excerpt' => array('type' => 'textarea', 'property' => 'post_excerpt', 'placeholder' => __('Excerpt automatically generated from content.', 'cpac')), 'column-featured_image' => array('type' => 'media', 'attachment' => array('library' => array('type' => 'image')), 'clear_button' => true), 'column-post_formats' => array('type' => 'select'), 'column-page_template' => array('type' => 'select'), 'column-parent' => array('type' => 'select2_dropdown', 'property' => 'post_parent', 'ajax_populate' => true, 'multiple' => false), 'column-ping_status' => array('type' => 'togglable', 'property' => 'ping_status', 'options' => array('closed', 'open')), 'column-content' => array('type' => 'textarea', 'property' => 'post_content'), 'column-order' => array('type' => 'text', 'property' => 'menu_order'), 'column-slug' => array('type' => 'text', 'property' => 'post_name'), 'column-sticky' => array('type' => 'togglable', 'options' => array('no', 'yes')), 'column-status' => array('type' => 'select', 'property' => 'post_status'), 'column-taxonomy' => array('type' => 'select2_tags'), 'column-meta' => array());
/**
* WooCommerce columns
*
*/
if (function_exists('WC')) {
$wc_data = array('name' => array('type' => 'text', 'property' => 'post_title', 'js' => array('selector' => 'a.row-title'), 'display_ajax' => false), 'amount' => array('type' => 'text'), 'column-wc-minimum_amount' => array('type' => 'text'), 'order_status' => array('type' => 'select'), 'coupon_code' => array('type' => 'text', 'js' => array('selector' => '.row-actions'), 'property' => 'post_title'), 'column-wc-free_shipping' => array('type' => 'togglable', 'options' => array('no', 'yes')), 'column-wc-apply_before_tax' => array('type' => 'togglable', 'options' => array('no', 'yes')), 'price' => array('type' => 'wc_price'), 'column-wc-weight' => array('type' => 'float', 'js' => array('inputclass' => 'small-text')), 'column-wc-dimensions' => array('type' => 'dimensions'), 'sku' => array('type' => 'text'), 'is_in_stock' => array('type' => 'wc_stock'), 'column-wc-stock-status' => array('type' => 'togglable', 'options' => array('outofstock', 'instock')), 'type' => array('type' => 'select', 'options' => wc_get_coupon_types()), 'thumb' => array('type' => 'media', 'attachment' => array('library' => array('type' => 'image')), 'clear_button' => true), 'column-wc-upsells' => array('type' => 'select2_dropdown', 'ajax_populate' => true, 'advanced_dropdown' => true, 'multiple' => true), 'column-wc-crosssells' => array('type' => 'select2_dropdown', 'ajax_populate' => true, 'advanced_dropdown' => true, 'multiple' => true), 'column-wc-exclude_products' => array('type' => 'select2_dropdown', 'ajax_populate' => true, 'advanced_dropdown' => true, 'multiple' => true), 'column-wc-include_products' => array('type' => 'select2_dropdown', 'ajax_populate' => true, 'advanced_dropdown' => true, 'multiple' => true), 'column-wc-shipping_class' => array('type' => 'select'), 'usage' => array('type' => 'wc_usage'), 'description' => array('type' => 'textarea', 'property' => 'post_excerpt'), 'column-wc-reviews_enabled' => array('type' => 'togglable', 'property' => 'comment_status', 'options' => array('closed', 'open')), 'column-wc-backorders_allowed' => array('type' => 'select', 'options' => array('no' => __('Do not allow', 'woocommerce'), 'notify' => __('Allow, but notify customer', 'woocommerce'), 'yes' => __('Allow', 'woocommerce'))), 'product_cat' => array('type' => 'select2_tags'), 'product_tag' => array('type' => 'select2_tags'), 'column-wc-featured' => array('type' => 'togglable', 'options' => array('no', 'yes')), 'column-wc-visibility' => array('type' => 'select'));
$data = array_merge($wc_data, $data);
}
// Handle capabilities for editing post status
$post_type_object = get_post_type_object($this->storage_model->get_post_type());
if (!current_user_can($post_type_object->cap->publish_posts)) {
unset($data['column-status']);
}
/**
* Filter the editability settings for a column
*
* @since 3.4
*
* @param array $data {
* Editability settings.
*
* @type string $type Editability type. Accepts 'text', 'select', 'textarea', etc.
* @type array $options Optional. Options for dropdown ([value] => [label]), only used when $type is "select"
* }
* @param CACIE_Editable_Model $model Editability storage model
*/
$data = apply_filters('cac/editable/editables_data', $data, $this);
$data = apply_filters('cac/editable/editables_data/type=' . $this->storage_model->get_type(), $data, $this);
$data = apply_filters('cac/editable/editables_data/post_type=' . $this->storage_model->get_post_type(), $data, $this);
return $data;
}
示例6: wc_get_coupon_type
/**
* Get a coupon type's name.
*
* @param string $type (default: '')
* @return string
*/
function wc_get_coupon_type($type = '')
{
$types = wc_get_coupon_types();
return isset($types[$type]) ? $types[$type] : '';
}
示例7: output
/**
* Output the metabox
*/
public static function output($post)
{
wp_nonce_field('woocommerce_save_data', 'woocommerce_meta_nonce');
?>
<style type="text/css">
#edit-slug-box, #minor-publishing-actions { display:none }
</style>
<div id="coupon_options" class="panel-wrap coupon_data">
<div class="wc-tabs-back"></div>
<ul class="coupon_data_tabs wc-tabs" style="display:none;">
<?php
$coupon_data_tabs = apply_filters('woocommerce_coupon_data_tabs', array('general' => array('label' => __('General', 'woocommerce'), 'target' => 'general_coupon_data', 'class' => 'general_coupon_data'), 'usage_restriction' => array('label' => __('Usage Restriction', 'woocommerce'), 'target' => 'usage_restriction_coupon_data', 'class' => ''), 'usage_limit' => array('label' => __('Usage Limits', 'woocommerce'), 'target' => 'usage_limit_coupon_data', 'class' => '')));
foreach ($coupon_data_tabs as $key => $tab) {
?>
<li class="<?php
echo $key;
?>
_options <?php
echo $key;
?>
_tab <?php
echo implode(' ', (array) $tab['class']);
?>
">
<a href="#<?php
echo $tab['target'];
?>
"><?php
echo esc_html($tab['label']);
?>
</a>
</li><?php
}
?>
</ul>
<div id="general_coupon_data" class="panel woocommerce_options_panel"><?php
// Type
woocommerce_wp_select(array('id' => 'discount_type', 'label' => __('Discount type', 'woocommerce'), 'options' => wc_get_coupon_types()));
// Amount
woocommerce_wp_text_input(array('id' => 'coupon_amount', 'label' => __('Coupon amount', 'woocommerce'), 'placeholder' => wc_format_localized_price(0), 'description' => __('Value of the coupon.', 'woocommerce'), 'data_type' => 'price', 'desc_tip' => true));
// Free Shipping
woocommerce_wp_checkbox(array('id' => 'free_shipping', 'label' => __('Allow free shipping', 'woocommerce'), 'description' => sprintf(__('Check this box if the coupon grants free shipping. The <a href="%s">free shipping method</a> must be enabled with the "must use coupon" setting.', 'woocommerce'), admin_url('admin.php?page=wc-settings&tab=shipping§ion=WC_Shipping_Free_Shipping'))));
// Apply before tax
woocommerce_wp_checkbox(array('id' => 'apply_before_tax', 'label' => __('Apply before tax', 'woocommerce'), 'description' => __('Check this box if the coupon should be applied before calculating cart tax.', 'woocommerce')));
// Expiry date
woocommerce_wp_text_input(array('id' => 'expiry_date', 'label' => __('Coupon expiry date', 'woocommerce'), 'placeholder' => _x('YYYY-MM-DD', 'placeholder', 'woocommerce'), 'description' => '', 'class' => 'date-picker', 'custom_attributes' => array('pattern' => "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])")));
do_action('woocommerce_coupon_options');
?>
</div>
<div id="usage_restriction_coupon_data" class="panel woocommerce_options_panel"><?php
echo '<div class="options_group">';
// minimum spend
woocommerce_wp_text_input(array('id' => 'minimum_amount', 'label' => __('Minimum spend', 'woocommerce'), 'placeholder' => __('No minimum', 'woocommerce'), 'description' => __('This field allows you to set the minimum subtotal needed to use the coupon.', 'woocommerce'), 'data_type' => 'price', 'desc_tip' => true));
// maximum spend
woocommerce_wp_text_input(array('id' => 'maximum_amount', 'label' => __('Maximum spend', 'woocommerce'), 'placeholder' => __('No maximum', 'woocommerce'), 'description' => __('This field allows you to set the maximum subtotal allowed when using the coupon.', 'woocommerce'), 'data_type' => 'price', 'desc_tip' => true));
// Individual use
woocommerce_wp_checkbox(array('id' => 'individual_use', 'label' => __('Individual use only', 'woocommerce'), 'description' => __('Check this box if the coupon cannot be used in conjunction with other coupons.', 'woocommerce')));
// Exclude Sale Products
woocommerce_wp_checkbox(array('id' => 'exclude_sale_items', 'label' => __('Exclude sale items', 'woocommerce'), 'description' => __('Check this box if the coupon should not apply to items on sale. Per-item coupons will only work if the item is not on sale. Per-cart coupons will only work if there are no sale items in the cart.', 'woocommerce')));
echo '</div><div class="options_group">';
// Product ids
?>
<p class="form-field"><label for="product_ids"><?php
_e('Products', 'woocommerce');
?>
</label>
<select id="product_ids" name="product_ids[]" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="<?php
_e('Search for a product…', 'woocommerce');
?>
">
<?php
$product_ids = get_post_meta($post->ID, 'product_ids', true);
if ($product_ids) {
$product_ids = array_map('absint', explode(',', $product_ids));
foreach ($product_ids as $product_id) {
$product = wc_get_product($product_id);
echo '<option value="' . esc_attr($product_id) . '" selected="selected">' . wp_kses_post($product->get_formatted_name()) . '</option>';
}
}
?>
</select> <img class="help_tip" data-tip='<?php
_e('Products which need to be in the cart to use this coupon or, for "Product Discounts", which products are discounted.', 'woocommerce');
?>
' src="<?php
echo WC()->plugin_url();
?>
/assets/images/help.png" height="16" width="16" /></p>
<?php
// Exclude Product ids
?>
<p class="form-field"><label for="exclude_product_ids"><?php
_e('Exclude products', 'woocommerce');
?>
</label>
<select id="exclude_product_ids" name="exclude_product_ids[]" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="<?php
//.........这里部分代码省略.........
示例8: shop_coupon_filters
/**
* Show custom filters to filter coupons by type.
*/
public function shop_coupon_filters()
{
?>
<select name="coupon_type" id="dropdown_shop_coupon_type">
<option value=""><?php
_e('Show all types', 'woocommerce');
?>
</option>
<?php
$types = wc_get_coupon_types();
foreach ($types as $name => $type) {
echo '<option value="' . esc_attr($name) . '"';
if (isset($_GET['coupon_type'])) {
selected($name, $_GET['coupon_type']);
}
echo '>' . esc_html__($type, 'woocommerce') . '</option>';
}
?>
</select>
<?php
}
示例9: update
/**
* Update one or more coupons.
*
* ## OPTIONS
*
* <coupon>
* : The ID or code of the coupon to update.
*
* --<field>=<value>
* : One or more fields to update.
*
* ## AVAILABLE FIELDS
*
* These fields are available for update command:
*
* * code
* * type
* * amount
* * description
* * expiry_date
* * individual_use
* * product_ids
* * exclude_product_ids
* * usage_limit
* * usage_limit_per_user
* * limit_usage_to_x_items
* * usage_count
* * enable_free_shipping
* * product_category_ids
* * exclude_product_categories
* * exclude_product_category_ids
* * minimum_amount
* * maximum_amount
* * customer_emails
*
* ## EXAMPLES
*
* wp wc coupon update 123 --amount=5
*
* wp wc coupon update coupon-code --code=new-coupon-code
*
* @since 2.5.0
*/
public function update($args, $assoc_args)
{
try {
$coupon = $this->get_coupon_from_id_or_code($args[0]);
if (!$coupon) {
throw new WC_CLI_Exception('woocommerce_cli_invalid_coupon', sprintf(__('Invalid coupon ID or code: %s', 'woocommerce'), $args[0]));
}
$id = $coupon->id;
$coupon_code = $coupon->code;
$data = apply_filters('woocommerce_cli_update_coupon_data', $assoc_args, $id);
if (isset($data['code'])) {
global $wpdb;
$coupon_code = apply_filters('woocommerce_coupon_code', $data['code']);
// Check for duplicate coupon codes
$coupon_found = $wpdb->get_var($wpdb->prepare("\n\t\t\t\t\tSELECT {$wpdb->posts}.ID\n\t\t\t\t\tFROM {$wpdb->posts}\n\t\t\t\t\tWHERE {$wpdb->posts}.post_type = 'shop_coupon'\n\t\t\t\t\tAND {$wpdb->posts}.post_status = 'publish'\n\t\t\t\t\tAND {$wpdb->posts}.post_title = '%s'\n\t\t\t\t\tAND {$wpdb->posts}.ID != %s\n\t\t\t\t ", $coupon_code, $id));
if ($coupon_found) {
throw new WC_CLI_Exception('woocommerce_cli_coupon_code_already_exists', __('The coupon code already exists', 'woocommerce'));
}
}
$id = wp_update_post(array('ID' => intval($id), 'post_title' => $coupon_code, 'post_excerpt' => isset($data['description']) ? $data['description'] : ''));
if (0 === $id) {
throw new WC_CLI_Exception('woocommerce_cli_cannot_update_coupon', __('Failed to update coupon', 'woocommerce'));
}
if (isset($data['type'])) {
// Validate coupon types.
if (!in_array(wc_clean($data['type']), array_keys(wc_get_coupon_types()))) {
throw new WC_CLI_Exception('woocommerce_cli_invalid_coupon_type', sprintf(__('Invalid coupon type - the coupon type must be any of these: %s', 'woocommerce'), implode(', ', array_keys(wc_get_coupon_types()))));
}
update_post_meta($id, 'discount_type', $data['type']);
}
if (isset($data['amount'])) {
update_post_meta($id, 'coupon_amount', wc_format_decimal($data['amount']));
}
if (isset($data['individual_use'])) {
update_post_meta($id, 'individual_use', true === $data['individual_use'] ? 'yes' : 'no');
}
if (isset($data['product_ids'])) {
update_post_meta($id, 'product_ids', implode(',', array_filter(array_map('intval', $data['product_ids']))));
}
if (isset($data['exclude_product_ids'])) {
update_post_meta($id, 'exclude_product_ids', implode(',', array_filter(array_map('intval', $data['exclude_product_ids']))));
}
if (isset($data['usage_limit'])) {
update_post_meta($id, 'usage_limit', absint($data['usage_limit']));
}
if (isset($data['usage_limit_per_user'])) {
update_post_meta($id, 'usage_limit_per_user', absint($data['usage_limit_per_user']));
}
if (isset($data['limit_usage_to_x_items'])) {
update_post_meta($id, 'limit_usage_to_x_items', absint($data['limit_usage_to_x_items']));
}
if (isset($data['usage_count'])) {
update_post_meta($id, 'usage_count', absint($data['usage_count']));
}
if (isset($data['expiry_date'])) {
update_post_meta($id, 'expiry_date', $this->get_coupon_expiry_date(wc_clean($data['expiry_date'])));
}
//.........这里部分代码省略.........
示例10: array
//Array for advanced search
$wpec_products_cols_advanced_search = $products_cols;
} else {
if (WOO_RUNNING === true) {
$products_search_cols = array();
//array for advanced search autocomplete
// ==============================================================
// Coupons Code
// ==============================================================
$couponfieldsResults = array();
$couponfieldsquery = "SELECT DISTINCT meta_key FROM {$wpdb->prefix}postmeta WHERE meta_key IN\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t('discount_type','coupon_amount','individual_use','coupon_title_suffix',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'apply_before_tax','free_shipping','coupon_title_prefix','exclude_sale_items',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'usage_limit','expiry_date','minimum_amount','usage_count')";
$couponfieldsResults = $wpdb->get_results($couponfieldsquery, ARRAY_A);
if (empty($couponfieldsResults)) {
$couponfieldsResults = array(array('meta_key' => 'apply_before_tax'), array('meta_key' => 'coupon_amount'), array('meta_key' => 'discount_type'), array('meta_key' => 'exclude_sale_items'), array('meta_key' => 'expiry_date'), array('meta_key' => 'free_shipping'), array('meta_key' => 'individual_use'), array('meta_key' => 'minimum_amount'), array('meta_key' => 'usage_count'), array('meta_key' => 'usage_limit'));
}
$select_box = SM_IS_WOO21 == "true" || SM_IS_WOO22 == "true" ? wc_get_coupon_types() : $woocommerce->get_coupon_discount_types();
$select_box_keys = array_keys($select_box);
$couponfield_names_select = array();
$i = 0;
foreach ($select_box as $select_box1) {
$couponfield_names_select[$i][0] = $select_box_keys[$i];
$couponfield_names_select[$i][1] = $select_box1;
$i++;
}
$cnt = 0;
$couponfield_names['items'][$cnt]['id'] = $cnt;
$couponfield_names['items'][$cnt]['name'] = 'Coupon Name';
$couponfield_names['items'][$cnt]['type'] = 'string';
$couponfield_names['items'][$cnt]['table'] = "posts";
$couponfield_names['items'][$cnt]['value'] = 'post_title';
$cnt++;
示例11: test_wc_get_coupon_types
/**
* Test wc_get_coupon_types().
*
* @since 2.2
*/
public function test_wc_get_coupon_types()
{
$coupon_types = array('fixed_cart' => 'Cart discount', 'percent' => 'Cart % discount', 'fixed_product' => 'Product discount', 'percent_product' => 'Product % discount');
$this->assertEquals($coupon_types, wc_get_coupon_types());
}
示例12: get_discount_types
public static function get_discount_types()
{
global $woocommerce;
return function_exists('wc_get_coupon_types') ? wc_get_coupon_types() : $woocommerce->get_coupon_discount_types();
}
示例13: update_coupon
/**
* Update a coupon
*
* @since 3.0.0
* @param int $id the coupon ID
* @param array $data
* @param array $options
* @return array|WP_Error
*/
public function update_coupon($id, $data, $options = array())
{
try {
$id = absint($id);
// validate the coupon ID.
if (empty($id)) {
throw new WC_CSV_Import_Suite_Import_Exception('wc_csv_import_suite_invalid_coupon_id', __('Invalid coupon ID', 'woocommerce-csv-import-suite'));
}
$post = get_post($id);
if (null === $post) {
throw new WC_CSV_Import_Suite_Import_Exception('wc_csv_import_suite_no_coupon_found', sprintf(__('No coupon found with the ID equal to %s', 'woocommerce-csv-import-suite'), $id));
}
// validate post type
if ('shop_coupon' !== $post->post_type) {
throw new WC_CSV_Import_Suite_Import_Exception('wc_csv_import_suite_invalid_coupon', __('Invalid coupon', 'woocommerce-csv-import-suite'));
}
/**
* Filter data that is going to be updated for a coupon via CSV
*
* @since 3.0.0
* @param array $data
* @param array $options
* @param object $this
*/
$data = apply_filters('wc_csv_import_suite_update_coupon_data', $data, $options, $this);
$coupon_data = array();
if (isset($data['code'])) {
global $wpdb;
$coupon_code = apply_filters('woocommerce_coupon_code', $data['code']);
// check for duplicate coupon codes
$coupon_found = $wpdb->get_var($wpdb->prepare("\n\t\t\t\t\tSELECT {$wpdb->posts}.ID\n\t\t\t\t\tFROM {$wpdb->posts}\n\t\t\t\t\tWHERE {$wpdb->posts}.post_type = 'shop_coupon'\n\t\t\t\t\tAND {$wpdb->posts}.post_status = 'publish'\n\t\t\t\t\tAND {$wpdb->posts}.post_title = '%s'\n\t\t\t\t\tAND {$wpdb->posts}.ID != %s\n\t\t\t\t ", $coupon_code, $id));
if ($coupon_found) {
throw new WC_CSV_Import_Suite_Import_Exception('wc_csv_import_suite_coupon_code_already_exists', __('The coupon code already exists', 'woocommerce-csv-import-suite'));
}
$coupon_data['post_title'] = $coupon_code;
}
if (isset($data['description'])) {
$coupon_data['post_excerpt'] = $data['description'];
}
if (!empty($coupon_data)) {
$coupon_data['ID'] = intval($id);
$updated = wp_update_post(array('ID' => intval($id), 'post_title' => $coupon_code), $wp_error = true);
if (is_wp_error($updated)) {
throw new WC_CSV_Import_Suite_Import_Exception($id->get_error_code(), $id->get_error_message());
}
}
// validate coupon types
if (isset($data['type'])) {
if (!in_array(wc_clean($data['type']), array_keys(wc_get_coupon_types()))) {
throw new WC_CSV_Import_Suite_Import_Exception('wc_csv_import_suite_invalid_coupon_type', sprintf(__('Invalid coupon type - the coupon type must be any of these: %s', 'woocommerce-csv-import-suite'), implode(', ', array_keys(wc_get_coupon_types()))));
}
}
// update coupon data
$this->update_coupon_data($id, $data, $options);
/**
* Triggered after a coupon has been updated via CSV import
*
* @since 3.0.0
* @param int $id Coupon ID
* @param array $data Data from CSV
* @param array $options Import options
*/
do_action('wc_csv_import_suite_update_coupon', $id, $data);
return $id;
} catch (WC_CSV_Import_Suite_Import_Exception $e) {
return new WP_Error($e->getErrorCode(), $e->getMessage());
}
}
示例14: getCouponData
protected function getCouponData($i05355412b857f5174e9a2f71b1e936a86ad60cd287395dcafb6eb7221410dbcd87e9e8ce0007214a)
{
$iced8cbcfca3c880f0f157e119d1cc6f8691e7e89 = (array) get_post($i05355412b857f5174e9a2f71b1e936a86ad60cd287395dcafb6eb7221410dbcd87e9e8ce0007214a);
$i05355412b857f5174e9a2f71b1e936a86ad60cd218327082d2290372922428ae0ac10d179dcc0334 = get_post_meta($i05355412b857f5174e9a2f71b1e936a86ad60cd287395dcafb6eb7221410dbcd87e9e8ce0007214a);
$i05355412b857f5174e9a2f71b1e936a86ad60cd2c2328e91b7d7f67ee535f97a7c0a148b48f30b57 = wc_get_coupon_types();
foreach ($i05355412b857f5174e9a2f71b1e936a86ad60cd218327082d2290372922428ae0ac10d179dcc0334 as $i05355412b857f5174e9a2f71b1e936a86ad60cd27baa31be52215025da340cfec29600d8d2b327c4 => $i05355412b857f5174e9a2f71b1e936a86ad60cd2e10f888510a016f5ea5f46b736afa9e60fb62395) {
if ($i05355412b857f5174e9a2f71b1e936a86ad60cd27baa31be52215025da340cfec29600d8d2b327c4 == "discount_type") {
$iced8cbcfca3c880f0f157e119d1cc6f8691e7e89["type"] = $i05355412b857f5174e9a2f71b1e936a86ad60cd2c2328e91b7d7f67ee535f97a7c0a148b48f30b57[$i05355412b857f5174e9a2f71b1e936a86ad60cd2e10f888510a016f5ea5f46b736afa9e60fb62395[0]];
}
$iced8cbcfca3c880f0f157e119d1cc6f8691e7e89[$i05355412b857f5174e9a2f71b1e936a86ad60cd27baa31be52215025da340cfec29600d8d2b327c4] = $i05355412b857f5174e9a2f71b1e936a86ad60cd2e10f888510a016f5ea5f46b736afa9e60fb62395[0];
}
return $iced8cbcfca3c880f0f157e119d1cc6f8691e7e89;
}
示例15: get_coupon_discount_types
/**
* @deprecated 2.1.0
* @return array
*/
public function get_coupon_discount_types()
{
_deprecated_function('Woocommerce->get_coupon_discount_types', '2.1', 'wc_get_coupon_types');
return wc_get_coupon_types();
}