/** * Create a order. * * @since 2.4 * * @return WC_Order Order object. */ public static function create_order() { // Create product $product = WC_Helper_Product::create_simple_product(); WC_Helper_Shipping::create_simple_flat_rate(); $order_data = array('status' => 'pending', 'customer_id' => 1, 'customer_note' => '', 'total' => ''); $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // Required, else wc_create_order throws an exception $order = wc_create_order($order_data); // Add order products $item_id = $order->add_product($product, 4); // Set billing address $billing_address = array('country' => 'US', 'first_name' => 'Jeroen', 'last_name' => 'Sormani', 'company' => 'WooCompany', 'address_1' => 'WooAddress', 'address_2' => '', 'postcode' => '123456', 'city' => 'WooCity', 'state' => 'NY', 'email' => '*****@*****.**', 'phone' => '555-32123'); $order->set_address($billing_address, 'billing'); // Add shipping costs $shipping_taxes = WC_Tax::calc_shipping_tax('10', WC_Tax::get_shipping_tax_rates()); $order->add_shipping(new WC_Shipping_Rate('flat_rate_shipping', 'Flat rate shipping', '10', $shipping_taxes, 'flat_rate')); // Set payment gateway $payment_gateways = WC()->payment_gateways->payment_gateways(); $order->set_payment_method($payment_gateways['bacs']); // Set totals $order->set_total(10, 'shipping'); $order->set_total(0, 'cart_discount'); $order->set_total(0, 'cart_discount_tax'); $order->set_total(0, 'tax'); $order->set_total(0, 'shipping_tax'); $order->set_total(40, 'total'); // 4 x $10 simple helper product return wc_get_order($order->id); }
public static function update_orders_value( $post_id, $post ) { if ( is_int( wp_is_post_revision( $post_id ) ) ) return; if ( is_int( wp_is_post_autosave( $post_id ) ) ) return; if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; if ( ! current_user_can( 'edit_post', $post_id ) ) return $post_id; if ( $post->post_type != 'product' ) return $post_id; if ( version_compare( WC()->version, '2.2.0', '<' ) ) { $product = get_product( $post ); } else { $product = wc_get_product( $post ); } if ( $product ) { if ( $product->is_on_sale() ) { update_post_meta( $post_id, '_psad_onsale_order', 2 ); } else { update_post_meta( $post_id, '_psad_onsale_order', 1 ); } if ( $product->is_featured() ) { update_post_meta( $post_id, '_psad_featured_order', 2 ); } else { update_post_meta( $post_id, '_psad_featured_order', 1 ); } } }
public function record_user_event($event_type, $data = array()) { if (!function_exists('jetpack_tracks_record_event')) { $this->log('Error. jetpack_tracks_record_event is not defined.'); return; } $user = wp_get_current_user(); $site_url = get_option('siteurl'); // Check for WooCommerce $wc_version = 'unavailable'; if (function_exists('WC')) { $wc_version = WC()->version; } // Check for Jetpack $jp_version = 'unavailable'; if (defined('JETPACK__VERSION')) { $jp_version = JETPACK__VERSION; } $jetpack_blog_id = -1; if (class_exists('Jetpack_Options') && method_exists('Jetpack_Options', 'get_option')) { $jetpack_blog_id = Jetpack_Options::get_option('id'); } $data['_via_ua'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $data['_via_ip'] = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $data['_lg'] = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : ''; $data['blog_url'] = $site_url; $data['blog_id'] = $jetpack_blog_id; $data['jetpack_version'] = $jp_version; $data['wc_version'] = $wc_version; $data['wp_version'] = get_bloginfo('version'); $event_type = self::$product_name . '_' . $event_type; $this->log('Tracked the following event: ' . $event_type); return jetpack_tracks_record_event($user, $event_type, $data); }
public static function bulky_woocommerce_cart_shipping_packages($packages) { // Reset the packages $packages = array(); // Bulky items $free_items = array(); $regular_items = array(); // Sort free from others foreach (WC()->cart->get_cart() as $item) { if ($item['data']->needs_shipping()) { if ($item['data']->get_shipping_class() == 'free' || $item['data']->get_shipping_class() == '') { $free_items[] = $item; } else { $regular_items[] = $item; } } } // Put inside packages if ($free_items) { $packages[] = array('ship_via' => array('free_shipping'), 'contents' => $free_items, 'contents_cost' => array_sum(wp_list_pluck($free_items, 'line_total')), 'applied_coupons' => WC()->cart->applied_coupons, 'destination' => array('country' => WC()->customer->get_shipping_country(), 'state' => WC()->customer->get_shipping_state(), 'postcode' => WC()->customer->get_shipping_postcode(), 'city' => WC()->customer->get_shipping_city(), 'address' => WC()->customer->get_shipping_address(), 'address_2' => WC()->customer->get_shipping_address_2())); } if ($regular_items) { $packages[] = array('ship_via' => array('flat_rate'), 'contents' => $regular_items, 'contents_cost' => array_sum(wp_list_pluck($regular_items, 'line_total')), 'applied_coupons' => WC()->cart->applied_coupons, 'destination' => array('country' => WC()->customer->get_shipping_country(), 'state' => WC()->customer->get_shipping_state(), 'postcode' => WC()->customer->get_shipping_postcode(), 'city' => WC()->customer->get_shipping_city(), 'address' => WC()->customer->get_shipping_address(), 'address_2' => WC()->customer->get_shipping_address_2())); } return $packages; }
/** * widget function. * * @see WP_Widget * @access public * @param array $args * @param array $instance * @return void */ public function widget($args, $instance) { if ($this->get_cached_widget($args)) { return; } ob_start(); extract($args); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); $number = absint($instance['number']); add_filter('posts_clauses', array(WC()->query, 'order_by_rating_post_clauses')); $query_args = array('posts_per_page' => $number, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product'); $query_args['meta_query'] = WC()->query->get_meta_query(); $r = new WP_Query($query_args); if ($r->have_posts()) { echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } echo '<ul class="product_list_widget">'; while ($r->have_posts()) { $r->the_post(); wc_get_template('content-widget-product.php', array('show_rating' => true)); } echo '</ul>'; echo $after_widget; } remove_filter('posts_clauses', array(WC()->query, 'order_by_rating_post_clauses')); wp_reset_postdata(); $content = ob_get_clean(); echo $content; $this->cache_widget($args, $content); }
/** * Test the is_customer_outside_base method */ public function test_is_customer_outside_base() { // Get the original settings for the session and the WooCommerce options $original_chosen_shipping_methods = \WC_Helper_Customer::get_chosen_shipping_methods(); $original_tax_based_on = \WC_Helper_Customer::get_tax_based_on(); $original_customer_details = \WC_Helper_Customer::get_customer_details(); $customer = \WC_Helper_Customer::create_mock_customer(); // Create dummy product, and add the product to the cart. $product = \WC_Helper_Product::create_simple_product(); WC()->cart->add_to_cart($product->id, 1); // Customer is going with the Local Pickup option, and the store calculates tax based on the store location. \WC_Helper_Customer::set_chosen_shipping_methods(array('local_pickup')); \WC_Helper_Customer::set_tax_based_on('base'); $this->assertEquals($customer->is_customer_outside_base(), false); // Customer is going with the Local Pickup option, and the store calculates tax based on the customer's billing address. \WC_Helper_Customer::set_chosen_shipping_methods(array('local_pickup')); \WC_Helper_Customer::set_tax_based_on('billing'); $this->assertEquals($customer->is_customer_outside_base(), false); // Customer is going with the Free Shipping option, and the store calculates tax based on the customer's billing address. \WC_Helper_Customer::set_chosen_shipping_methods(array('free_shipping')); \WC_Helper_Customer::set_tax_based_on('billing'); $this->assertEquals($customer->is_customer_outside_base(), true); // Customer is going with the Free Shipping option, and the store calculates tax based on the store base location. \WC_Helper_Customer::set_chosen_shipping_methods(array('free_shipping')); \WC_Helper_Customer::set_tax_based_on('base'); $this->assertEquals($customer->is_customer_outside_base(), false); //Now reset the settings back to the way they were before this test \WC_Helper_Customer::set_chosen_shipping_methods($original_chosen_shipping_methods); \WC_Helper_Customer::set_tax_based_on($original_tax_based_on); \WC_Helper_Customer::set_customer_details($original_customer_details); // Clean up the cart WC()->cart->empty_cart(); // Clean up product \WC_Helper_Product::delete_product($product->id); }
function add_position_to_session_callback() { WC()->session->set('latitude', esc_attr($_POST['lat'])); WC()->session->set('longitude', esc_attr($_POST['lng'])); echo 'done'; die; }
/** * Constructor */ public function __construct() { // Init settings $this->init_form_fields(); $this->init_settings(); // Save settings hook add_action('woocommerce_update_options_email_' . $this->id, array($this, 'process_admin_options')); // Default template base if not declared in child constructor if (is_null($this->template_base)) { $this->template_base = WC()->plugin_path() . '/templates/'; } // Settings $this->heading = $this->get_option('heading', $this->heading); $this->subject = $this->get_option('subject', $this->subject); $this->email_type = $this->get_option('email_type'); $this->enabled = $this->get_option('enabled'); // Find/replace $this->find['blogname'] = '{blogname}'; $this->find['site-title'] = '{site_title}'; $this->replace['blogname'] = $this->get_blogname(); $this->replace['site-title'] = $this->get_blogname(); // For multipart messages add_filter('phpmailer_init', array($this, 'handle_multipart')); // For default inline styles add_filter('woocommerce_email_style_inline_tags', array($this, 'style_inline_tags')); add_filter('woocommerce_email_style_inline_h1_tag', array($this, 'style_inline_h1_tag')); add_filter('woocommerce_email_style_inline_h2_tag', array($this, 'style_inline_h2_tag')); add_filter('woocommerce_email_style_inline_h3_tag', array($this, 'style_inline_h3_tag')); add_filter('woocommerce_email_style_inline_a_tag', array($this, 'style_inline_a_tag')); add_filter('woocommerce_email_style_inline_img_tag', array($this, 'style_inline_img_tag')); }
public function get_output($placeholder = true, $placeholder_src = 'default') { $picker = ''; $href = apply_filters('woocommerce_swatches_get_swatch_href', '#', $this); $anchor_class = apply_filters('woocommerce_swatches_get_swatch_anchor_css_class', 'swatch-anchor', $this); $image_class = apply_filters('woocommerce_swatches_get_swatch_image_css_class', 'swatch-img', $this); $image_alt = apply_filters('woocommerce_swatches_get_swatch_image_alt', 'thumbnail', $this); if ($this->type == 'photo' || $this->type == 'image') { $picker .= '<a href="' . $href . '" style="width:' . $this->width . 'px;height:' . $this->height . 'px;" title="' . esc_attr($this->term_label) . '" class="' . $anchor_class . '">'; $picker .= '<img src="' . apply_filters('woocommerce_swatches_get_swatch_image', $this->thumbnail_src, $this->term_slug, $this->taxonomy_slug, $this) . '" alt="' . $image_alt . '" class="wp-post-image swatch-photo' . $this->meta_key() . ' ' . $image_class . '" width="' . $this->width . '" height="' . $this->height . '"/>'; $picker .= '</a>'; } elseif ($this->type == 'color') { $picker .= '<a href="' . $href . '" style="text-indent:-9999px;width:' . $this->width . 'px;height:' . $this->height . 'px;background-color:' . apply_filters('woocommerce_swatches_get_swatch_color', $this->color, $this->term_slug, $this->taxonomy_slug, $this) . ';" title="' . $this->term_label . '" class="' . $anchor_class . '">' . $this->term_label . '</a>'; } elseif ($placeholder) { if ($placeholder_src == 'default') { $src = apply_filters('woocommerce_placeholder_img_src', WC()->plugin_url() . '/assets/images/placeholder.png'); } else { $src = $placeholder_src; } $picker .= '<a href="' . $href . '" style="width:' . $this->width . 'px;height:' . $this->height . 'px;" title="' . esc_attr($this->term_label) . '" class="' . $anchor_class . '">'; $picker .= '<img src="' . $src . '" alt="' . $image_alt . '" class="wp-post-image swatch-photo' . $this->meta_key() . ' ' . $image_class . '" width="' . $this->width . '" height="' . $this->height . '"/>'; $picker .= '</a>'; } else { return ''; } $out = '<div class="select-option swatch-wrapper' . ($this->selected ? ' selected' : '') . '" data-attribute="' . esc_attr($this->taxonomy_slug) . '" data-value="' . esc_attr($this->term_slug) . '">'; $out .= apply_filters('woocommerce_swatches_picker_html', $picker, $this); $out .= '</div>'; return $out; }
/** * Get My Account menu items. * * @since 2.6.0 * @return array */ function wc_get_account_menu_items() { $endpoints = array('orders' => get_option('woocommerce_myaccount_orders_endpoint', 'orders'), 'downloads' => get_option('woocommerce_myaccount_downloads_endpoint', 'downloads'), 'edit-address' => get_option('woocommerce_myaccount_edit_address_endpoint', 'edit-address'), 'payment-methods' => get_option('woocommerce_myaccount_payment_methods_endpoint', 'payment-methods'), 'edit-account' => get_option('woocommerce_myaccount_edit_account_endpoint', 'edit-account'), 'customer-logout' => get_option('woocommerce_logout_endpoint', 'customer-logout')); $items = array('dashboard' => __('Dashboard', 'woocommerce'), 'orders' => __('Orders', 'woocommerce'), 'downloads' => __('Downloads', 'woocommerce'), 'edit-address' => __('Addresses', 'woocommerce'), 'payment-methods' => __('Payment methods', 'woocommerce'), 'edit-account' => __('Account details', 'woocommerce'), 'customer-logout' => __('Logout', 'woocommerce')); // Remove missing endpoints. foreach ($endpoints as $endpoint_id => $endpoint) { if (empty($endpoint)) { unset($items[$endpoint_id]); } } // Check if payment gateways support add new payment methods. if (isset($items['payment-methods'])) { $support_payment_methods = false; foreach (WC()->payment_gateways->get_available_payment_gateways() as $gateway) { if ($gateway->supports('add_payment_method') || $gateway->supports('tokenization')) { $support_payment_methods = true; break; } } if (!$support_payment_methods) { unset($items['payment-methods']); } } return apply_filters('woocommerce_account_menu_items', $items); }
/** * Gets the total number of tickets requested *per event* (of course, we're only * interested in events that maintain global stock where tickets for those events * that utilize global stock are in the cart). * * @return array */ protected function cart_get_global_stock_quantities() { $cart = WC()->cart; $current = $cart->get_cart_item_quantities(); $woo_tickets = Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance(); $quantities = array(); foreach ($cart->get_cart() as $cart_item) { $product = $cart_item['data']; $event = $woo_tickets->get_event_for_ticket($product->id); // Skip non-tickets or tickets that do not utilize global stock if (!$event || !$woo_tickets->uses_global_stock($event->ID) || !$product->managing_stock()) { continue; } $tickets = $this->get_event_tickets($event->ID); if (!isset($tickets[$product->id])) { continue; } // We only need to accumulate the stock quantities of tickets using *global* stock if (Tribe__Tickets__Global_Stock::OWN_STOCK_MODE === $tickets[$product->id]->global_stock_mode()) { continue; } // Make sure ticket caps haven't been exceeded if (Tribe__Tickets__Global_Stock::CAPPED_STOCK_MODE === $tickets[$product->id]->global_stock_mode()) { if ($current[$product->id] > $tickets[$product->id]->global_stock_cap()) { $this->cart_flag_capped_stock_error($product->id); } } if (!isset($quantities[$event->ID])) { $quantities[$event->ID] = 0; } $quantities[$event->ID] += $current[$product->id]; } return $quantities; }
private function calclateShippingForPackage($package, $package_key) { //sanity check. Just to be sure if (!$this->isEnabled() || empty($package)) { return false; } // Check if we need to recalculate shipping for this package $package_hash = 'wc_ship_' . md5(json_encode($package) . Cache::getItem('shipping')); $status_options = get_option('woocommerce_status_options', array()); $session_key = 'shipping_for_package_' . $package_key; $stored_rates = WC()->session->get($session_key); if (!is_array($stored_rates) || $package_hash !== $stored_rates['package_hash'] || !empty($status_options['shipping_debug_mode'])) { // Calculate shipping method rates $package['rates'] = array(); foreach ($this->loadShippingMethods($package) as $shipping_method) { // Shipping instances need an ID $package['rates'] = $package['rates'] + Event::trigger('getRatesForPackage', array('shipping_method' => $shipping_method), 'filter'); } $package['rates'] = apply_filters('woocommerce_package_rates', $package['rates'], $package); // Store in session to avoid recalculation WC()->session->set($session_key, array('package_hash' => $package_hash, 'rates' => $package['rates'])); } else { $package['rates'] = $stored_rates['rates']; } return $package; }
/** * Init the mailer and call for the skipped next payment email notification hook. * * @since 1.0.0 * @access public * @static * @param $order WC_Order * @param $subscription WC_Subscription */ public static function send_next_payment_date_email($order, $subscription) { WC()->mailer(); if ($subscription->has_status(array('active')) && 'true' !== get_post_meta($subscription->id, '_skipped_next_payment_email_sent', true)) { do_action('subscription_skipped_notification', $order, $subscription); } }
/** * filter_available_payment_gateways_per_category. */ function filter_available_payment_gateways_per_category($available_gateways) { //if ( ! is_checkout() ) return $available_gateways; foreach ($available_gateways as $gateway_id => $gateway) { $categories_in = get_option('wcj_gateways_per_category_' . $gateway_id); if (!empty($categories_in)) { $do_skip = true; foreach (WC()->cart->get_cart() as $cart_item_key => $values) { $product_categories = get_the_terms($values['product_id'], 'product_cat'); if (empty($product_categories)) { continue; } // ... to next product in the cart foreach ($product_categories as $product_category) { if (in_array($product_category->term_id, $categories_in)) { // Current gateway is OK, breaking to check next gateway (no need to check other categories of the product) $do_skip = false; break; } } if (!$do_skip) { // Current gateway is OK, breaking to check next gateway (no need to check other products in the cart) break; } } if ($do_skip) { // Skip (i.e. hide/unset) current gateway - no products of needed categories found in the cart unset($available_gateways[$gateway_id]); } } } return $available_gateways; }
/** * RenaRomano Mobile Menu Button * Outputs the Primary Navigation Menu Button for the Pushy Menu * * @author Jordan Pakrosnis */ function rena_mobile_menu_button() { // Output Button ?> <div id="rena-mobile-topnav"> <a class="cart-contents" href="<?php echo WC()->cart->get_cart_url(); ?> " title="<?php _e('View your shopping cart'); ?> "> <i class="fa fa-shopping-cart"></i> <?php if (WC()->cart->cart_contents_count > 0) { echo '<span>' . WC()->cart->cart_contents_count . '</span>'; } ?> </a><button type="button" class="menu-btn"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> </div><!-- /#rena-mobile-topnav --> <?php }
/** * Handle IPN requests for the legacy paypal gateway by calling gateways manually if needed. * * @access public * @return void */ function woocommerce_legacy_paypal_ipn() { if (!empty($_GET['paypalListener']) && $_GET['paypalListener'] == 'paypal_standard_IPN') { WC()->payment_gateways(); do_action('woocommerce_api_wc_gateway_paypal'); } }
/** * widget function. * * @see WP_Widget * @access public * @param array $args * @param array $instance * @return void */ public function widget($args, $instance) { global $comments, $comment, $woocommerce; if ($this->get_cached_widget($args)) { return; } ob_start(); extract($args); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); $number = absint($instance['number']); $query_args = array('posts_per_page' => $number, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'post__in' => $viewed_products, 'orderby' => 'rand'); $query_args['meta_query'] = array(); $query_args['meta_query'][] = WC()->query->stock_status_meta_query(); $query_args['meta_query'] = array_filter($query_args['meta_query']); $r = new WP_Query($query_args); if ($r->have_posts()) { echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } echo '<ul class="product_list_widget">'; while ($r->have_posts()) { $r->the_post(); wc_get_template('content-widget-product.php'); } echo '</ul>'; echo $after_widget; } wp_reset_postdata(); $content = ob_get_clean(); echo $content; }
function wc_gzd_get_gzd_product($product) { if (!isset($product->gzd_product) || !is_object($product->gzd_product)) { $product->gzd_product = WC()->product_factory->get_gzd_product($product); } return $product->gzd_product; }
/** * Test wc_cart_totals_subtotal_html() * * @todo test with taxes incl./excl. * @since 2.4 */ public function test_wc_cart_totals_subtotal_html() { $product = \WC_Helper_Product::create_simple_product(); WC()->cart->add_to_cart($product->id, 1); $this->expectOutputString(wc_price($product->price), wc_cart_totals_subtotal_html()); \WC_Helper_Product::delete_product($product->id); }
/** * Delete the simple flat rate. * * @since 2.3 */ public static function delete_simple_flat_rate() { delete_option('woocommerce_flat_rate_settings'); delete_option('woocommerce_flat_rate'); WC_Cache_Helper::get_transient_version('shipping', true); WC()->shipping->unregister_shipping_methods(); }
/** * Settings page. * * Handles the display of the main woocommerce settings page in admin. * * @access public * @return void */ public static function output() { global $current_section, $current_tab; do_action('be_compare_settings_start'); wp_enqueue_script('woocommerce_settings', WC()->plugin_url() . '/assets/js/admin/settings.min.js', array('jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'iris', 'chosen'), WC()->version, true); wp_localize_script('woocommerce_settings', 'woocommerce_settings_params', array('i18n_nav_warning' => __('The changes you made will be lost if you navigate away from this page.', 'be-compare-products'))); // Include settings pages self::get_settings_pages(); // Get current tab/section $current_tab = empty($_GET['tab']) ? 'settings' : sanitize_title($_GET['tab']); $current_section = empty($_REQUEST['section']) ? '' : sanitize_title($_REQUEST['section']); // Save settings if data has been posted if (!empty($_POST)) { self::save(); } // Add any posted messages if (!empty($_GET['wc_error'])) { self::add_error(stripslashes($_GET['wc_error'])); } if (!empty($_GET['wc_message'])) { self::add_message(stripslashes($_GET['wc_message'])); } self::show_messages(); // Get tabs for the settings page $tabs = apply_filters('be_compare_settings_tabs_array', array()); include 'html-settings.php'; }
function wac_update() { // is_wac_ajax: flag defined on wooajaxcart.js if (!empty($_POST['is_wac_ajax'])) { $resp = array(); $resp['update_label'] = __('Update Cart', 'woocommerce'); $resp['price'] = 0; // render the cart totals (cart-totals.php) ob_start(); do_action('woocommerce_after_cart_table'); do_action('woocommerce_cart_collaterals'); do_action('woocommerce_after_cart'); $resp['html'] = ob_get_clean(); $resp['price'] = 0; // calculate the item price if (!empty($_POST['cart_item_key'])) { $items = WC()->cart->get_cart(); $cart_item_key = $_POST['cart_item_key']; if (array_key_exists($cart_item_key, $items)) { $cart_item = $items[$cart_item_key]; $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); $price = apply_filters('woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal($_product, $cart_item['quantity']), $cart_item, $cart_item_key); $resp['price'] = $price; } } echo json_encode($resp); exit; } }
function woo_warp_side_cart() { ?> <link rel="stylesheet" type="text/css" href="<?php echo '' . plugins_url('css/style.css', __FILE__) . ''; ?> "> <div class="side-cart uk-panel uk-panel-box uk-panel-box-secondary"> <span class="ww-cart-icon side-cart uk-panel uk-panel-box uk-panel-box-primary"> <span class="uk-icon-shopping-cart"></span> </span> <p> <?php echo sprintf(_n('%d item', '%d items', WC()->cart->cart_contents_count), WC()->cart->cart_contents_count); ?> <br /> <?php echo WC()->cart->get_cart_total(); ?> </p> <a class="uk-button uk-button-mini uk-width-1-1 uk-button-primary" href="<?php echo WC()->cart->get_cart_url(); ?> " title="<?php _e('View Cart'); ?> ">View Cart</a> </div> <?php }
/** * Output the shortcode. * * @param array $atts */ public static function output($atts) { // Check cart class is loaded or abort if (is_null(WC()->cart)) { return; } extract(shortcode_atts(array(), $atts)); global $post; if (!empty($_REQUEST['orderid']) && isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'woocommerce-order_tracking')) { $order_id = empty($_REQUEST['orderid']) ? 0 : esc_attr($_REQUEST['orderid']); $order_email = empty($_REQUEST['order_email']) ? '' : esc_attr($_REQUEST['order_email']); if (!$order_id) { echo '<p class="woocommerce-error">' . __('Please enter a valid order ID', 'woocommerce') . '</p>'; } elseif (!$order_email) { echo '<p class="woocommerce-error">' . __('Please enter a valid order email', 'woocommerce') . '</p>'; } else { $order = wc_get_order(apply_filters('woocommerce_shortcode_order_tracking_order_id', $order_id)); if ($order && $order->get_id() && $order_email) { if (strtolower($order->get_billing_email()) == strtolower($order_email)) { do_action('woocommerce_track_order', $order->get_id()); wc_get_template('order/tracking.php', array('order' => $order)); return; } } else { echo '<p class="woocommerce-error">' . sprintf(__('Sorry, we could not find that order ID in our database.', 'woocommerce'), get_permalink($post->ID)) . '</p>'; } } } wc_get_template('order/form-tracking.php'); }
function siw_wc_checkout_extra_information() { $checkout = WC()->checkout(); //lijsten van talen en niveau $languages = siw_get_array('languages'); $language_skill = siw_get_array('language_skill'); echo '<h1>Informatie voor partner</h1>'; echo '<div class="woocommerce-extra-fields">'; echo '<div id="infoForPartner"><h3>' . __('Informatie voor partnerorganisatie') . '</h3>'; woocommerce_form_field('motivation', array('type' => 'textarea', 'class' => array('form-row-first'), 'required' => true, 'label' => __('Motivation', 'siw'), 'placeholder' => __('Vul hier (in het Engels) in waarom je graag aan je gekozen project wil deelnemen.')), $checkout->get_value('motivation')); woocommerce_form_field('healthIssues', array('type' => 'textarea', 'class' => array('form-row-last'), 'required' => false, 'clear' => true, 'label' => __('Allergies/diet/health issues', 'siw'), 'placeholder' => __('Heb je een allergie, gebruik je medicijnen of volg je een diëet, vul dat dan hier in (in het Engels).', 'siw')), $checkout->get_value('healthIssues')); woocommerce_form_field('volunteerExperience', array('type' => 'textarea', 'class' => array('form-row-first'), 'required' => false, 'label' => __('Volunteer experience', 'siw'), 'placeholder' => __('Heb je eerder vrijwilligerswerk gedaan? Beschrijf dat dan hier (in het Engels).', 'siw')), $checkout->get_value('volunteerExperience')); woocommerce_form_field('togetherWith', array('type' => 'text', 'class' => array('form-row-last'), 'required' => false, 'clear' => true, 'label' => __('Together with', 'siw'), 'placeholder' => __('Wil je graag met iemand aan een project deelnemen. Vul zijn of haar naam dan hier in.', 'siw')), $checkout->get_value('togetherWith')); echo '</div>'; // gegevens noodcontact echo '<div id="emergencyContact"><h3>' . __('Noodcontact') . '</h3>'; woocommerce_form_field('emergencyContactName', array('type' => 'text', 'class' => array('form-row-first'), 'required' => true, 'label' => __('Naam', 'siw')), $checkout->get_value('emergencyContactName')); woocommerce_form_field('emergencyContactPhone', array('type' => 'text', 'class' => array('form-row-last'), 'required' => true, 'label' => __('Telefoonnummer', 'siw'), 'clear' => true), $checkout->get_value('emergencyContactPhone')); echo '</div>'; echo '<div id="languageSkills"><h3>' . __('Talenkennis') . '</h3>'; woocommerce_form_field('language1', array('type' => 'select', 'class' => array('form-row-first'), 'label' => __('Taal 1', 'siw'), 'required' => true, 'clear' => true, 'options' => $languages), $checkout->get_value('language1')); woocommerce_form_field('language1Skill', array('type' => 'radio', 'class' => array('form-row-wide'), 'label' => __('Niveau taal 1', 'siw'), 'required' => true, 'clear' => true, 'options' => $language_skill), $checkout->get_value('language1Skill')); woocommerce_form_field('language2', array('type' => 'select', 'class' => array('form-row-first'), 'label' => __('Taal 2', 'siw'), 'required' => false, 'clear' => true, 'options' => $languages), $checkout->get_value('language2')); woocommerce_form_field('language2Skill', array('type' => 'radio', 'class' => array('form-row-wide'), 'label' => __('Niveau taal 2', 'siw'), 'required' => false, 'clear' => true, 'options' => $language_skill), $checkout->get_value('language2Skill')); woocommerce_form_field('language3', array('type' => 'select', 'class' => array('form-row-first'), 'label' => __('Taal 3', 'siw'), 'required' => false, 'clear' => true, 'options' => $languages), $checkout->get_value('language3')); woocommerce_form_field('language3Skill', array('type' => 'radio', 'class' => array('form-row-wide'), 'label' => __('Niveau taal 3', 'siw'), 'required' => false, 'clear' => true, 'options' => $language_skill), $checkout->get_value('language3Skill')); echo '</div>'; echo '</div>'; }
public function __construct() { $this->id = 'tbz_voguepay_gateway'; $this->icon = apply_filters('woocommerce_vogueway_icon', plugins_url('assets/pay-via-voguepay.png', __FILE__)); $this->has_fields = false; $this->order_button_text = 'Make Payment'; $this->payment_url = 'https://voguepay.com/pay/'; $this->notify_url = WC()->api_request_url('WC_Tbz_Voguepay_Gateway'); $this->method_title = 'VoguePay Payment Gateway'; $this->method_description = 'VoguePay Payment Gateway allows you to receive Mastercard, Verve Card and Visa Card Payments On your Woocommerce Powered Site.'; // Load the form fields. $this->init_form_fields(); // Load the settings. $this->init_settings(); // Define user set variables $this->title = $this->get_option('title'); $this->description = $this->get_option('description'); $this->voguePayMerchantId = $this->get_option('voguePayMerchantId'); $this->storeId = $this->get_option('storeId'); //Actions add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); // Payment listener/API hook add_action('woocommerce_api_wc_tbz_voguepay_gateway', array($this, 'check_voguepay_response')); // Check if the gateway can be used if (!$this->is_valid_for_use()) { $this->enabled = false; } }
function add_payment_options() { $defaults = Pay4Pay::get_default_settings(); $tax_class_options = Pay4Pay::instance()->get_woocommerce_tax_classes(); // general $form_fields = array('pay4pay_title' => array('title' => __('Extra Charge', 'woocommerce-payforpayment'), 'type' => 'title', 'class' => 'pay4pay-title', 'description' => ''), 'pay4pay_item_title' => array('title' => __('Item Title', 'woocommerce-payforpayment'), 'type' => 'text', 'description' => __('This will show up in the shopping basket.', 'woocommerce-payforpayment'), 'desc_tip' => true), 'pay4pay_charges_fixed' => array('title' => __('Fixed charge', 'woocommerce-payforpayment'), 'type' => 'number', 'description' => __('Extra charge to be added to cart when this payment method is selected.', 'woocommerce-payforpayment'), 'desc_tip' => true, 'custom_attributes' => array('step' => 'any')), 'pay4pay_charges_percentage' => array('title' => __('Percent charge', 'woocommerce-payforpayment'), 'type' => 'number', 'description' => __('Percentage of cart total to be added to payment.', 'woocommerce-payforpayment'), 'desc_tip' => true, 'custom_attributes' => array('step' => 'any', 'data-setchangehandler' => '1', 'data-reference-name' => 'woocommerce-pay4pay-percentage'), 'id' => 'woocommerce-pay4pay-percentage'), 'pay4pay_charges_minimum' => array('title' => __('Charge at least', 'woocommerce-payforpayment'), 'type' => 'number', 'description' => __('Minimum extra charge to be added to cart when this payment method is selected.', 'woocommerce-payforpayment'), 'desc_tip' => true, 'custom_attributes' => array('step' => 'any', 'data-dependency-notzero' => 'woocommerce-pay4pay-percentage')), 'pay4pay_charges_maximum' => array('title' => __('Charge at most', 'woocommerce-payforpayment'), 'type' => 'number', 'description' => __('Maximum extra charge to be added to cart when this payment method is selected. Enter zero to disable.', 'woocommerce-payforpayment'), 'desc_tip' => true, 'custom_attributes' => array('step' => 'any', 'data-dependency-notzero' => 'woocommerce-pay4pay-percentage')), 'pay4pay_disable_on_free_shipping' => array('title' => __('Disable on Free Shipping', 'woocommerce-payforpayment'), 'label' => __('Don’t charge this fee when free shipping is available.', 'woocommerce-payforpayment'), 'type' => 'checkbox', 'desc_tip' => true)); // taxes if ('yes' == get_option('woocommerce_calc_taxes')) { $form_fields += array('pay4pay_title_taxes' => array('title' => __('Extra Charge Taxes', 'woocommerce-payforpayment'), 'type' => 'title', 'class' => 'pay4pay-title'), 'pay4pay_taxes' => array('title' => __('Taxable', 'woocommerce-payforpayment'), 'type' => 'checkbox', 'label' => __('Payment fee is taxable', 'woocommerce-payforpayment'), 'custom_attributes' => array('data-setchangehandler' => '1', 'data-reference-name' => 'woocommerce-pay4pay-taxes')), 'pay4pay_includes_taxes' => array('title' => __('Inclusive Taxes', 'woocommerce-payforpayment'), 'type' => 'checkbox', 'label' => __('The payment fee is inclusive of taxes.', 'woocommerce-payforpayment'), 'description' => __('If you leave this unchecked taxes will be calculated on top of the payment fee.', 'woocommerce-payforpayment'), 'desc_tip' => true, 'class' => 'pay4pay_taxes', 'custom_attributes' => array('data-dependency-notzero' => 'woocommerce-pay4pay-taxes')), 'pay4pay_tax_class' => array('title' => __('Tax class', 'woocommerce-payforpayment'), 'type' => 'select', 'description' => __('Select a the tax class applied to the extra charge.', 'woocommerce-payforpayment'), 'options' => $tax_class_options, 'desc_tip' => true, 'class' => 'pay4pay_taxes', 'custom_attributes' => array('data-dependency-notzero' => 'woocommerce-pay4pay-taxes'))); } // include in calculation $form_fields += array('pay4pay_title_include' => array('title' => __('Include in percental payment fee calculation:', 'woocommerce-payforpayment'), 'type' => 'title', 'class' => 'pay4pay-title dependency-notzero-woocommerce-pay4pay-percentage', 'custom_attributes' => array('data-dependency-notzero' => 'woocommerce-pay4pay-percentage')), 'pay4pay_enable_extra_fees' => array('title' => __('Fees', 'woocommerce-payforpayment'), 'type' => 'checkbox', 'label' => __('Include fees in calculation.', 'woocommerce-payforpayment'), 'desc_tip' => true, 'class' => 'pay4pay_charges_percentage', 'custom_attributes' => array('data-dependency-notzero' => 'woocommerce-pay4pay-percentage')), 'pay4pay_include_coupons' => array('title' => __('Coupons', 'woocommerce-payforpayment'), 'type' => 'checkbox', 'label' => __('Include Coupons in calculation.', 'woocommerce-payforpayment'), 'desc_tip' => true, 'class' => 'pay4pay_charges_percentage', 'custom_attributes' => array('data-dependency-notzero' => 'woocommerce-pay4pay-percentage')), 'pay4pay_include_shipping' => array('title' => __('Shipping', 'woocommerce-payforpayment'), 'type' => 'checkbox', 'label' => __('Include shipping cost in calculation.', 'woocommerce-payforpayment'), 'desc_tip' => true, 'class' => 'pay4pay_charges_percentage', 'custom_attributes' => array('data-dependency-notzero' => 'woocommerce-pay4pay-percentage'))); if ('yes' == get_option('woocommerce_calc_taxes')) { $form_fields += array('pay4pay_include_cart_taxes' => array('title' => __('Taxes', 'woocommerce-payforpayment'), 'type' => 'checkbox', 'label' => __('Include taxes in calculation.', 'woocommerce-payforpayment'), 'desc_tip' => true, 'class' => 'pay4pay_charges_percentage', 'custom_attributes' => array('data-dependency-notzero' => 'woocommerce-pay4pay-percentage'))); } foreach ($defaults as $option_key => $default_value) { if (array_key_exists($option_key, $form_fields)) { $form_fields[$option_key]['default'] = $default_value; } } foreach (WC()->payment_gateways()->payment_gateways() as $gateway_id => $gateway) { $form_fields['pay4pay_item_title']['default'] = $gateway->title; $gateway->form_fields += $form_fields; add_action('woocommerce_update_options_payment_gateways_' . $gateway->id, array($this, 'update_payment_options'), 20); } }
/** * Gets order total - formatted for display. * * @return string */ public function get_formatted_order_total($tax_display = '', $display_refunded = true) { $formatted_total = wc_price($this->get_total(), array('currency' => $this->get_order_currency())); $order_total = $this->get_total(); $total_refunded = $this->get_total_refunded(); $tax_string = ''; // Tax for inclusive prices if (wc_tax_enabled() && 'incl' == $tax_display) { $tax_string_array = array(); if ('itemized' == get_option('woocommerce_tax_total_display')) { foreach ($this->get_tax_totals() as $code => $tax) { $tax_amount = $total_refunded && $display_refunded ? wc_price(WC_Tax::round($tax->amount - $this->get_total_tax_refunded_by_rate_id($tax->rate_id)), array('currency' => $this->get_order_currency())) : $tax->formatted_amount; $tax_string_array[] = sprintf('%s %s', $tax_amount, $tax->label); } } else { $tax_amount = $total_refunded && $display_refunded ? $this->get_total_tax() - $this->get_total_tax_refunded() : $this->get_total_tax(); $tax_string_array[] = sprintf('%s %s', wc_price($tax_amount, array('currency' => $this->get_order_currency())), WC()->countries->tax_or_vat()); } if (!empty($tax_string_array)) { $tax_string = ' ' . sprintf(__('(Includes %s)', 'woocommerce'), implode(', ', $tax_string_array)); } } if ($total_refunded && $display_refunded) { $formatted_total = '<del>' . strip_tags($formatted_total) . '</del> <ins>' . wc_price($order_total - $total_refunded, array('currency' => $this->get_order_currency())) . $tax_string . '</ins>'; } else { $formatted_total .= $tax_string; } return apply_filters('woocommerce_get_formatted_order_total', $formatted_total, $this); }
/** * Cart Link * Displayed a link to the cart including the number of items present and the cart total * * @since 2.2.6 * * @param array $settings Settings * * @return array Settings */ function odin_cart_link() { if (is_cart()) { $class = 'current-menu-item active'; } else { $class = ''; } ?> <li class="<?php echo esc_attr($class); ?> "> <a class="cart-contents" href="<?php echo esc_url(WC()->cart->get_cart_url()); ?> " title="<?php _e('View your shopping cart', 'odin'); ?> "> <?php echo wp_kses_data(WC()->cart->get_cart_total()); ?> <span class="count"><?php echo wp_kses_data(sprintf(_n('%d item', '%d items', WC()->cart->get_cart_contents_count(), 'odin'), WC()->cart->get_cart_contents_count())); ?> </span> </a> </li> <?php }
/** * Output widget. * * @see WP_Widget * * @param array $args * @param array $instance */ public function widget($args, $instance) { $viewed_products = !empty($_COOKIE['woocommerce_recently_viewed']) ? (array) explode('|', $_COOKIE['woocommerce_recently_viewed']) : array(); $viewed_products = array_reverse(array_filter(array_map('absint', $viewed_products))); if (empty($viewed_products)) { return; } ob_start(); $number = !empty($instance['number']) ? absint($instance['number']) : $this->settings['number']['std']; $query_args = array('posts_per_page' => $number, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'post__in' => $viewed_products, 'orderby' => 'post__in'); $query_args['meta_query'] = array(); $query_args['meta_query'][] = WC()->query->stock_status_meta_query(); $query_args['meta_query'] = array_filter($query_args['meta_query']); $r = new WP_Query($query_args); if ($r->have_posts()) { $this->widget_start($args, $instance); echo apply_filters('woocommerce_before_widget_product_list', '<ul class="product_list_widget">'); while ($r->have_posts()) { $r->the_post(); wc_get_template('content-widget-product.php'); } echo apply_filters('woocommerce_after_widget_product_list', '</ul>'); $this->widget_end($args); } wp_reset_postdata(); $content = ob_get_clean(); echo $content; }