本文整理汇总了PHP中wc_print_notices函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_print_notices函数的具体用法?PHP wc_print_notices怎么用?PHP wc_print_notices使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wc_print_notices函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: woocommerce_apply_giftcard
function woocommerce_apply_giftcard($giftcard_code)
{
global $wpdb;
if (!empty($_POST['giftcard_code'])) {
$giftcard_number = sanitize_text_field($_POST['giftcard_code']);
if (!isset(WC()->session->giftcard_post)) {
$giftcard_id = wpr_get_giftcard_by_code($giftcard_number);
if ($giftcard_id) {
$current_date = date("Y-m-d");
$cardExperation = wpr_get_giftcard_expiration($giftcard_id);
if (strtotime($current_date) <= strtotime($cardExperation) || strtotime($cardExperation) == '') {
if (wpr_get_giftcard_balance($giftcard_id) > 0) {
WC()->session->giftcard_post = $giftcard_id;
wc_add_notice(__('Gift card applied successfully.', 'rpgiftcards'), 'success');
} else {
wc_add_notice(__('Gift Card does not have a balance!', 'rpgiftcards'), 'error');
}
} else {
wc_add_notice(__('Gift Card has expired!', 'rpgiftcards'), 'error');
// Giftcard Entered has expired
}
} else {
wc_add_notice(__('Gift Card does not exist!', 'rpgiftcards'), 'error');
// Giftcard Entered does not exist
}
} else {
wc_add_notice(__('Gift Card already in the cart!', 'rpgiftcards'), 'error');
// You already have a gift card in the cart
}
wc_print_notices();
}
}
示例2: 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;
}
示例3: easy_booking_before_add_to_cart_button
/**
*
* Adds a custom form to the product page.
*
**/
public function easy_booking_before_add_to_cart_button()
{
global $post, $product;
$product = wc_get_product($product->id);
// Is product bookable ?
$is_bookable = get_post_meta($product->id, '_booking_option', true);
$info_text = $this->options['easy_booking_info_text'];
$start_date_text = $this->options['easy_booking_start_date_text'];
$end_date_text = $this->options['easy_booking_end_date_text'];
$product_price = $product->get_price();
$args = apply_filters('easy_booking_new_price_args', array());
// Product is bookable
if (isset($is_bookable) && $is_bookable === 'yes') {
// Display info text
if (isset($info_text) && !empty($info_text)) {
echo apply_filters('easy_booking_before_picker_form', '<div class="woocommerce-info">' . wpautop(esc_textarea($info_text)) . '</div>', $info_text);
}
echo '<div class="wc_ebs_errors">' . wc_print_notices() . '</div>';
// Please do not remove inputs' attributes (classes, ids, etc.)
echo '<div class="wceb_picker_wrap">';
echo apply_filters('easy_booking_picker_form', '<p class="form-row form-row-wide">
<label for="start_date">' . esc_html($start_date_text) . '</label>
<input type="hidden" id="variation_id" name="variation_id" data-product_id="' . absint($product->id) . '" value="">
<input type="text" id="start_date" class="datepicker datepicker_start" data-value="" placeholder="' . esc_html($start_date_text) . '">
</p>
<p class="form-row form-row-wide">
<label for="end_date">' . esc_html($end_date_text) . '</label>
<input type="text" id="end_date" class="datepicker datepicker_end" data-value="" placeholder="' . esc_html($end_date_text) . '">
</p>', $start_date_text, $end_date_text, $product);
echo '</div>';
// If product is not variable, add a new price field before add to cart button
if (!$product->is_type('variable')) {
echo '<p class="booking_price"><span class="price">' . wc_price($product_price, $args) . '</span></p>';
}
}
}
示例4: 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;
}
}
示例5: 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;
}
示例6: WooComposer_Product
function WooComposer_Product($atts)
{
$product_style = '';
extract(shortcode_atts(array("product_style" => ""), $atts));
$output = '';
ob_start();
$output .= '<div class="woocommerce woo-msg">';
wc_print_notices();
$output .= ob_get_clean();
$output .= '</div>';
$template = 'design-single-' . $product_style . '.php';
require_once $template;
$function = 'WooComposer_Single_' . $product_style;
$output .= $function($atts);
return $output;
}
示例7: output
/**
* Outputs the thankyou page
*
* @access public
* @param mixed $atts
* @return void
*/
public static function output($atts)
{
wc_print_notices();
// Pay for order after checkout step
if (isset($_GET['order'])) {
$order_id = (int) $_GET['order'];
} else {
$order_id = 0;
}
WC()->cart->empty_cart();
if ($order_id > 0) {
$order = new WC_Order($order_id);
} else {
$order = false;
}
wc_get_template('checkout/thankyou.php', array('order' => $order));
}
开发者ID:Benjamin002,项目名称:woocommerce-paybox-gateway,代码行数:24,代码来源:shortcode_woocommerce_paybox_gateway.php
示例8: woocomposer_grid_shortcode
function woocomposer_grid_shortcode($atts)
{
$product_style = '';
extract(shortcode_atts(array("product_style" => ""), $atts));
$output = '';
ob_start();
$output .= '<div class="woocommerce">';
wc_print_notices();
$output .= ob_get_clean();
$output .= '</div>';
$uid = uniqid();
$output = '<div id="woo-grid-' . $uid . '" class="woocomposer_grid">';
$template = 'design-loop-' . $product_style . '.php';
require_once $template;
$function = 'WooComposer_Loop_' . $product_style;
$output .= $function($atts, 'grid');
$output .= "\n" . '</div>';
return $output;
}
示例9: wc_quick_donation_handler
public function wc_quick_donation_handler($settings)
{
global $donation_box, $donation_price, $currency;
$settings = shortcode_atts(array('type' => wcqd_get_option(WC_QD_DB . 'default_render_type'), 'grouped' => false, 'show_errors' => wcqd_get_option(WC_QD_DB . 'shortcode_show_errors'), 'selected_value' => wcqd_get_option(WC_QD_DB . 'pre_selected_project'), 'defined_amount' => false), $settings);
$donation_box = WC_QD()->f()->generate_donation_selbox($settings['grouped'], $settings['type'], $settings['selected_value']);
$donation_price = WC_QD()->f()->generate_price_box($settings['defined_amount']);
$currency = get_woocommerce_currency_symbol();
$return_value = '';
$messages = '';
if ($settings['show_errors']) {
ob_start();
wc_print_notices();
$return_value .= ob_get_clean();
ob_flush();
}
do_action('wc_quick_donation_before_doantion_form', $return_value, $settings['type'], $settings['grouped']);
$return_value .= WC_QD()->f()->load_template('donation-form.php', WC_QD_TEMPLATE, array('donation_box' => $donation_box, 'donation_price' => $donation_price, 'currency' => $currency));
do_action('wc_quick_donation_after_doantion_form', $return_value, $settings['type'], $settings['grouped']);
return $return_value;
}
示例10: update_order_review
/**
* AJAX update order review on checkout
*/
public static function update_order_review()
{
ob_start();
check_ajax_referer('update-order-review', 'security');
if (!defined('WOOCOMMERCE_CHECKOUT')) {
define('WOOCOMMERCE_CHECKOUT', true);
}
if (WC()->cart->is_empty()) {
$data = array('fragments' => apply_filters('woocommerce_update_order_review_fragments', array('form.woocommerce-checkout' => '<div class="woocommerce-error">' . __('Sorry, your session has expired.', 'woocommerce') . ' <a href="' . home_url() . '" class="wc-backward">' . __('Return to homepage', 'woocommerce') . '</a></div>')));
wp_send_json($data);
die;
}
do_action('woocommerce_checkout_update_order_review', $_POST['post_data']);
$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
if (isset($_POST['shipping_method']) && is_array($_POST['shipping_method'])) {
foreach ($_POST['shipping_method'] as $i => $value) {
$chosen_shipping_methods[$i] = wc_clean($value);
}
}
WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods);
WC()->session->set('chosen_payment_method', empty($_POST['payment_method']) ? '' : $_POST['payment_method']);
if (isset($_POST['country'])) {
WC()->customer->set_country($_POST['country']);
}
if (isset($_POST['state'])) {
WC()->customer->set_state($_POST['state']);
}
if (isset($_POST['postcode'])) {
WC()->customer->set_postcode($_POST['postcode']);
}
if (isset($_POST['city'])) {
WC()->customer->set_city($_POST['city']);
}
if (isset($_POST['address'])) {
WC()->customer->set_address($_POST['address']);
}
if (isset($_POST['address_2'])) {
WC()->customer->set_address_2($_POST['address_2']);
}
if (wc_ship_to_billing_address_only()) {
if (isset($_POST['country'])) {
WC()->customer->set_shipping_country($_POST['country']);
}
if (isset($_POST['state'])) {
WC()->customer->set_shipping_state($_POST['state']);
}
if (isset($_POST['postcode'])) {
WC()->customer->set_shipping_postcode($_POST['postcode']);
}
if (isset($_POST['city'])) {
WC()->customer->set_shipping_city($_POST['city']);
}
if (isset($_POST['address'])) {
WC()->customer->set_shipping_address($_POST['address']);
}
if (isset($_POST['address_2'])) {
WC()->customer->set_shipping_address_2($_POST['address_2']);
}
} else {
if (isset($_POST['s_country'])) {
WC()->customer->set_shipping_country($_POST['s_country']);
}
if (isset($_POST['s_state'])) {
WC()->customer->set_shipping_state($_POST['s_state']);
}
if (isset($_POST['s_postcode'])) {
WC()->customer->set_shipping_postcode($_POST['s_postcode']);
}
if (isset($_POST['s_city'])) {
WC()->customer->set_shipping_city($_POST['s_city']);
}
if (isset($_POST['s_address'])) {
WC()->customer->set_shipping_address($_POST['s_address']);
}
if (isset($_POST['s_address_2'])) {
WC()->customer->set_shipping_address_2($_POST['s_address_2']);
}
}
WC()->cart->calculate_totals();
// Get order review fragment
ob_start();
woocommerce_order_review();
$woocommerce_order_review = ob_get_clean();
// Get checkout payment fragment
ob_start();
woocommerce_checkout_payment();
$woocommerce_checkout_payment = ob_get_clean();
// Get messages if reload checkout is not true
$messages = '';
if (!isset(WC()->session->reload_checkout)) {
ob_start();
wc_print_notices();
$messages = ob_get_clean();
}
$data = array('result' => empty($messages) ? 'success' : 'failure', 'messages' => $messages, 'reload' => isset(WC()->session->reload_checkout) ? 'true' : 'false', 'fragments' => apply_filters('woocommerce_update_order_review_fragments', array('.woocommerce-checkout-review-order-table' => $woocommerce_order_review, '.woocommerce-checkout-payment' => $woocommerce_checkout_payment)));
wp_send_json($data);
die;
//.........这里部分代码省略.........
示例11: print_notices
/**
* Print WooCommerce messages regardless of the version of WooCommerce running.
*
* @since version 1.4.5
*/
public static function print_notices()
{
global $woocommerce;
if (function_exists('wc_print_notices')) {
wc_print_notices();
} else {
// WC < 2.1
$woocommerce->show_messages();
}
}
示例12: shop_messages
/**
* Show messages
*
* @return string
*/
public static function shop_messages()
{
ob_start();
wc_print_notices();
return '<div class="woocommerce">' . ob_get_clean() . '</div>';
}
示例13: yit_my_account_template
/**
* Add custom template form my-account page
*
* @return void
* @since 2.0.0
* @author Francesco Licandro <francesco.licandro@yithemes.com>
*/
function yit_my_account_template()
{
if (function_exists('WC') && is_page(get_option('woocommerce_myaccount_page_id'))) {
global $wp;
if (is_user_logged_in()) {
if (!is_rtl()) {
echo '<div class="col-sm-3" id="my-account-sidebar">';
wc_get_template('/myaccount/my-account-menu.php');
echo '</div>';
}
echo '<div class="col-sm-9" id="my-account-content">';
wc_print_notices();
if (!isset($wp->query_vars['recent-downloads']) && !isset($wp->query_vars['wishlist']) && !isset($wp->query_vars['edit-address']) && !isset($wp->query_vars['edit-account']) && !isset($wp->query_vars['view-order']) && !isset($wp->query_vars['lost-password'])) {
wc_get_template('myaccount/my-orders.php', array('order_count' => 15));
} elseif (isset($wp->query_vars['recent-downloads'])) {
wc_get_template('myaccount/my-downloads.php');
} elseif (isset($wp->query_vars['wishlist'])) {
echo do_shortcode('[yith_wcwl_wishlist]');
} else {
yit_content_loop();
}
echo '</div>';
if (is_rtl()) {
echo '<div class="col-sm-3" id="my-account-sidebar">';
wc_get_template('/myaccount/my-account-menu.php');
echo '</div>';
}
} else {
echo '<div class="row" id="my-account-content">';
if (isset($wp->query_vars['lost-password'])) {
WC_Shortcode_My_Account::lost_password();
} else {
wc_get_template('myaccount/form-login.php');
}
echo '</div>';
}
}
}
示例14: woocommerce_show_messages
/**
* @deprecated
*/
function woocommerce_show_messages()
{
_deprecated_function('woocommerce_show_messages', '2.1', 'wc_print_notices');
wc_print_notices();
}
示例15: process_checkout
//.........这里部分代码省略.........
wc_add_notice(__('Invalid shipping method.', 'woocommerce'), 'error');
$this->shipping_methods[$i] = '';
}
}
}
if (WC()->cart->needs_payment()) {
// Payment Method
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
if (!isset($available_gateways[$this->posted['payment_method']])) {
$this->payment_method = '';
wc_add_notice(__('Invalid payment method.', 'woocommerce'), 'error');
} else {
$this->payment_method = $available_gateways[$this->posted['payment_method']];
$this->payment_method->validate_fields();
}
}
// Action after validation
do_action('woocommerce_after_checkout_validation', $this->posted);
if (!isset($_POST['woocommerce_checkout_update_totals']) && wc_notice_count('error') == 0) {
try {
// Customer accounts
$this->customer_id = apply_filters('woocommerce_checkout_customer_id', get_current_user_id());
if (!is_user_logged_in() && ($this->must_create_account || !empty($this->posted['createaccount']))) {
$username = !empty($this->posted['account_username']) ? $this->posted['account_username'] : '';
$password = !empty($this->posted['account_password']) ? $this->posted['account_password'] : '';
$new_customer = wc_create_new_customer($this->posted['billing_email'], $username, $password);
if (is_wp_error($new_customer)) {
throw new Exception($new_customer->get_error_message());
}
$this->customer_id = $new_customer;
wc_set_customer_auth_cookie($this->customer_id);
// As we are now logged in, checkout will need to refresh to show logged in data
WC()->session->set('reload_checkout', true);
// Add customer info from other billing fields
if ($this->posted['billing_first_name'] && apply_filters('woocommerce_checkout_update_customer_data', true, $this)) {
$userdata = array('ID' => $this->customer_id, 'first_name' => $this->posted['billing_first_name'] ? $this->posted['billing_first_name'] : '', 'last_name' => $this->posted['billing_last_name'] ? $this->posted['billing_last_name'] : '', 'display_name' => $this->posted['billing_first_name'] ? $this->posted['billing_first_name'] : '');
wp_update_user(apply_filters('woocommerce_checkout_customer_userdata', $userdata, $this));
}
}
// Do a final stock check at this point
$this->check_cart_items();
// Abort if errors are present
if (wc_notice_count('error') > 0) {
throw new Exception();
}
$order_id = $this->create_order();
do_action('woocommerce_checkout_order_processed', $order_id, $this->posted);
// Process payment
if (WC()->cart->needs_payment()) {
// Store Order ID in session so it can be re-used after payment failure
WC()->session->order_awaiting_payment = $order_id;
// Process Payment
$result = $available_gateways[$this->posted['payment_method']]->process_payment($order_id);
// Redirect to success/confirmation/payment page
if ($result['result'] == 'success') {
$result = apply_filters('woocommerce_payment_successful_result', $result, $order_id);
if (is_ajax()) {
echo '<!--WC_START-->' . json_encode($result) . '<!--WC_END-->';
exit;
} else {
wp_redirect($result['redirect']);
exit;
}
}
} else {
if (empty($order)) {
$order = new WC_Order($order_id);
}
// No payment was required for order
$order->payment_complete();
// Empty the Cart
WC()->cart->empty_cart();
// Get redirect
$return_url = $order->get_checkout_order_received_url();
// Redirect to success/confirmation/payment page
if (is_ajax()) {
echo '<!--WC_START-->' . json_encode(array('result' => 'success', 'redirect' => apply_filters('woocommerce_checkout_no_payment_needed_redirect', $return_url, $order))) . '<!--WC_END-->';
exit;
} else {
wp_safe_redirect(apply_filters('woocommerce_checkout_no_payment_needed_redirect', $return_url, $order));
exit;
}
}
} catch (Exception $e) {
if (!empty($e)) {
wc_add_notice($e->getMessage(), 'error');
}
}
}
// endif
// If we reached this point then there were errors
if (is_ajax()) {
ob_start();
wc_print_notices();
$messages = ob_get_clean();
echo '<!--WC_START-->' . json_encode(array('result' => 'failure', 'messages' => $messages, 'refresh' => isset(WC()->session->refresh_totals) ? 'true' : 'false', 'reload' => isset(WC()->session->reload_checkout) ? 'true' : 'false')) . '<!--WC_END-->';
unset(WC()->session->refresh_totals, WC()->session->reload_checkout);
exit;
}
}