function fflcommerce_shipping_calculator() { if (fflcommerce_shipping::show_shipping_calculator()) { ?> <form class="shipping_calculator" action="<?php echo esc_url(fflcommerce_cart::get_cart_url()); ?> " method="post"> <h2><a href="#" class="shipping-calculator-button"><?php _e('Calculate Shipping', 'fflcommerce'); ?> <span>↓</span></a></h2> <section class="shipping-calculator-form"> <p class="form-row"> <select name="calc_shipping_country" id="calc_shipping_country" class="country_to_state" rel="calc_shipping_state"> <?php foreach (fflcommerce_countries::get_allowed_countries() as $key => $value) { ?> <option value="<?php echo esc_attr($key); ?> " <?php selected(fflcommerce_customer::get_shipping_country(), $key); ?> ><?php echo $value; ?> </option> <?php } ?> </select> </p> <div class="col2-set"> <p class="form-row col-1"> <?php $current_cc = fflcommerce_customer::get_shipping_country(); $current_r = fflcommerce_customer::get_shipping_state(); $states = fflcommerce_countries::$states; if (fflcommerce_countries::country_has_states($current_cc)) { // Dropdown ?> <span> <select name="calc_shipping_state" id="calc_shipping_state"> <option value=""><?php _e('Select a state…', 'fflcommerce'); ?> </option><?php foreach ($states[$current_cc] as $key => $value) { echo '<option value="' . esc_attr($key) . '"'; if ($current_r == $key) { echo 'selected="selected"'; } echo '>' . $value . '</option>'; } ?> </select> </span> <?php } else { // Input ?> <input type="text" class="input-text" value="<?php echo esc_attr($current_r); ?> " placeholder="<?php _e('state', 'fflcommerce'); ?> " name="calc_shipping_state" id="calc_shipping_state" /> <?php } ?> </p> <p class="form-row col-2"> <input type="text" class="input-text" value="<?php echo esc_attr(fflcommerce_customer::get_shipping_postcode()); ?> " placeholder="<?php _e('Postcode/Zip', 'fflcommerce'); ?> " title="<?php _e('Postcode', 'fflcommerce'); ?> " name="calc_shipping_postcode" id="calc_shipping_postcode" /> </p> <?php do_action('fflcommerce_after_shipping_calculator_fields'); ?> </div> <p> <button type="submit" name="calc_shipping" value="1" class="button"><?php _e('Update Totals', 'fflcommerce'); ?> </button> </p> <p> <?php $available_methods = fflcommerce_shipping::get_available_shipping_methods(); foreach ($available_methods as $method) { for ($i = 0; $i < $method->get_rates_amount(); $i++) { ?> <div class="col2-set"> <p class="form-row col-1"> <?php echo '<input type="radio" name="shipping_rates" value="' . esc_attr($method->id . ':' . $i) . '"' . ' class="shipping_select"'; if ($method->get_cheapest_service() == $method->get_selected_service($i) && $method->is_chosen()) { echo ' checked>'; } else { echo '>'; } echo $method->get_selected_service($i); ?> <p class="form-row col-2"><?php if ($method->get_selected_price($i) > 0) { echo fflcommerce_price($method->get_selected_price($i)); echo __(' (ex. tax)', 'fflcommerce'); } else { echo __('Free', 'fflcommerce'); } ?> </div> <?php } } ?> <input type="hidden" name="cart-url" value="<?php echo esc_attr(fflcommerce_cart::get_cart_url()); ?> "> <?php fflcommerce::nonce_field('cart'); ?> </section> </form> <?php } }
<p><?php _e('Your cart is empty.', 'fflcommerce'); ?> </p> <p><a href="<?php echo esc_url(fflcommerce_cart::get_shop_url()); ?> " class="button"><?php _e('← Return to Shop', 'fflcommerce'); ?> </a></p> <?php } else { ?> <form class="form-cart-items" action="<?php echo esc_url(fflcommerce_cart::get_cart_url()); ?> " method="post"> <table class="shop_table cart" cellspacing="0"> <thead> <tr> <th class="product-remove"></th> <th class="product-thumbnail"></th> <th class="product-name"><span class="nobr"><?php _e('Product Name', 'fflcommerce'); ?> </span></th> <th class="product-price"><span class="nobr"><?php _e('Unit Price', 'fflcommerce'); ?> </span></th>
/** * Widget * Display the widget in the sidebar * Save output to the cache if empty * * @param array sidebar arguments * @param array instance */ public function widget($args, $instance) { // Hide widget if page is the cart or checkout if (is_cart() || is_checkout()) { return false; } extract($args); // Set the widget title $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Cart', 'fflcommerce'), $instance, $this->id_base); // Print the widget wrapper & title echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } // Get the contents of the cart $cart_contents = fflcommerce_cart::$cart_contents; // If there are items in the cart print out a list of products if (!empty($cart_contents)) { // Open the list echo '<ul class="cart_list">'; foreach ($cart_contents as $key => $value) { // Get product instance $_product = $value['data']; if ($_product->exists() && $value['quantity'] > 0) { echo '<li>'; // Print the product image & title with a link to the permalink echo '<a href="' . esc_attr(get_permalink($_product->id)) . '" title="' . esc_attr($_product->get_title()) . '">'; // Print the product thumbnail image if exists else display placeholder echo has_post_thumbnail($_product->id) ? get_the_post_thumbnail($_product->id, 'shop_tiny') : fflcommerce_get_image_placeholder('shop_tiny'); // Print the product title echo '<span class="js_widget_product_title">' . $_product->get_title() . '</span>'; echo '</a>'; // Displays variations and cart item meta echo fflcommerce_cart::get_item_data($value); // Print the quantity & price per product echo '<span class="js_widget_product_price">' . $value['quantity'] . ' × ' . $_product->get_price_html() . '</span>'; echo '</li>'; } } echo '</ul>'; // Close the list // Print the cart total echo '<p class="total"><strong>'; echo __('Subtotal', 'fflcommerce'); echo ':</strong> ' . fflcommerce_price($this->total_cart_items()); echo '</p>'; do_action('fflcommerce_widget_cart_before_buttons'); // Print view cart & checkout buttons $view_cart_button_label = isset($instance['view_cart_button']) ? $instance['view_cart_button'] : __('View Cart →', 'fflcommerce'); $checkout_button_label = isset($instance['checkout_button']) ? $instance['checkout_button'] : __('Checkout →', 'fflcommerce'); echo '<p class="buttons">'; echo '<a href="' . esc_attr(fflcommerce_cart::get_cart_url()) . '" class="button">' . __($view_cart_button_label, 'fflcommerce') . '</a>'; echo '<a href="' . esc_attr(fflcommerce_cart::get_checkout_url()) . '" class="button checkout">' . __($checkout_button_label, 'fflcommerce') . '</a>'; echo '</p>'; } else { echo '<span class="empty">' . __('No products in the cart.', 'fflcommerce') . '</span>'; } // Print closing widget wrapper echo $after_widget; }
function fflcommerce_cancel_order() { if (isset($_GET['cancel_order']) && isset($_GET['order']) && isset($_GET['order_id'])) { $order_key = urldecode($_GET['order']); $order_id = (int) $_GET['order_id']; $order = new fflcommerce_order($order_id); if ($order->id == $order_id && $order->order_key == $order_key && $order->status == 'pending' && fflcommerce::verify_nonce('cancel_order')) { // Cancel the order + restore stock $order->cancel_order(__('Order cancelled by customer.', 'fflcommerce')); // Message fflcommerce::add_message(__('Your order was cancelled.', 'fflcommerce')); } elseif ($order->status != 'pending') { fflcommerce::add_error(__('Your order is no longer pending and could not be cancelled. Please contact us if you need assistance.', 'fflcommerce')); } else { fflcommerce::add_error(__('Invalid order.', 'fflcommerce')); } wp_safe_redirect(fflcommerce_cart::get_cart_url()); exit; } }