/**
  * Store any messages or errors added by other plugins, particularly important for those occasions when the new payment
  * method caused and error or failure.
  *
  * @since 1.4
  */
 public static function store_pay_shortcode_mesages()
 {
     if (wc_notice_count('notice') > 0) {
         self::$woocommerce_messages = wc_get_notices('success');
         self::$woocommerce_messages += wc_get_notices('notice');
     }
     if (wc_notice_count('error') > 0) {
         self::$woocommerce_errors = wc_get_notices('error');
     }
 }
 /**
  * Output the shortcode.
  *
  * @param array $atts
  */
 public static function output($atts)
 {
     global $wp;
     // Check cart class is loaded or abort
     if (is_null(WC()->cart)) {
         return;
     }
     if (!is_user_logged_in()) {
         $message = apply_filters('woocommerce_my_account_message', '');
         if (!empty($message)) {
             wc_add_notice($message);
         }
         // After password reset, add confirmation message.
         if (!empty($_GET['password-reset'])) {
             wc_add_notice(__('Your password has been reset successfully.', 'woocommerce'));
         }
         if (isset($wp->query_vars['lost-password'])) {
             self::lost_password();
         } else {
             wc_get_template('myaccount/form-login.php');
         }
     } else {
         // Start output buffer since the html may need discarding for BW compatibility
         ob_start();
         // Collect notices before output
         $notices = wc_get_notices();
         // Output the new account page
         self::my_account($atts);
         /**
          * Deprecated my-account.php template handling. This code should be
          * removed in a future release.
          *
          * If woocommerce_account_content did not run, this is an old template
          * so we need to render the endpoint content again.
          */
         if (!did_action('woocommerce_account_content')) {
             foreach ($wp->query_vars as $key => $value) {
                 if ('pagename' === $key) {
                     continue;
                 }
                 if (has_action('woocommerce_account_' . $key . '_endpoint')) {
                     ob_clean();
                     // Clear previous buffer
                     wc_set_notices($notices);
                     wc_print_notices();
                     do_action('woocommerce_account_' . $key . '_endpoint', $value);
                     break;
                 }
             }
             wc_deprecated_function('Your theme version of my-account.php template', '2.6', 'the latest version, which supports multiple account pages and navigation, from WC 2.6.0');
         }
         // Send output buffer
         ob_end_flush();
     }
 }
 /**
  * Store any messages or errors added by other plugins, particularly important for those occasions when the new payment
  * method caused and error or failure.
  *
  * @since 1.4
  */
 public static function store_pay_shortcode_mesages()
 {
     global $woocommerce;
     if (function_exists('wc_notice_count')) {
         // WC 2.1+
         if (wc_notice_count('notice') > 0) {
             self::$woocommerce_messages = wc_get_notices('success');
             self::$woocommerce_messages += wc_get_notices('notice');
         }
         if (wc_notice_count('error') > 0) {
             self::$woocommerce_errors = wc_get_notices('error');
         }
     } else {
         if ($woocommerce->message_count() > 0) {
             self::$woocommerce_messages = $woocommerce->get_messages();
         }
         if ($woocommerce->error_count() > 0) {
             self::$woocommerce_errors = $woocommerce->get_errors();
         }
     }
 }
 function woocommerce_add_to_cart_variable_rc_callback()
 {
     ob_start();
     $product_id = apply_filters('woocommerce_add_to_cart_product_id', absint($_POST['product_id']));
     $quantity = empty($_POST['quantity']) ? 1 : apply_filters('woocommerce_stock_amount', $_POST['quantity']);
     $variation_id = $_POST['variation_id'];
     $variation = $_POST['variation'];
     $passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity);
     if ($passed_validation && WC()->cart->add_to_cart($product_id, $quantity, $variation_id, $variation)) {
         do_action('woocommerce_ajax_added_to_cart', $product_id);
         if (get_option('woocommerce_cart_redirect_after_add') == 'yes') {
             wc_add_to_cart_message($product_id);
         }
         // Return fragments
         WC_AJAX::get_refreshed_fragments();
     } else {
         // If there was an error adding to the cart, redirect to the product page to show any errors
         $notice = end(wc_get_notices('error'));
         $data = array('error' => true, 'product_url' => apply_filters('woocommerce_cart_redirect_after_error', get_permalink($product_id), $product_id), 'notice' => $notice);
         wp_send_json($data);
     }
     die;
 }
Exemplo n.º 5
0
 /**
  * Test wc_get_notices().
  *
  * @since 2.2
  */
 public function test_wc_get_notices()
 {
     // no notices
     $notices = wc_get_notices();
     $this->assertInternalType('array', $notices);
     $this->assertEmpty($notices);
     // default type
     wc_add_notice('Another Notice');
     $this->assertEquals(array('success' => array('Another Notice')), wc_get_notices());
     // specific type
     wc_add_notice('Error Notice', 'error');
     $this->assertEquals(array('Error Notice'), wc_get_notices('error'));
     // invalid type
     $notices = wc_get_notices('bogus_type');
     $this->assertInternalType('array', $notices);
     $this->assertEmpty($notices);
 }
Exemplo n.º 6
0
        $redirect_url = get_permalink(icl_object_id(function_exists('wc_get_page_id') ? wc_get_page_id('cart') : woocommerce_get_page_id('cart')), 'page', true);
    } else {
        $redirect_url = get_permalink(function_exists('wc_get_page_id') ? wc_get_page_id('cart') : woocommerce_get_page_id('cart'));
    }
} else {
    $redirect_url = $yith_wcwl->get_wishlist_url();
}
//get the details of the product
$details = $yith_wcwl->get_product_details($_GET['wishlist_item_id']);
//add to the cart
if ($woocommerce->cart->add_to_cart($details[0]['prod_id'], 1)) {
    //$_SESSION['messages'] 	= sprintf( '<a href="%s" class="button">%s</a> %s', get_permalink( woocommerce_get_page_id( 'cart' ) ), __( 'View Cart &rarr;', 'yit' ), __( 'Product successfully added to the cart.', 'yit' ) );
    if (function_exists('wc_add_to_cart_message')) {
        wc_add_to_cart_message($details[0]['prod_id']);
    } else {
        woocommerce_add_to_cart_message($details[0]['prod_id']);
    }
    //$woocommerce->set_messages();
    if (get_option('yith_wcwl_remove_after_add_to_cart') == 'yes') {
        $yith_wcwl->remove($details[0]['ID']);
    }
    header("Location: {$redirect_url}");
} else {
    //if failed, redirect to wishlist page with errors
    if (function_exists('wc_get_notices')) {
        $_SESSION['errors'] = wc_get_notices("error");
    } else {
        $_SESSION['errors'] = $woocommerce->get_errors();
    }
    header("Location: {$error_link_url}");
}
 /**
  * @param $gateway_id
  * @param $order_id
  * @param $response
  */
 private function payment_failure($gateway_id, $order_id, $response)
 {
     $message = isset($response['messages']) ? $response['messages'] : wc_get_notices('error');
     // if messages empty give generic response
     if (empty($message)) {
         $message = __('There was an error processing the payment', 'woocommerce-pos');
     }
     update_post_meta($order_id, '_pos_payment_result', 'failure');
     update_post_meta($order_id, '_pos_payment_message', $message);
 }
Exemplo n.º 8
0
 /**
  * @deprecated 2.1.0
  * @return mixed
  */
 public function get_messages()
 {
     _deprecated_function('Woocommerce->get_messages', '2.1', 'wc_get_notices( "success" )');
     return wc_get_notices('success');
 }
function avia_woocommerce_cart_dropdown()
{
    global $woocommerce, $avia_config;
    $cart_subtotal = $woocommerce->cart->get_cart_subtotal();
    $link = $woocommerce->cart->get_cart_url();
    $id = "";
    $added = wc_get_notices('success');
    $trigger = !empty($added) ? "av-display-cart-on-load" : "";
    if (avia_get_option('cart_icon') == "always_display_menu") {
        $id = 'id="menu-item-shop"';
    }
    $output = "";
    $output .= "<ul {$id} class = 'cart_dropdown {$trigger}' data-success='" . __('was added to the cart', 'avia_framework') . "'><li class='cart_dropdown_first'>";
    $output .= "<a class='cart_dropdown_link' href='" . $link . "'><span " . av_icon_string('cart') . "></span><span class='av-cart-counter'>0</span><span class='avia_hidden_link_text'>" . __('Shopping Cart', 'avia_framework') . "</span></a><!--<span class='cart_subtotal'>" . $cart_subtotal . "</span>-->";
    $output .= "<div class='dropdown_widget dropdown_widget_cart'><div class='avia-arrow'></div>";
    $output .= '<div class="widget_shopping_cart_content"></div>';
    $output .= "</div>";
    $output .= "</li></ul>";
    echo $output;
}
Exemplo n.º 10
0
$error_link_url = $yith_wcwl->get_wishlist_url();
//determine to success link redirect url
//handle redirect option chosen by admin
if (isset($_GET['redirect_to_cart']) && $_GET['redirect_to_cart'] == 'true') {
    $redirect_url = $woocommerce->cart->get_cart_url();
} else {
    $redirect_url = $yith_wcwl->get_wishlist_url();
}
//get the details of the product
$details = $yith_wcwl->get_product_details($_GET['wishlist_item_id']);
//add to the cart
if ($woocommerce->cart->add_to_cart($details[0]['prod_id'], 1)) {
    if (function_exists('wc_add_to_cart_message')) {
        wc_add_to_cart_message($details[0]['prod_id']);
    } else {
        woocommerce_add_to_cart_message($details[0]['prod_id']);
    }
    $woocommerce->set_messages();
    if (get_option('yith_wcwl_remove_after_add_to_cart') == 'yes') {
        $yith_wcwl->remove($details[0]['ID']);
    }
    header("Location: {$redirect_url}");
} else {
    //if failed, redirect to wishlist page with errors
    if (function_exists('wc_get_notices')) {
        $_SESSION['errors'] = wc_get_notices('error');
    } else {
        $_SESSION['errors'] = $woocommerce->get_errors();
    }
    header("Location: {$error_link_url}");
}
 function ajax_product_add_to_cart()
 {
     global $post, $woocommerce, $product;
     /* Set arrays and variables */
     $prod_id = $_POST['id'];
     $var_id = '';
     $quantity = $_POST['quantity'];
     $attributes = $_POST['atts'];
     /* Get Product by id*/
     $product = wc_get_product($prod_id);
     /* Set attribute array for this cart item and modify it to fit  */
     $att_query = array();
     foreach ($attributes as $name => $value) {
         $new_att_name = 'attribute_' . $name;
         $value = str_replace(" ", "-", $value);
         $att_query[$new_att_name] = strtolower($value);
     }
     /* If has children get variations and check the array against the data passed before */
     if ($product->has_child()) {
         $available_variations = $product->get_available_variations();
         $count = count($available_variations);
         /* if only one variation, use only one id */
         if ($count == '1') {
             foreach ($available_variations as $avar) {
                 $var_id = $avar['variation_id'];
                 $attributes = $att_query;
                 $result = $woocommerce->cart->add_to_cart($prod_id, $quantity, $var_id, $attributes, null);
             }
             /* if more than one variation, do this fancy pants logic */
         } elseif ($count > '1') {
             $var_id = '';
             $count_difference = '999';
             foreach ($available_variations as $avar) {
                 $attributes = $avar['attributes'];
                 $att_count = count($attributes);
                 /* check for exact match. If exact, add to cart and exit */
                 if ($att_query == $attributes) {
                     $var_id = $avar['variation_id'];
                     break;
                 } else {
                     $difference = array_diff($att_query, $attributes);
                     $cdif = count($difference);
                     if ($cdif < $count_difference) {
                         $count_difference = $cdif;
                         $var_id = $avar['variation_id'];
                         $check_dif = $difference;
                     }
                 }
             }
             $attributes = $att_query;
             $result = $woocommerce->cart->add_to_cart($prod_id, $quantity, $var_id, $attributes, null);
         }
         /* If no children, just add to cart */
     } else {
         $result = $woocommerce->cart->add_to_cart($prod_id, $quantity);
     }
     /* Call WC ajax after add to cart. Not yet found a way to make this work. */
     //add_filter('add_to_cart_fragments', WC_AJAX::get_refreshed_fragments());
     //add_action('woocommerce_add_to_cart','');
     /* cart notices */
     $notices = wc_get_notices();
     if (!empty($notices)) {
         wc_print_notices();
         exit;
     }
     if (!empty($result) && empty($notices)) {
         echo '<ul class="woocommerce-success"><li>Product successfully added to your cart.</li></ul>';
         exit;
     }
     if (empty($result) && empty($notices)) {
         echo '<ul class="woocommerce-error"><li>Product could not be added to your cart.</li></ul>';
         exit;
     } else {
         exit;
     }
 }
 public function expire_notice_added()
 {
     foreach (wc_get_notices() as $type => $notices) {
         foreach ($notices as $notice) {
             if (false !== strpos($notice, 'wc-csr-countdown')) {
                 return true;
             }
         }
     }
     return false;
 }
 /**
  * Overwrite the default "Coupon added" notice with a more descriptive message.
  * @param  WC_Coupon $coupon The coupon data
  * @param  bool      $remove_message_only If true the notice will be removed, and no notice will be shown.
  * @return void
  */
 private function overwrite_success_message($coupon, $remove_message_only = false)
 {
     $succss_msg = $coupon->get_coupon_message(WC_Coupon::WC_COUPON_SUCCESS);
     //If ajax, remove only
     $remove_message_only |= defined('DOING_AJAX') && DOING_AJAX;
     $new_succss_msg = sprintf(__("Discount applied: %s", 'woocommerce-jos-autocoupon'), __($this->coupon_excerpt($coupon), 'woocommerce-jos-autocoupon'));
     //Compatibility woocommerce-2-1-notice-api
     if (function_exists('wc_get_notices')) {
         $all_notices = wc_get_notices();
         if (!isset($all_notices['success'])) {
             $all_notices['success'] = array();
         }
         $messages = $all_notices['success'];
     } else {
         $messages = $woocommerce->messages;
     }
     $sizeof_messages = sizeof($messages);
     for ($y = 0; $y < $sizeof_messages; $y++) {
         if ($messages[$y] == $succss_msg) {
             if (isset($all_notices)) {
                 if ($remove_message_only) {
                     unset($all_notices['success'][$y]);
                 } else {
                     $all_notices['success'][$y] = $new_succss_msg;
                 }
                 WC()->session->set('wc_notices', $all_notices);
             } else {
                 if ($remove_message_only) {
                     unset($messages[$y]);
                 } else {
                     $messages[$y] = $new_succss_msg;
                 }
             }
             break;
         }
     }
 }