本文整理汇总了PHP中wc_add_notice函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_add_notice函数的具体用法?PHP wc_add_notice怎么用?PHP wc_add_notice使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wc_add_notice函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: wc_redirects__add_to_cart_redirect
function wc_redirects__add_to_cart_redirect($url)
{
static $cached_result = null;
if (isset($cached_result)) {
return $cached_result;
}
if (!isset($_REQUEST['add-to-cart'])) {
return $url;
}
$product_id = apply_filters('woocommerce_add_to_cart_product_id', absint($_REQUEST['add-to-cart']));
$selected_redirection_type = get_post_meta($product_id, WC_REDIRECTS__REDIRECTION_TYPE_META_NAME, true);
if (!empty($selected_redirection_type)) {
foreach (wc_redirects__get_valid_redirection_types() as $redirection_type) {
if ($redirection_type['name'] === $selected_redirection_type) {
$result = call_user_func($redirection_type['callback']);
if ($result === false) {
wc_add_notice("Item added to cart, but redirection " . "to {$redirection_type['label']} failed.");
} else {
$url = $result;
}
break;
}
}
}
return $cached_result = $url;
}
示例3: calculate_shipping
/**
* Calculate shipping for the cart
*/
public static function calculate_shipping()
{
try {
WC()->shipping->reset_shipping();
$country = wc_clean($_POST['calc_shipping_country']);
$state = wc_clean(isset($_POST['calc_shipping_state']) ? $_POST['calc_shipping_state'] : '');
$postcode = apply_filters('woocommerce_shipping_calculator_enable_postcode', true) ? wc_clean($_POST['calc_shipping_postcode']) : '';
$city = apply_filters('woocommerce_shipping_calculator_enable_city', false) ? wc_clean($_POST['calc_shipping_city']) : '';
if ($postcode && !WC_Validation::is_postcode($postcode, $country)) {
throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce'));
} elseif ($postcode) {
$postcode = wc_format_postcode($postcode, $country);
}
if ($country) {
WC()->customer->set_location($country, $state, $postcode, $city);
WC()->customer->set_shipping_location($country, $state, $postcode, $city);
} else {
WC()->customer->set_to_base();
WC()->customer->set_shipping_to_base();
}
WC()->customer->calculated_shipping(true);
wc_add_notice(__('Shipping costs updated.', 'woocommerce'), 'notice');
do_action('woocommerce_calculated_shipping');
} catch (Exception $e) {
if (!empty($e)) {
wc_add_notice($e->getMessage(), 'error');
}
}
}
示例4: checkout_validate_vat
public static function checkout_validate_vat()
{
check_ajax_referer('update-order-review', 'security');
if (!isset($_POST['vat_id']) || !isset($_POST['country'])) {
die;
}
$country = sanitize_text_field($_POST['country']);
$vat_id = trim(preg_replace("/[^a-z0-9.]+/i", "", sanitize_text_field($_POST['vat_id'])));
// Strip away country code
if (substr($vat_id, 0, 2) == $country) {
$vat_id = substr($vat_id, 2);
}
if (WC_GZDP_VAT_Helper::instance()->validate($country, $vat_id)) {
// Add price vat filters..
add_filter('woocommerce_cart_get_taxes', array(__CLASS__, "remove_taxes"), 0, 2);
echo json_encode(array('valid' => true, 'vat_id' => $country . '-' . $vat_id));
} else {
wc_add_notice(__('VAT ID seems to be invalid.', 'woocommerce-germanized-pro'), 'error');
ob_start();
wc_print_notices();
$messages = ob_get_clean();
echo json_encode(array('valid' => false, 'error' => $messages));
}
die;
}
示例5: cancel_booking
/**
* Cancel a booking.
*/
public static function cancel_booking()
{
if (isset($_GET['cancel_booking']) && isset($_GET['booking_id'])) {
$booking_id = absint($_GET['booking_id']);
$booking = get_wc_booking($booking_id);
$booking_can_cancel = $booking->has_status(apply_filters('woocommerce_valid_booking_statuses_for_cancel', array('unpaid', 'pending-confirmation', 'confirmed', 'paid')));
$redirect = $_GET['redirect'];
if ($booking->has_status('cancelled')) {
// Already cancelled - take no action
} elseif ($booking_can_cancel && $booking->id == $booking_id && isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'woocommerce-bookings-cancel_booking')) {
// Cancel the booking
$booking->update_status('cancelled');
WC_Cache_Helper::get_transient_version('bookings', true);
// Message
wc_add_notice(apply_filters('woocommerce_booking_cancelled_notice', __('Your booking was cancelled.', 'woocommerce-bookings')), apply_filters('woocommerce_booking_cancelled_notice_type', 'notice'));
do_action('woocommerce_bookings_cancelled_booking', $booking->id);
} elseif (!$booking_can_cancel) {
wc_add_notice(__('Your booking can no longer be cancelled. Please contact us if you need assistance.', 'woocommerce-bookings'), 'error');
} else {
wc_add_notice(__('Invalid booking.', 'woocommerce-bookings'), 'error');
}
if ($redirect) {
wp_safe_redirect($redirect);
exit;
}
}
}
示例6: wc_minimum_order_amount
function wc_minimum_order_amount()
{
global $woocommerce;
$postcode = get_user_meta(get_current_user_id(), 'shipping_postcode', true);
if (strstr(' 90024 90027 90028 90029 90034 90036 90038 90039 90046 90048 90064 90066 90067 90068 90069 90095 90230 90291 90401 90402 90403 90404 90405 91505 91506 91602 91604 91607 91608 90010 90012 90019 90020 90025 90232 91601 91606 90073 90031 90090 90005 90004 90026 90035 90056 90211 90212 ', $postcode)) {
$minimum = 60;
} else {
if (strstr(' 90045 90049 90016 90292 91423 90008 90018 90045 90049 90210 90245 90272 90293 90077 90094 91403 91436 90079 90210 90007 90015 90017 90057 90071 90089 90266 90013 90014 ', $postcode)) {
$minimum = 100;
} else {
$minimum = false;
}
}
if ($minimum == false) {
wc_print_notice(sprintf('We are unable to service your area at this time. Please give us a call at (323) 450-7708 to discuss arrangements for your delivery.', wc_price($minimum), wc_price(WC()->cart->subtotal)), 'error');
echo "<script>\n\t\t\t\tjQuery(document).ready(function(\$) {\n\t\t\t\t\t\$('.checkout-button').addClass('disabled');\n\t\t\t\t\t\$('.checkout-button').click(function(e) { e.preventDefault(); });\n\t\t\t\t});\n\t\t\t</script>";
} elseif (WC()->cart->subtotal < $minimum) {
if (is_cart()) {
wc_print_notice(sprintf('Based on your zip code ' . $postcode . ', you must have an order with a minimum of %s to checkout. Your current order total is %s.', wc_price($minimum), wc_price(WC()->cart->subtotal)), 'error');
echo "\n\t\t\t\t<script>\n\t\t\t\t\tjQuery(document).ready(function(\$) {\n\t\t\t\t\t\t\$('.checkout-button').addClass('disabled');\n\t\t\t\t\t\t\$('.checkout-button').click(function(e) { e.preventDefault(); });\n\t\t\t\t\t});\n\t\t\t\t</script>";
} else {
wc_add_notice(sprintf('Based on your zip code ' . $postcode . ', you must have an order with a minimum of %s to checkout. Your current order total is %s.', wc_price($minimum), wc_price(WC()->cart->subtotal)), 'error');
}
}
}
示例7: renew_handler
/**
* Handle a renewal url
*/
public function renew_handler()
{
if (!empty($_GET['renew_licence']) && is_user_logged_in()) {
global $wpdb;
$licence_key = sanitize_text_field($_GET['renew_licence']);
$licence = $wpdb->get_row($wpdb->prepare("\n\t\t\t\tSELECT * FROM {$wpdb->prefix}wp_plugin_licencing_licences\n\t\t\t\tWHERE licence_key = %s\n\t\t\t\tAND ( user_id = %d OR user_id = 0 )\n\t\t\t", $licence_key, get_current_user_id()));
// Renewable?
if (!$licence) {
wc_add_notice(__('Invalid licence', 'wp-plugin-licencing'), 'error');
return;
}
if (!$licence->date_expires || strtotime($licence->date_expires) > current_time('timestamp')) {
wc_add_notice(__('This licence does not need to be renewed yet', 'wp-plugin-licencing'), 'notice');
return;
}
// Purchasable?
$product = get_product($licence->product_id);
if (!$product->is_purchasable()) {
wc_add_notice(__('This product can no longer be purchased', 'wp-plugin-licencing'), 'error');
return;
}
// Add to cart
WC()->cart->empty_cart();
WC()->cart->add_to_cart($licence->product_id, 1, '', '', array('renewing_key' => $licence_key));
// Message
wc_add_notice(sprintf(__('The product has been added to your cart with a %d%% discount.', 'wp-plugin-licencing'), apply_filters('wp_plugin_licencing_renewal_discount_percent', 30)), 'success');
// Redirect to checkout
wp_redirect(get_permalink(wc_get_page_id('checkout')));
exit;
}
}
示例8: validate_add_cart_item
public function validate_add_cart_item($passed, $product_id, $qty)
{
$product = get_product($product_id);
if ($product->product_type !== 'trip') {
return $passed;
}
$stockOk = false;
foreach ($this->package_types as $package) {
if (isset($_POST['wc_trip_' . $package . "_package"])) {
$post = $_POST['wc_trip_' . $package . "_package"];
$stockCheck = $product->check_package_stock($package, $post);
if ($stockCheck) {
$stockOk = true;
} else {
wc_add_notice("Sorry, " . $post . " is out of stock", 'error');
return false;
}
}
}
if ($stockOk) {
return true;
} else {
wc_add_notice("Couldn't find specified packages, try again", 'error');
return false;
}
}
示例9: wc_template_redirect
/**
* Handle redirects before content is output - hooked into template_redirect so is_page works.
*/
function wc_template_redirect()
{
global $wp_query, $wp;
// When default permalinks are enabled, redirect shop page to post type archive url
if (!empty($_GET['page_id']) && '' === get_option('permalink_structure') && $_GET['page_id'] == wc_get_page_id('shop')) {
wp_safe_redirect(get_post_type_archive_link('product'));
exit;
} elseif (is_page(wc_get_page_id('checkout')) && WC()->cart->is_empty() && empty($wp->query_vars['order-pay']) && !isset($wp->query_vars['order-received'])) {
wc_add_notice(__('Checkout is not available whilst your cart is empty.', 'woocommerce'), 'notice');
wp_redirect(wc_get_page_permalink('cart'));
exit;
} elseif (isset($wp->query_vars['customer-logout'])) {
wp_redirect(str_replace('&', '&', wp_logout_url(wc_get_page_permalink('myaccount'))));
exit;
} elseif (is_search() && is_post_type_archive('product') && apply_filters('woocommerce_redirect_single_search_result', true) && 1 === absint($wp_query->found_posts)) {
$product = wc_get_product($wp_query->post);
if ($product && $product->is_visible()) {
wp_safe_redirect(get_permalink($product->id), 302);
exit;
}
} elseif (is_add_payment_method_page()) {
WC()->payment_gateways();
} elseif (is_checkout()) {
// Buffer the checkout page
ob_start();
// Ensure gateways and shipping methods are loaded early
WC()->payment_gateways();
WC()->shipping();
}
}
示例10: validate_custom_checkout_field_process
function validate_custom_checkout_field_process()
{
// Check if set, if its not set add an error.
if (isset($_POST['latitude']) && !$_POST['latitude'] || isset($_POST['longitude']) && !$_POST['longitude']) {
wc_add_notice(__('Please define your location on the map.'), 'error');
}
}
示例11: plp_cartcontent
function plp_cartcontent()
{
global $woocommerce;
$poj = new WC_Product_Factory();
$count = 0;
if (isset($_POST['productadd'])) {
$woocommerce->cart = new WC_Cart();
$woocommerce->cart->get_cart_from_session();
foreach ($_POST['productadd'] as $productId => $quantity) {
$quantity = (int) $quantity;
$productId = (int) $productId;
$product = $poj->get_product($productId);
if ($quantity > 0) {
if (isset($product->variation_id) && isset($product->parent)) {
$woocommerce->cart->add_to_cart($product->parent->id, $quantity, $product->variation_id, $product->get_variation_attributes());
} else {
$woocommerce->cart->add_to_cart($productId, $quantity);
}
$count++;
}
}
if ($count >= 1) {
$success_msg = get_option('plp_custom_success_msg');
wc_add_notice($success_msg, "success");
} else {
$error_msg = get_option('plp_custom_err_msg');
wc_add_notice($error_msg, "error");
}
}
}
示例12: maybe_setup_cart
/**
* Setup the cart for paying for a delayed initial payment for a subscription.
*
* @since 2.0
*/
public function maybe_setup_cart()
{
global $wp;
if (isset($_GET['pay_for_order']) && isset($_GET['key']) && isset($wp->query_vars['order-pay'])) {
// Pay for existing order
$order_key = $_GET['key'];
$order_id = isset($wp->query_vars['order-pay']) ? $wp->query_vars['order-pay'] : absint($_GET['order_id']);
$order = wc_get_order($wp->query_vars['order-pay']);
if ($order->order_key == $order_key && $order->has_status(array('pending', 'failed')) && !wcs_order_contains_subscription($order, array('renewal', 'resubscribe'))) {
$subscriptions = wcs_get_subscriptions_for_order($order, array('order_type' => 'parent'));
if (get_current_user_id() !== $order->get_user_id()) {
wc_add_notice(__('That doesn\'t appear to be your order.', 'woocommerce-subscriptions'), 'error');
wp_safe_redirect(get_permalink(wc_get_page_id('myaccount')));
exit;
} elseif (!empty($subscriptions)) {
// Setup cart with all the original order's line items
$this->setup_cart($order, array('order_id' => $order_id));
WC()->session->set('order_awaiting_payment', $order_id);
// Set cart hash for orders paid in WC >= 2.6
$this->set_cart_hash($order_id);
wp_safe_redirect(WC()->cart->get_checkout_url());
exit;
}
}
}
}
示例13: active_free_order
/**
* @return void
*/
public function active_free_order()
{
try {
$response = array();
$fb_id = isset($_POST['post_id']) ? $_POST['post_id'] : 0;
$redirect_url = isset($_POST['redirect_url']) ? $_POST['redirect_url'] : '';
if (!$fb_id || !$redirect_url || !is_user_logged_in()) {
throw new Exception(__('Không thể kích hoạt', NDV_WOO));
return false;
}
$user = wp_get_current_user();
update_user_meta($user->ID, 'ndv_share', $fb_id);
$response['status'] = 'success';
$response['redirect'] = $redirect_url;
if (is_ajax()) {
echo '<!--WC_START-->' . json_encode($response) . '<!--WC_END-->';
exit;
} else {
wp_redirect($response['redirect']);
exit;
}
} catch (Exception $e) {
if (!empty($e)) {
wc_add_notice($e->getMessage(), 'error');
}
}
if (is_ajax()) {
ob_start();
wc_print_notices();
$messages = ob_get_clean();
echo '<!--WC_START-->' . json_encode(array('result' => 'failure', 'messages' => isset($messages) ? $messages : '')) . '<!--WC_END-->';
exit;
}
}
示例14: wc_gateway_ppec_format_paypal_api_exception
function wc_gateway_ppec_format_paypal_api_exception($errors)
{
$error_strings = array();
foreach ($errors as $error) {
$error_strings[] = $error->maptoBuyerFriendlyError();
}
wc_add_notice(__('Payment error:', 'woocommerce-gateway-paypal-express-checkout') . '<ul><li>' . implode('</li><li>', $error_strings) . '</li></ul>', 'error');
}
示例15: checkoutProcess
/**
* @author Panagiotis Vagenas <pan.vagenas@gmail.com>
* @since 151229
*/
public function checkoutProcess()
{
if ($this->isTimologioRequest()) {
$valid = $this->validateInvoicePostFields();
if (count($valid) < count($this->fields)) {
wc_add_notice(__('Please fill all invoice fields', 'wc-timologio'), 'error');
}
}
}