本文整理汇总了PHP中WC_Coupon::get_generic_coupon_error方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Coupon::get_generic_coupon_error方法的具体用法?PHP WC_Coupon::get_generic_coupon_error怎么用?PHP WC_Coupon::get_generic_coupon_error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Coupon
的用法示例。
在下文中一共展示了WC_Coupon::get_generic_coupon_error方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: apply_coupon
/**
* AJAX apply coupon on checkout page
*/
public function apply_coupon()
{
check_ajax_referer('apply-coupon', 'security');
if (!empty($_POST['coupon_code'])) {
WC()->cart->add_discount(sanitize_text_field($_POST['coupon_code']));
} else {
wc_add_notice(WC_Coupon::get_generic_coupon_error(WC_Coupon::E_WC_COUPON_PLEASE_ENTER), 'error');
}
wc_print_notices();
die;
}
示例2: output
/**
* Output the cart shortcode.
*
* @access public
* @param array $atts
* @return void
*/
public static function output($atts)
{
global $woocommerce;
if (!defined('WOOCOMMERCE_CART')) {
define('WOOCOMMERCE_CART', true);
}
// Add Discount
if (!empty($_POST['apply_coupon'])) {
if (!empty($_POST['coupon_code'])) {
$woocommerce->cart->add_discount(sanitize_text_field($_POST['coupon_code']));
} else {
$woocommerce->add_error(WC_Coupon::get_generic_coupon_error(WC_Coupon::E_WC_COUPON_PLEASE_ENTER));
}
// Remove Coupon Codes
} elseif (isset($_GET['remove_discounts'])) {
$woocommerce->cart->remove_coupons($_GET['remove_discounts']);
// Update Shipping
} elseif (!empty($_POST['calc_shipping']) && $woocommerce->verify_nonce('cart')) {
$validation = $woocommerce->validation();
$woocommerce->shipping->reset_shipping();
$woocommerce->customer->calculated_shipping(true);
$country = woocommerce_clean($_POST['calc_shipping_country']);
$state = woocommerce_clean($_POST['calc_shipping_state']);
$postcode = apply_filters('woocommerce_shipping_calculator_enable_postcode', true) ? woocommerce_clean($_POST['calc_shipping_postcode']) : '';
$city = apply_filters('woocommerce_shipping_calculator_enable_city', false) ? woocommerce_clean($_POST['calc_shipping_city']) : '';
if ($postcode && !$validation->is_postcode($postcode, $country)) {
$woocommerce->add_error(__('Please enter a valid postcode/ZIP.', 'woocommerce'));
$postcode = '';
} elseif ($postcode) {
$postcode = $validation->format_postcode($postcode, $country);
}
if ($country) {
// Update customer location
$woocommerce->customer->set_location($country, $state, $postcode, $city);
$woocommerce->customer->set_shipping_location($country, $state, $postcode, $city);
$woocommerce->add_message(__('Shipping costs updated.', 'woocommerce'));
} else {
$woocommerce->customer->set_to_base();
$woocommerce->customer->set_shipping_to_base();
$woocommerce->add_message(__('Shipping costs updated.', 'woocommerce'));
}
do_action('woocommerce_calculated_shipping');
}
// Check cart items are valid
do_action('woocommerce_check_cart_items');
// Calc totals
$woocommerce->cart->calculate_totals();
if (sizeof($woocommerce->cart->get_cart()) == 0) {
//woocommerce_get_template( 'cart/cart-empty.php' );
woocommerce_get_template('checkout/form-checkout.php');
} else {
//woocommerce_get_template( 'cart/cart.php' );
woocommerce_get_template('checkout/form-checkout.php');
}
}
示例3: woocommerce_ajax_apply_coupon
/**
* AJAX apply coupon on checkout page
*
* @access public
* @return void
*/
function woocommerce_ajax_apply_coupon()
{
global $woocommerce;
check_ajax_referer('apply-coupon', 'security');
if (!empty($_POST['coupon_code'])) {
$woocommerce->cart->add_discount(sanitize_text_field($_POST['coupon_code']));
} else {
$woocommerce->add_error(WC_Coupon::get_generic_coupon_error(WC_Coupon::E_WC_COUPON_PLEASE_ENTER));
}
$woocommerce->show_messages();
die;
}
示例4: app_ref_code
function app_ref_code()
{
if (!session_id()) {
session_start();
}
global $woocommerce, $wpdb;
if ($_REQUEST['coupon_code'] != "") {
/* Checdk ref code is valid or not */
$query_to_ck = 'SELECT user_id FROM wp_usermeta WHERE meta_key = "genRefKey" and meta_value = "' . $_REQUEST['coupon_code'] . '"';
$result_to_ck = mysql_query($query_to_ck);
$array_to_check = mysql_fetch_array($result_to_ck);
if (!empty($array_to_check)) {
/****/
$user_id = get_current_user_id();
$query = 'SELECT user_id FROM wp_usermeta WHERE meta_key = "refKeyID" and meta_value = "' . $_REQUEST['coupon_code'] . '" and user_id=' . $user_id . '';
$result = mysql_query($query);
$array = mysql_fetch_array($result);
if (isset($_SESSION['flagCheck']) && in_array($_REQUEST['coupon_code'], $_SESSION['flagCheck'])) {
echo '-3';
exit;
}
if (empty($array)) {
update_user_meta($user_id, "temp", $_REQUEST['coupon_code']);
$_SESSION['flagCheck'][] = $_REQUEST['coupon_code'];
if (!empty($_REQUEST['coupon_code'])) {
$time = time();
$p = array('post_title' => $time, 'post_content' => '', 'post_name' => $time, 'post_status' => 'publish', 'post_type' => 'shop_coupon', 'post_author' => 1);
if ($id = wp_insert_post($p)) {
// Add metadata to post
update_post_meta($id, 'coupon_amount', get_user_meta(1, "rewordBonus", true));
update_post_meta($id, 'discount_type', 'fixed_cart');
update_user_meta(get_current_user_id(), 'temp', $_REQUEST['coupon_code']);
update_user_meta(get_current_user_id(), 'applied_coupon_id_track', $id);
}
$p_i = get_post($id);
if ($woocommerce->cart->add_discount(sanitize_text_field($p_i->post_title))) {
echo '1';
} else {
echo '-2';
}
} else {
$woocommerce->set_messages();
$woocommerce->add_error(WC_Coupon::get_generic_coupon_error(WC_Coupon::E_WC_COUPON_PLEASE_ENTER));
echo '-6';
}
} else {
echo '-3';
}
} else {
echo '-3';
}
}
/* */
exit;
}