本文整理汇总了PHP中WC_AJAX类的典型用法代码示例。如果您正苦于以下问题:PHP WC_AJAX类的具体用法?PHP WC_AJAX怎么用?PHP WC_AJAX使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WC_AJAX类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: ts_remove_cart_item
function ts_remove_cart_item()
{
$cart_item_key = sanitize_text_field($_POST['cart_item_key']);
if ($cart_item = WC()->cart->get_cart_item($cart_item_key)) {
WC()->cart->remove_cart_item($cart_item_key);
}
WC_AJAX::get_refreshed_fragments();
}
开发者ID:ericsoncardosoweb,项目名称:dallia,代码行数:8,代码来源:woo_functions.php
示例2: evotx_woocommerce_ajax_add_to_cart
function evotx_woocommerce_ajax_add_to_cart()
{
global $woocommerce;
// Initial values
$product_id = apply_filters('woocommerce_add_to_cart_product_id', absint($_POST['product_id']));
$variation_id = apply_filters('woocommerce_add_to_cart_variation_id', absint($_POST['variation_id']));
$quantity = empty($_POST['quantity']) ? 1 : apply_filters('woocommerce_stock_amount', $_POST['quantity']);
$passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity);
// if variations are sent
if (isset($_POST['variations'])) {
$att = array();
foreach ($_POST['variations'] as $varF => $varV) {
$att[$varF] = $varV;
}
}
if ($passed_validation && !empty($variation_id)) {
$cart_item_key = WC()->cart->add_to_cart($product_id, $quantity, $variation_id, $att);
do_action('woocommerce_ajax_added_to_cart', $product_id);
$frags = new WC_AJAX();
$frags->get_refreshed_fragments();
}
/*
// if variation ID is given
if(!empty($variation_id) && $variation_id > 0){
$cart_item_key = $woocommerce->cart->add_to_cart( $product_id, $quantity, $variation_id ,$att);
do_action( 'woocommerce_ajax_added_to_cart', $product_id ,$quantity, $variation_id ,$variation);
// Return fragments
//$frags = new WC_AJAX( );
//$frags->get_refreshed_fragments( );
// if WC settings set to redirect after adding to cart
if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) {
// show cart notification
wc_add_to_cart_message( $product_id );
$woocommerce->set_messages();
}
}else{
if ( $passed_validation && $woocommerce->cart->add_to_cart( $product_id, $quantity) ) {
do_action( 'woocommerce_ajax_added_to_cart', $product_id );
if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) {
woocommerce_add_to_cart_message( $product_id );
$woocommerce->set_messages();
}
// Return fragments
// $frags = new WC_AJAX( );
// $frags->get_refreshed_fragments( );
} else {
header( 'Content-Type: application/json; charset=utf-8' );
// If there was an error adding to the cart, redirect to the product page to show any errors
$data = array(
'error' => true,
'product_url' => apply_filters( 'woocommerce_cart_redirect_after_error', get_permalink( $product_id ), $product_id )
);
$woocommerce->set_messages();
echo json_encode( $data );
}
die();
} // endif
*/
$output = array('key' => $cart_item_key, 'variation' => WC()->cart->cart_contents_total);
echo json_encode($output);
}
开发者ID:sabdev1,项目名称:ljcdevsab,代码行数:75,代码来源:class-ajax.php
示例3: install
/**
* Install WC
*/
public static function install()
{
global $wpdb;
if (!defined('WC_INSTALLING')) {
define('WC_INSTALLING', true);
}
// Ensure needed classes are loaded
include_once 'admin/class-wc-admin-notices.php';
self::create_options();
self::create_tables();
self::create_roles();
// Register post types
WC_Post_types::register_post_types();
WC_Post_types::register_taxonomies();
// Also register endpoints - this needs to be done prior to rewrite rule flush
WC()->query->init_query_vars();
WC()->query->add_endpoints();
WC_API::add_endpoint();
WC_Auth::add_endpoint();
WC_AJAX::add_endpoint();
self::create_terms();
self::create_cron_jobs();
self::create_files();
// Queue upgrades/setup wizard
$current_wc_version = get_option('woocommerce_version', null);
$current_db_version = get_option('woocommerce_db_version', null);
$major_wc_version = substr(WC()->version, 0, strrpos(WC()->version, '.'));
WC_Admin_Notices::remove_all_notices();
// No versions? This is a new install :)
if (is_null($current_wc_version) && is_null($current_db_version) && apply_filters('woocommerce_enable_setup_wizard', true)) {
WC_Admin_Notices::add_notice('install');
set_transient('_wc_activation_redirect', 1, 30);
// No page? Let user run wizard again..
} elseif (!get_option('woocommerce_cart_page_id')) {
WC_Admin_Notices::add_notice('install');
// Show welcome screen for major updates only
} elseif (version_compare($current_wc_version, $major_wc_version, '<')) {
set_transient('_wc_activation_redirect', 1, 30);
}
if (!is_null($current_db_version) && version_compare($current_db_version, max(array_keys(self::$db_updates)), '<')) {
WC_Admin_Notices::add_notice('update');
} else {
self::update_db_version();
}
self::update_wc_version();
// Flush rules after install
flush_rewrite_rules();
delete_transient('wc_attribute_taxonomies');
/*
* Deletes all expired transients. The multi-table delete syntax is used
* to delete the transient record from table a, and the corresponding
* transient_timeout record from table b.
*
* Based on code inside core's upgrade_network() function.
*/
$sql = "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b\n\t\t\tWHERE a.option_name LIKE %s\n\t\t\tAND a.option_name NOT LIKE %s\n\t\t\tAND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )\n\t\t\tAND b.option_value < %d";
$wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_transient_') . '%', $wpdb->esc_like('_transient_timeout_') . '%', time()));
// Trigger action
do_action('woocommerce_installed');
}
开发者ID:noahjohn9259,项目名称:woocommerce,代码行数:63,代码来源:class-wc-install.php
示例4: frontend_scripts
/**
* Front end styles and scripts.
*
* @return void
*/
public static function frontend_scripts()
{
wp_register_style('wcsatt-css', WCS_ATT()->plugin_url() . '/assets/css/wcsatt-frontend.css', false, WCS_ATT::VERSION, 'all');
wp_enqueue_style('wcsatt-css');
if (is_cart()) {
wp_register_script('wcsatt-cart', WCS_ATT()->plugin_url() . '/assets/js/wcsatt-cart.js', array('jquery', 'wc-country-select', 'wc-address-i18n'), WCS_ATT::VERSION, true);
}
wp_enqueue_script('wcsatt-cart');
$params = array('update_cart_option_nonce' => wp_create_nonce('wcsatt_update_cart_option'), 'wc_ajax_url' => WCS_ATT_Core_Compatibility::is_wc_version_gte_2_4() ? WC_AJAX::get_endpoint("%%endpoint%%") : WC()->ajax_url());
wp_localize_script('wcsatt-cart', 'wcsatt_cart_params', $params);
}
开发者ID:VictorArgote,项目名称:woocommerce-subscribe-to-all-the-things,代码行数:16,代码来源:class-wcsatt-display.php
示例5: woocommerce_add_to_cart_simple_rc_callback
function woocommerce_add_to_cart_simple_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']);
$passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity);
if ($passed_validation && WC()->cart->add_to_cart($product_id, $quantity)) {
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 {
$this->json_headers();
// If there was an error adding to the cart, redirect to the product page to show any errors
$data = array('error' => true, 'product_url' => apply_filters('woocommerce_cart_redirect_after_error', get_permalink($product_id), $product_id));
echo json_encode($data);
}
die;
}
开发者ID:bhavikchudasama,项目名称:ajax-add-cart,代码行数:21,代码来源:woocommerce-add-to-cart-for-simple-products.php
示例6: woocommerce_add_to_cart_variable_rc_callback
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;
}
开发者ID:vlabunets,项目名称:my-php-functions,代码行数:23,代码来源:woocommerce-ajax-add-to-cart-variable-products.php
示例7: bulk_edit_variations
* Bulk edit variations via AJAX
*/
public static function bulk_edit_variations()
{
ob_start();
check_ajax_referer('bulk-edit-variations', 'security');
// Check permissions again and make sure we have what we need
if (!current_user_can('edit_products') || empty($_POST['product_id']) || empty($_POST['bulk_action'])) {
die(-1);
}
$product_id = absint($_POST['product_id']);
$bulk_action = wc_clean($_POST['bulk_action']);
$data = !empty($_POST['data']) ? array_map('wc_clean', $_POST['data']) : array();
$variations = array();
if (apply_filters('woocommerce_bulk_edit_variations_need_children', true)) {
$variations = get_posts(array('post_parent' => $product_id, 'posts_per_page' => -1, 'post_type' => 'product_variation', 'fields' => 'ids', 'post_status' => array('publish', 'private')));
}
if (method_exists(__CLASS__, "variation_bulk_action_{$bulk_action}")) {
call_user_func(array(__CLASS__, "variation_bulk_action_{$bulk_action}"), $variations, $data);
} else {
do_action('woocommerce_bulk_edit_variations_default', $bulk_action, $data, $product_id, $variations);
}
do_action('woocommerce_bulk_edit_variations', $bulk_action, $data, $product_id, $variations);
// Sync and update transients
WC_Product_Variable::sync($product_id);
wc_delete_product_transients($product_id);
die;
}
}
WC_AJAX::init();
开发者ID:JodiWarren,项目名称:woocommerce,代码行数:30,代码来源:class-wc-ajax.php
示例8: get_script_data
/**
* Return data for script handles.
* @access private
* @param string $handle
* @return array|bool
*/
private static function get_script_data($handle)
{
global $wp;
switch ($handle) {
case 'woocommerce':
return array('ajax_url' => WC()->ajax_url(), 'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"));
break;
case 'wc-geolocation':
return array('wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'home_url' => home_url(), 'is_cart' => is_cart() ? '1' : '0', 'is_account_page' => is_account_page() ? '1' : '0', 'is_checkout' => is_checkout() ? '1' : '0', 'hash' => isset($_GET['v']) ? wc_clean($_GET['v']) : '');
break;
case 'wc-single-product':
return array('i18n_required_rating_text' => esc_attr__('Please select a rating', 'woocommerce'), 'review_rating_required' => get_option('woocommerce_review_rating_required'));
break;
case 'wc-checkout':
return array('ajax_url' => WC()->ajax_url(), 'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'update_order_review_nonce' => wp_create_nonce('update-order-review'), 'apply_coupon_nonce' => wp_create_nonce('apply-coupon'), 'remove_coupon_nonce' => wp_create_nonce('remove-coupon'), 'option_guest_checkout' => get_option('woocommerce_enable_guest_checkout'), 'checkout_url' => WC_AJAX::get_endpoint("checkout"), 'is_checkout' => is_page(wc_get_page_id('checkout')) && empty($wp->query_vars['order-pay']) && !isset($wp->query_vars['order-received']) ? 1 : 0, 'debug_mode' => defined('WP_DEBUG') && WP_DEBUG, 'i18n_checkout_error' => esc_attr__('Error processing checkout. Please try again.', 'woocommerce'));
break;
case 'wc-address-i18n':
return array('locale' => json_encode(WC()->countries->get_country_locale()), 'locale_fields' => json_encode(WC()->countries->get_country_locale_field_selectors()), 'i18n_required_text' => esc_attr__('required', 'woocommerce'));
break;
case 'wc-cart':
return array('ajax_url' => WC()->ajax_url(), 'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'update_shipping_method_nonce' => wp_create_nonce("update-shipping-method"));
break;
case 'wc-cart-fragments':
return array('ajax_url' => WC()->ajax_url(), 'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'fragment_name' => apply_filters('woocommerce_cart_fragment_name', 'wc_fragments'));
break;
case 'wc-add-to-cart':
return array('ajax_url' => WC()->ajax_url(), 'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'i18n_view_cart' => esc_attr__('View Cart', 'woocommerce'), 'cart_url' => apply_filters('woocommerce_add_to_cart_redirect', WC()->cart->get_cart_url()), 'is_cart' => is_cart(), 'cart_redirect_after_add' => get_option('woocommerce_cart_redirect_after_add'));
break;
case 'wc-add-to-cart-variation':
return array('i18n_no_matching_variations_text' => esc_attr__('Sorry, no products matched your selection. Please choose a different combination.', 'woocommerce'), 'i18n_unavailable_text' => esc_attr__('Sorry, this product is unavailable. Please choose a different combination.', 'woocommerce'));
break;
case 'wc-country-select':
return array('countries' => json_encode(array_merge(WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states())), 'i18n_select_state_text' => esc_attr__('Select an option…', 'woocommerce'), 'i18n_matches_1' => _x('One result is available, press enter to select it.', 'enhanced select', 'woocommerce'), 'i18n_matches_n' => _x('%qty% results are available, use up and down arrow keys to navigate.', 'enhanced select', 'woocommerce'), 'i18n_no_matches' => _x('No matches found', 'enhanced select', 'woocommerce'), 'i18n_ajax_error' => _x('Loading failed', 'enhanced select', 'woocommerce'), 'i18n_input_too_short_1' => _x('Please enter 1 or more characters', 'enhanced select', 'woocommerce'), 'i18n_input_too_short_n' => _x('Please enter %qty% or more characters', 'enhanced select', 'woocommerce'), 'i18n_input_too_long_1' => _x('Please delete 1 character', 'enhanced select', 'woocommerce'), 'i18n_input_too_long_n' => _x('Please delete %qty% characters', 'enhanced select', 'woocommerce'), 'i18n_selection_too_long_1' => _x('You can only select 1 item', 'enhanced select', 'woocommerce'), 'i18n_selection_too_long_n' => _x('You can only select %qty% items', 'enhanced select', 'woocommerce'), 'i18n_load_more' => _x('Loading more results…', 'enhanced select', 'woocommerce'), 'i18n_searching' => _x('Searching…', 'enhanced select', 'woocommerce'));
break;
}
return false;
}
开发者ID:mselango,项目名称:driz-project,代码行数:43,代码来源:class-wc-frontend-scripts.php
示例9: removeCartToFly
function removeCartToFly()
{
global $woocommerce;
$woocommerce->cart->set_quantity($_POST['remove_item'], 0);
if ($woocommerce->cart) {
$items_in_cart = $woocommerce->cart->cart_contents_count;
$prod_ids_in_cart = array();
foreach ($woocommerce->cart->get_cart() as $cart_item_key => $cart_item) {
$product_id = apply_filters('woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key);
array_push($prod_ids_in_cart, $product_id);
}
$test01 = 0;
$test02 = 0;
$test03 = 0;
$test04 = 0;
if (in_array("566", $prod_ids_in_cart)) {
$test01 = 1;
}
if (in_array("568", $prod_ids_in_cart)) {
$test02 = 1;
}
if (in_array("570", $prod_ids_in_cart)) {
$test03 = 1;
}
if (in_array("572", $prod_ids_in_cart)) {
$test04 = 1;
}
$how_many_tests_in_cart = $test01 + $test02 + $test03 + $test04;
if (in_array("574", $prod_ids_in_cart)) {
foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
if ($cart_item['product_id'] == 574) {
$woocommerce->cart->set_quantity($cart_item_key, 0);
}
}
if ($how_many_tests_in_cart == 0) {
}
if ($how_many_tests_in_cart == 1) {
$woocommerce->cart->add_to_cart('574', '1', '719', '1');
}
if ($how_many_tests_in_cart == 2) {
$woocommerce->cart->add_to_cart('574', '1', '720', '2');
}
if ($how_many_tests_in_cart == 3) {
$woocommerce->cart->add_to_cart('574', '1', '721', '3');
}
if ($how_many_tests_in_cart == 4) {
$woocommerce->cart->add_to_cart('574', '1', '722', '4');
}
}
// end if there is processing in cart
}
// edn of if woocommerce cart
$ver = explode(".", WC_VERSION);
if ($ver[0] >= 2 && $ver[1] >= 0 && $ver[2] >= 0) {
$wc_ajax = new WC_AJAX();
$wc_ajax->get_refreshed_fragments();
} else {
woocommerce_get_refreshed_fragments();
}
die;
}
开发者ID:WP-Panda,项目名称:allergenics,代码行数:61,代码来源:functions.php
示例10: so_27270880_add_variation_to_cart
function so_27270880_add_variation_to_cart()
{
ob_start();
$product_id = apply_filters('woocommerce_add_to_cart_product_id', absint($_POST['product_id']));
$quantity = empty($_POST['quantity']) ? 1 : wc_stock_amount($_POST['quantity']);
$variation_id = isset($_POST['variation_id']) ? absint($_POST['variation_id']) : '';
$variations = !empty($_POST['variation']) ? (array) $_POST['variation'] : '';
$passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity, $variation_id, $variations, $cart_item_data);
if ($passed_validation && WC()->cart->add_to_cart($product_id, $quantity, $variation_id, $variations)) {
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
$data = array('error' => true, 'product_url' => apply_filters('woocommerce_cart_redirect_after_error', get_permalink($product_id), $product_id));
wp_send_json($data);
}
die;
}
开发者ID:developmentDM2,项目名称:The-Haute-Mess,代码行数:22,代码来源:woocommerce.php
示例11: porto_refresh_cart_fragment
function porto_refresh_cart_fragment()
{
$cart_ajax = new WC_AJAX();
$cart_ajax->get_refreshed_fragments();
exit;
}
开发者ID:rinodung,项目名称:live-theme,代码行数:6,代码来源:woocommerce.php
示例12: json_search_products
public function json_search_products()
{
WC_AJAX::json_search_products('', array('product'));
}
开发者ID:daanbakker1995,项目名称:vanteun,代码行数:4,代码来源:class-wc-crm-ajax.php
示例13: enqueue_scripts
/**
* Enqueue the scripts and styles in the page
*/
public function enqueue_scripts()
{
// scripts
wp_enqueue_script('yith-woocompare-main', YITH_WOOCOMPARE_ASSETS_URL . '/js/woocompare.js', array('jquery'), $this->version, true);
wp_localize_script('yith-woocompare-main', 'yith_woocompare', array('ajaxurl' => WC_AJAX::get_endpoint("%%endpoint%%"), 'actionadd' => $this->action_add, 'actionremove' => $this->action_remove, 'actionview' => $this->action_view, 'added_label' => __('Added', 'yith-woocommerce-compare'), 'table_title' => __('Product Comparison', 'yith-woocommerce-compare'), 'auto_open' => get_option('yith_woocompare_auto_open', 'yes'), 'loader' => YITH_WOOCOMPARE_ASSETS_URL . '/images/loader.gif', 'button_text' => get_option('yith_woocompare_button_text')));
// colorbox
wp_enqueue_style('jquery-colorbox', YITH_WOOCOMPARE_ASSETS_URL . '/css/colorbox.css');
wp_enqueue_script('jquery-colorbox', YITH_WOOCOMPARE_ASSETS_URL . '/js/jquery.colorbox-min.js', array('jquery'), '1.4.21', true);
// widget
if (is_active_widget(false, false, 'yith-woocompare-widget', true) && !is_admin()) {
wp_enqueue_style('yith-woocompare-widget', YITH_WOOCOMPARE_ASSETS_URL . '/css/widget.css');
}
}
开发者ID:mautd29388,项目名称:naturel,代码行数:16,代码来源:class.yith-woocompare-frontend.php
示例14: install
/**
* Install WC
*/
public static function install()
{
global $wpdb;
if (!defined('WC_INSTALLING')) {
define('WC_INSTALLING', true);
}
// Ensure needed classes are loaded
include_once 'admin/class-wc-admin-notices.php';
self::create_options();
self::create_tables();
self::create_roles();
// Register post types
WC_Post_types::register_post_types();
WC_Post_types::register_taxonomies();
// Also register endpoints - this needs to be done prior to rewrite rule flush
WC()->query->init_query_vars();
WC()->query->add_endpoints();
WC_API::add_endpoint();
WC_Auth::add_endpoint();
WC_AJAX::add_endpoint();
self::create_terms();
self::create_cron_jobs();
self::create_files();
// Queue upgrades
$current_db_version = get_option('woocommerce_db_version', null);
if (version_compare($current_db_version, '2.3.0', '<') && null !== $current_db_version) {
WC_Admin_Notices::add_notice('update');
} else {
delete_option('woocommerce_db_version');
add_option('woocommerce_db_version', WC()->version);
}
// Update version
delete_option('woocommerce_version');
add_option('woocommerce_version', WC()->version);
// Check if pages are needed
if (wc_get_page_id('shop') < 1) {
WC_Admin_Notices::add_notice('install');
}
// Flush rules after install
flush_rewrite_rules();
delete_transient('wc_attribute_taxonomies');
/*
* Deletes all expired transients. The multi-table delete syntax is used
* to delete the transient record from table a, and the corresponding
* transient_timeout record from table b.
*
* Based on code inside core's upgrade_network() function.
*/
$sql = "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b\n\t\t\tWHERE a.option_name LIKE %s\n\t\t\tAND a.option_name NOT LIKE %s\n\t\t\tAND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )\n\t\t\tAND b.option_value < %d";
$wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_transient_') . '%', $wpdb->esc_like('_transient_timeout_') . '%', time()));
// Redirect to welcome screen
if (!is_network_admin() && !isset($_GET['activate-multi'])) {
set_transient('_wc_activation_redirect', 1, 30);
}
// Trigger action
do_action('woocommerce_installed');
}
开发者ID:nightbook,项目名称:woocommerce,代码行数:60,代码来源:class-wc-install.php
示例15: venedor_ajax_product_remove
function venedor_ajax_product_remove()
{
$cart = WC()->instance()->cart;
$cart_id = $_POST['cart_id'];
$cart_item_id = $cart->find_product_in_cart($cart_id);
if ($cart_item_id) {
$cart->set_quantity($cart_item_id, 0);
}
$cart_ajax = new WC_AJAX();
$cart_ajax->get_refreshed_fragments();
exit;
}
开发者ID:robwri32,项目名称:garland,代码行数:12,代码来源:functions.php
示例16: addToCart
public function addToCart()
{
check_ajax_referer('jckqv', 'nonce');
global $woocommerce;
$varId = isset($_GET['variation_id']) ? $_GET['variation_id'] : '';
$_GET['quantity'] = isset($_GET['quantity']) ? $_GET['quantity'] : 1;
$variations = array();
foreach ($_GET as $key => $value) {
if (substr($key, 0, 10) == "attribute_") {
$variations[$key] = $value;
}
}
if (is_array($_GET['quantity'])) {
foreach ($_GET['quantity'] as $prodId => $prodQty) {
if ($prodQty > 0) {
$atc = $woocommerce->cart->add_to_cart($prodId, $prodQty, $varId, $variations);
if ($atc) {
continue;
} else {
break;
}
}
}
} else {
$atc = $woocommerce->cart->add_to_cart($_GET['product_id'], $_GET['quantity'], $varId, $variations);
}
if ($atc) {
$woocommerce->cart->maybe_set_cart_cookies();
$wc_ajax = new WC_AJAX();
$wc_ajax->get_refreshed_fragments();
} else {
header('Content-Type: application/json');
$soldIndv = get_post_meta($_GET['product_id'], '_sold_individually', true);
if ($soldIndv == "yes") {
$response = array('result' => 'individual');
$response['message'] = __('Sorry, that item can only be added once.', $this->slug);
} else {
$response = array('result' => 'fail');
$response['message'] = __('Sorry, something went wrong. Please try again.', $this->slug);
}
$response['get'] = $_GET;
echo json_encode($response);
}
die;
}
开发者ID:brycefrees,项目名称:DivisionWest,代码行数:45,代码来源:jck_woo_quickview.php
示例17: enqueue_scripts
/**
* Enqueue the scripts and styles in the page
*/
public function enqueue_scripts()
{
// scripts
$min = !(defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '.min' : '';
wp_register_script('yith-woocompare-main', YITH_WOOCOMPARE_ASSETS_URL . '/js/woocompare' . $min . '.js', array('jquery'), $this->version, true);
// enqueue and add localize
wp_enqueue_script('yith-woocompare-main');
wp_localize_script('yith-woocompare-main', 'yith_woocompare', array('ajaxurl' => version_compare(WC()->version, '2.4', '>=') ? WC_AJAX::get_endpoint("%%endpoint%%") : admin_url('admin-ajax.php', 'relative'), 'actionadd' => $this->action_add, 'actionremove' => $this->action_remove, 'actionview' => $this->action_view, 'added_label' => apply_filters('yith_woocompare_compare_added_label', __('Added', 'yith-woocommerce-compare')), 'table_title' => apply_filters('yith_woocompare_compare_table_title', __('Product Comparison', 'yith-woocommerce-compare')), 'auto_open' => get_option('yith_woocompare_auto_open', 'yes'), 'loader' => YITH_WOOCOMPARE_ASSETS_URL . '/images/loader.gif', 'button_text' => get_option('yith_woocompare_button_text')));
// colorbox
wp_enqueue_style('jquery-colorbox', YITH_WOOCOMPARE_ASSETS_URL . '/css/colorbox.css');
wp_enqueue_script('jquery-colorbox', YITH_WOOCOMPARE_ASSETS_URL . '/js/jquery.colorbox-min.js', array('jquery'), '1.4.21', true);
// widget
if (is_active_widget(false, false, 'yith-woocompare-widget', true) && !is_admin()) {
wp_enqueue_style('yith-woocompare-widget', YITH_WOOCOMPARE_ASSETS_URL . '/css/widget.css');
}
}
开发者ID:websideas,项目名称:Mondova,代码行数:19,代码来源:class.yith-woocompare-frontend.php
示例18: get_script_data
/**
* Return data for script handles.
* @access private
* @param string $handle
* @return array|bool
*/
private static function get_script_data($handle)
{
global $wp;
switch ($handle) {
case 'woocommerce':
return array('ajax_url' => WC()->ajax_url(), 'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"));
break;
case 'wc-geolocation':
return array('wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'home_url' => home_url(), 'is_available' => !(is_cart() || is_account_page() || is_checkout() || is_customize_preview()) ? '1' : '0', 'hash' => isset($_GET['version']) ? wc_clean($_GET['version']) : '');
break;
case 'wc-single-product':
return array('i18n_required_rating_text' => esc_attr__('Please select a rating', 'woocommerce'), 'review_rating_required' => get_option('woocommerce_review_rating_required'), 'flexslider' => apply_filters('woocommerce_single_product_carousel_options', array('rtl' => is_rtl(), 'animation' => 'slide', 'smoothHeight' => true, 'directionNav' => false, 'controlNav' => 'thumbnails', 'slideshow' => false, 'animationSpeed' => 500)));
break;
case 'wc-checkout':
return array('ajax_url' => WC()->ajax_url(), 'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'update_order_review_nonce' => wp_create_nonce('update-order-review'), 'apply_coupon_nonce' => wp_create_nonce('apply-coupon'), 'remove_coupon_nonce' => wp_create_nonce('remove-coupon'), 'option_guest_checkout' => get_option('woocommerce_enable_guest_checkout'), 'checkout_url' => WC_AJAX::get_endpoint("checkout"), 'is_checkout' => is_page(wc_get_page_id('checkout')) && empty($wp->query_vars['order-pay']) && !isset($wp->query_vars['order-received']) ? 1 : 0, 'debug_mode' => defined('WP_DEBUG') && WP_DEBUG, 'i18n_checkout_error' => esc_attr__('Error processing checkout. Please try again.', 'woocommerce'));
break;
case 'wc-address-i18n':
return array('locale' => json_encode(WC()->countries->get_country_locale()), 'locale_fields' => json_encode(WC()->countries->get_country_locale_field_selectors()), 'i18n_required_text' => esc_attr__('required', 'woocommerce'));
break;
case 'wc-cart':
return array('ajax_url' => WC()->ajax_url(), 'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'update_shipping_method_nonce' => wp_create_nonce("update-shipping-method"), 'apply_coupon_nonce' => wp_create_nonce("apply-coupon"), 'remove_coupon_nonce' => wp_create_nonce("remove-coupon"));
break;
case 'wc-cart-fragments':
return array('ajax_url' => WC()->ajax_url(), 'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'fragment_name' => apply_filters('woocommerce_cart_fragment_name', 'wc_fragments'));
break;
case 'wc-add-to-cart':
return array('ajax_url' => WC()->ajax_url(), 'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'i18n_view_cart' => esc_attr__('View cart', 'woocommerce'), 'cart_url' => apply_filters('woocommerce_add_to_cart_redirect', wc_get_cart_url()), 'is_cart' => is_cart(), 'cart_redirect_after_add' => get_option('woocommerce_cart_redirect_after_add'));
break;
case 'wc-add-to-cart-variation':
// We also need the wp.template for this script :)
wc_get_template('single-product/add-to-cart/variation.php');
return array('wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%"), 'i18n_no_matching_variations_text' => esc_attr__('Sorry, no products matched your selection. Please choose a different combination.', 'woocommerce'), 'i18n_make_a_selection_text' => esc_attr__('Please select some product options before adding this product to your cart.', 'woocommerce'), 'i18n_unavailable_text' => esc_attr__('Sorry, this product is unavailable. Please choose a different combination.', 'woocommerce'));
break;
case 'wc-country-select':
return array('countries' => json_encode(array_merge(WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states())), 'i18n_select_state_text' => esc_attr__('Select an option…', 'woocommerce'), 'i18n_matches_1' => _x('One result is available, press enter to select it.', 'enhanced select', 'woocommerce'), 'i18n_matches_n' => _x('%qty% results are available, use up and down arrow keys to navigate.', 'enhanced select', 'woocommerce'), 'i18n_no_matches' => _x('No matches found', 'enhanced select', 'woocommerce'), 'i18n_ajax_error' => _x('Loading failed', 'enhanced select', 'woocommerce'), 'i18n_input_too_short_1' => _x('Please enter 1 or more characters', 'enhanced select', 'woocommerce'), 'i18n_input_too_short_n' => _x('Please enter %qty% or more characters', 'enhanced select', 'woocommerce'), 'i18n_input_too_long_1' => _x('Please delete 1 character', 'enhanced select', 'woocommerce'), 'i18n_input_too_long_n' => _x('Please delete %qty% characters', 'enhanced select', 'woocommerce'), 'i18n_selection_too_long_1' => _x('You can only select 1 item', 'enhanced select', 'woocommerce'), 'i18n_selection_too_long_n' => _x('You can only select %qty% items', 'enhanced select', 'woocommerce'), 'i18n_load_more' => _x('Loading more results…', 'enhanced select', 'woocommerce'), 'i18n_searching' => _x('Searching…', 'enhanced select', 'woocommerce'));
break;
case 'wc-password-strength-meter':
return array('min_password_strength' => apply_filters('woocommerce_min_password_strength', 3), 'i18n_password_error' => esc_attr__('Please enter a stronger password.', 'woocommerce'), 'i18n_password_hint' => esc_attr__('The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ & ).', 'woocommerce'));
break;
}
return false;
}
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:48,代码来源:class-wc-frontend-scripts.php
示例19: install
/**
* Install WC
*/
public static function install()
{
if (!defined('WC_INSTALLING')) {
define('WC_INSTALLING', true);
}
// Ensure needed classes are loaded
include_once 'admin/class-wc-admin-notices.php';
self::create_options();
self::create_tables();
self::create_roles();
// Register post types
WC_Post_types::register_post_types();
WC_Post_types::register_taxonomies();
// Also register endpoints - this needs to be done prior to rewrite rule flush
WC()->query->init_query_vars();
WC()->query->add_endpoints();
WC_API::add_endpoint();
WC_AJAX::add_endpoint();
self::create_terms();
self::create_cron_jobs();
self::create_files();
// Queue upgrades
$current_db_version = get_option('woocommerce_db_version', null);
if (version_compare($current_db_version, '2.3.0', '<') && null !== $current_db_version) {
WC_Admin_Notices::add_notice('update');
} else {
delete_option('woocommerce_db_version');
add_option('woocommerce_db_version', WC()->version);
}
// Update version
delete_option('woocommerce_version');
add_option('woocommerce_version', WC()->version);
// Check if pages are needed
if (wc_get_page_id('shop') < 1) {
WC_Admin_Notices::add_notice('install');
}
// Flush rules after install
flush_rewrite_rules();
delete_transient('wc_attribute_taxonomies');
// Redirect to welcome screen
if (!is_network_admin() && !isset($_GET['activate-multi'])) {
set_transient('_wc_activation_redirect', 1, 30);
}
// Trigger action
do_action('woocommerce_installed');
}
开发者ID:nathanielks,项目名称:woocommerce,代码行数:49,代码来源:class-wc-install.php
注:本文中的WC_AJAX类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论