public static function check_remove_coupon() { if (!empty($_GET['unset_coupon'])) { self::remove_coupon($_GET['unset_coupon']); fflcommerce_session::instance()->chosen_shipping_method_id = null; fflcommerce_cart::calculate_totals(); } }
/** * Process the payment and return the result **/ function process_payment($order_id) { $order = new fflcommerce_order($order_id); $status = FFLCommerce_Base::get_options()->get('fflcommerce_cod_status', 'processing'); $order->update_status($status, __('Waiting for cash delivery.', 'fflcommerce')); // Remove cart fflcommerce_cart::empty_cart(); // Return thankyou redirect $checkout_redirect = apply_filters('fflcommerce_get_checkout_redirect_page_id', fflcommerce_get_page_id('thanks')); return array('result' => 'success', 'redirect' => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink($checkout_redirect)))); }
/** * Process the payment and return the result **/ function process_payment($order_id) { $order = new fflcommerce_order($order_id); // Mark as on-hold (we're awaiting the cheque) $order->update_status('waiting-for-payment', __('Awaiting cheque payment', 'fflcommerce')); // Remove cart fflcommerce_cart::empty_cart(); // Return thankyou redirect $checkout_redirect = apply_filters('fflcommerce_get_checkout_redirect_page_id', fflcommerce_get_page_id('thanks')); return array('result' => 'success', 'redirect' => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink($checkout_redirect)))); }
function fflcommerce_cart($atts) { unset(fflcommerce_session::instance()->selected_rate_id); // Process Discount Codes if (isset($_POST['apply_coupon']) && $_POST['apply_coupon'] && fflcommerce::verify_nonce('cart')) { $coupon_code = sanitize_title($_POST['coupon_code']); fflcommerce_cart::add_discount($coupon_code); } elseif (isset($_POST['calc_shipping']) && $_POST['calc_shipping'] && fflcommerce::verify_nonce('cart')) { // Update Shipping unset(fflcommerce_session::instance()->chosen_shipping_method_id); $country = $_POST['calc_shipping_country']; $state = $_POST['calc_shipping_state']; $postcode = $_POST['calc_shipping_postcode']; if ($postcode && !fflcommerce_validation::is_postcode($postcode, $country)) { fflcommerce::add_error(__('Please enter a valid postcode/ZIP.', 'fflcommerce')); $postcode = ''; } elseif ($postcode) { $postcode = fflcommerce_validation::format_postcode($postcode, $country); } if ($country) { // Update customer location fflcommerce_customer::set_location($country, $state, $postcode); fflcommerce_customer::set_shipping_location($country, $state, $postcode); fflcommerce::add_message(__('Shipping costs updated.', 'fflcommerce')); } else { fflcommerce_customer::set_shipping_location('', '', ''); fflcommerce::add_message(__('Shipping costs updated.', 'fflcommerce')); } } elseif (isset($_POST['shipping_rates'])) { $rates_params = explode(":", $_POST['shipping_rates']); $available_methods = fflcommerce_shipping::get_available_shipping_methods(); $shipping_method = $available_methods[$rates_params[0]]; if ($rates_params[1] != null) { fflcommerce_session::instance()->selected_rate_id = $rates_params[1]; } $shipping_method->choose(); // chooses the method selected by user. } // Re-Calc prices. This needs to happen every time the cart page is loaded and after checking post results. fflcommerce_cart::calculate_totals(); $result = fflcommerce_cart::check_cart_item_stock(); if (is_wp_error($result)) { fflcommerce::add_error($result->get_error_message()); } fflcommerce_render('shortcode/cart', array('cart' => fflcommerce_cart::get_cart(), 'coupons' => fflcommerce_cart::get_coupons())); }
function fflcommerce_process_checkout() { if (!is_checkout() || is_fflcommerce_single_page(FFLCOMMERCE_PAY)) { return; } if (count(fflcommerce_cart::get_cart()) == 0) { wp_safe_redirect(get_permalink(fflcommerce_get_page_id('cart'))); exit; } /** @var fflcommerce_checkout $_checkout */ $_checkout = fflcommerce_checkout::instance(); $result = $_checkout->process_checkout(); if (isset($result['result']) && $result['result'] === 'success') { wp_safe_redirect(apply_filters('fflcommerce_is_ajax_payment_successful', $result['redirect'])); exit; } if (isset($result['redirect'])) { wp_safe_redirect(get_permalink($result['redirect'])); exit; } }
public static function get_available_shipping_methods() { $_available_methods = array(); if (self::$enabled == 'yes') { foreach (self::get_all_methods() as $method) { /** @var $method fflcommerce_shipping_method */ if (fflcommerce_cart::has_free_shipping_coupon() && $method->id == 'free_shipping') { $_available_methods[$method->id] = $method; } if ($method->is_available() && $method->cost >= 0) { $_available_methods[$method->id] = $method; } } } //throw error if there are no shipping methods if (empty($_available_methods)) { self::$shipping_error_message = __('Please enter your shipping destination and postal code to view shipping options and rates.', 'fflcommerce'); if (self::get_options()->get('fflcommerce_enable_shipping_calc') == 'no' && is_cart()) { self::$shipping_error_message .= __(' If the Shipping Calculator is not available here, you will need to advance to the Checkout to do this.', 'fflcommerce'); } self::$shipping_error_message .= __(' There may be no methods available for your destination and you should contact us for assistance.', 'fflcommerce'); } return apply_filters('fflcommerce_available_shipping_methods', $_available_methods); }
/** * provides functionality to tell checkout if * the gateway should be processed or not. If false, the gateway will not be * processed, otherwise the gateway will be processed. * * @param $subtotal * @param $shipping_total * @param int $discount * @return boolean defaults to needs_payment from cart class. If overridden, the gateway will provide * details as to when it should or shouldn't be processed. * @since 1.2 */ public function process_gateway($subtotal, $shipping_total, $discount = 0) { // default to cart needs_payment() to keep the same functionality that FFL Commerce offers today // if overridden, the gateway will provide the details when to skip or not return fflcommerce_cart::needs_payment(); }
/** * Outputs the thankyou page **/ function fflcommerce_thankyou() { $thankyou_message = __('<p>Thank you. Your order has been processed successfully.</p>', 'fflcommerce'); echo apply_filters('fflcommerce_thankyou_message', $thankyou_message); // Pay for order after checkout step if (isset($_GET['order'])) { $order_id = $_GET['order']; } else { $order_id = 0; } if (isset($_GET['key'])) { $order_key = $_GET['key']; } else { $order_key = ''; } if ($order_id > 0) { $order = new fflcommerce_order($order_id); if ($order->order_key == $order_key) { ?> <?php do_action('fflcommerce_thankyou_before_order_details', $order->id); ?> <ul class="order_details"> <li class="order"> <?php _e('Order:', 'fflcommerce'); ?> <strong><?php echo $order->get_order_number(); ?> </strong> </li> <li class="date"> <?php _e('Date:', 'fflcommerce'); ?> <strong><?php echo date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($order->order_date)); ?> </strong> </li> <li class="total"> <?php _e('Total:', 'fflcommerce'); ?> <strong><?php echo fflcommerce_price($order->order_total); ?> </strong> </li> <li class="method"> <?php _e('Payment method:', 'fflcommerce'); ?> <strong><?php $gateways = fflcommerce_payment_gateways::payment_gateways(); if (isset($gateways[$order->payment_method])) { echo $gateways[$order->payment_method]->title; } else { echo $order->payment_method; } ?> </strong> </li> </ul> <div class="clear"></div> <?php do_action('thankyou_' . $order->payment_method, $order_id); do_action('fflcommerce_thankyou', $order->id); } } echo '<p><a class="button" href="' . esc_url(fflcommerce_cart::get_shop_url()) . '">' . __('← Continue Shopping', 'fflcommerce') . '</a></p>'; }
/** * Validate the checkout */ public function validate_checkout() { if (fflcommerce_cart::is_empty()) { fflcommerce::add_error(sprintf(__('Sorry, your session has expired. <a href="%s">Return to homepage →</a>', 'fflcommerce'), home_url())); } // Process Discount Codes if (!empty($_POST['coupon_code'])) { $coupon = sanitize_title($_POST['coupon_code']); fflcommerce_cart::add_discount($coupon); } foreach (fflcommerce_cart::get_coupons() as $coupon) { fflcommerce_cart::is_valid_coupon($coupon); } // Checkout fields $this->posted['shipping_method'] = ''; $this->posted['shipping_service'] = ''; if (isset($_POST['shipping_method'])) { $shipping_method = fflcommerce_clean($_POST['shipping_method']); $shipping_data = explode(':', $shipping_method); $this->posted['shipping_method'] = $shipping_data[0]; $this->posted['shipping_service'] = $shipping_data[1]; } $this->posted['shiptobilling'] = isset($_POST['shiptobilling']) ? fflcommerce_clean($_POST['shiptobilling']) : ''; $this->posted['payment_method'] = isset($_POST['payment_method']) ? fflcommerce_clean($_POST['payment_method']) : ''; $this->posted['order_comments'] = isset($_POST['order_comments']) ? fflcommerce_clean($_POST['order_comments']) : ''; $this->posted['terms'] = isset($_POST['terms']) ? fflcommerce_clean($_POST['terms']) : ''; $this->posted['create_account'] = isset($_POST['create_account']) ? fflcommerce_clean($_POST['create_account']) : ''; $this->posted['account_username'] = isset($_POST['account_username']) ? fflcommerce_clean($_POST['account_username']) : ''; $this->posted['account_password'] = isset($_POST['account_password']) ? fflcommerce_clean($_POST['account_password']) : ''; $this->posted['account_password_2'] = isset($_POST['account_password_2']) ? fflcommerce_clean($_POST['account_password_2']) : ''; if (fflcommerce_cart::get_total(false) == 0) { $this->posted['payment_method'] = 'no_payment'; } // establish customer billing and shipping locations if (fflcommerce_cart::ship_to_billing_address_only()) { $this->posted['shiptobilling'] = 'true'; } $country = isset($_POST['billing_country']) ? fflcommerce_clean($_POST['billing_country']) : ''; $state = isset($_POST['billing_state']) ? fflcommerce_clean($_POST['billing_state']) : ''; $allowed_countries = FFLCommerce_Base::get_options()->get('fflcommerce_allowed_countries'); if ($allowed_countries === 'specific') { $specific_countries = FFLCommerce_Base::get_options()->get('fflcommerce_specific_allowed_countries'); if (!in_array($country, $specific_countries)) { fflcommerce::add_error(__('Invalid billing country.', 'fflcommerce')); return; } } if (fflcommerce_countries::country_has_states($country)) { $states = fflcommerce_countries::get_states($country); if (!in_array($state, array_keys($states))) { fflcommerce::add_error(__('Invalid billing state.', 'fflcommerce')); return; } } $postcode = isset($_POST['billing_postcode']) ? fflcommerce_clean($_POST['billing_postcode']) : ''; $ship_to_billing = FFLCommerce_Base::get_options()->get('fflcommerce_ship_to_billing_address_only') == 'yes'; fflcommerce_customer::set_location($country, $state, $postcode); if (FFLCommerce_Base::get_options()->get('fflcommerce_calc_shipping') == 'yes') { if ($ship_to_billing || !empty($_POST['shiptobilling'])) { fflcommerce_customer::set_shipping_location($country, $state, $postcode); } else { $country = isset($_POST['shipping_country']) ? fflcommerce_clean($_POST['shipping_country']) : ''; $state = isset($_POST['shipping_state']) ? fflcommerce_clean($_POST['shipping_state']) : ''; $postcode = isset($_POST['shipping_postcode']) ? fflcommerce_clean($_POST['shipping_postcode']) : ''; if ($allowed_countries === 'specific') { $specific_countries = FFLCommerce_Base::get_options()->get('fflcommerce_specific_allowed_countries'); if (!in_array($country, $specific_countries)) { fflcommerce::add_error(__('Invalid shipping country.', 'fflcommerce')); return; } } if (fflcommerce_countries::country_has_states($country)) { $states = fflcommerce_countries::get_states($country); if (!in_array($state, array_keys($states))) { fflcommerce::add_error(__('Invalid shipping state.', 'fflcommerce')); return; } } fflcommerce_customer::set_shipping_location($country, $state, $postcode); } } // Billing Information foreach ($this->billing_fields as $field) { $field = apply_filters('fflcommerce_billing_field', $field); $this->posted[$field['name']] = isset($_POST[$field['name']]) ? fflcommerce_clean($_POST[$field['name']]) : ''; // Format if (isset($field['format'])) { switch ($field['format']) { case 'postcode': $this->posted[$field['name']] = strtolower(str_replace(' ', '', $this->posted[$field['name']])); break; } } // Required if ($field['name'] == 'billing_state' && fflcommerce_customer::has_valid_shipping_state()) { $field['required'] = false; } if (isset($field['required']) && $field['required'] && empty($this->posted[$field['name']])) { fflcommerce::add_error($field['label'] . __(' (billing) is a required field.', 'fflcommerce')); } if ($field['name'] == 'billing_euvatno') { $vatno = isset($this->posted['billing_euvatno']) ? $this->posted['billing_euvatno'] : ''; $vatno = str_replace(' ', '', $vatno); $country = fflcommerce_tax::get_customer_country(); // strip any country code from the beginning of the number if (strpos($vatno, $country) === 0) { $vatno = substr($vatno, strlen($country)); } if ($vatno != '') { $url = 'http://isvat.appspot.com/' . $country . '/' . $vatno . '/'; $httpRequest = curl_init(); curl_setopt($httpRequest, CURLOPT_FAILONERROR, true); curl_setopt($httpRequest, CURLOPT_RETURNTRANSFER, true); curl_setopt($httpRequest, CURLOPT_HEADER, false); curl_setopt($httpRequest, CURLOPT_URL, $url); $result = curl_exec($httpRequest); curl_close($httpRequest); if ($result === 'false') { fflcommerce_log('EU VAT validation error with URL: ' . $url); fflcommerce::add_error($field['label'] . __(' (billing) is not a valid VAT Number. Leave it blank to disable VAT validation. (VAT may be charged depending on your location)', 'fflcommerce')); } else { $this->valid_euvatno = fflcommerce_countries::get_base_country() != fflcommerce_tax::get_customer_country() && fflcommerce_countries::is_eu_country(fflcommerce_tax::get_customer_country()); } } } // Validation if (isset($field['validate']) && !empty($this->posted[$field['name']])) { switch ($field['validate']) { case 'phone': if (!fflcommerce_validation::is_phone($this->posted[$field['name']])) { fflcommerce::add_error($field['label'] . __(' (billing) is not a valid number.', 'fflcommerce')); } break; case 'email': if (!fflcommerce_validation::is_email($this->posted[$field['name']])) { fflcommerce::add_error($field['label'] . __(' (billing) is not a valid email address.', 'fflcommerce')); } break; case 'postcode': if (!fflcommerce_validation::is_postcode($this->posted[$field['name']], $_POST['billing_country'])) { fflcommerce::add_error($field['label'] . __(' (billing) is not a valid postcode/ZIP.', 'fflcommerce')); } else { $this->posted[$field['name']] = fflcommerce_validation::format_postcode($this->posted[$field['name']], $_POST['billing_country']); } break; } } } // Shipping Information if (fflcommerce_shipping::is_enabled() && !fflcommerce_cart::ship_to_billing_address_only() && empty($this->posted['shiptobilling'])) { foreach ($this->shipping_fields as $field) { $field = apply_filters('fflcommerce_shipping_field', $field); if (isset($_POST[$field['name']])) { $this->posted[$field['name']] = fflcommerce_clean($_POST[$field['name']]); } else { $this->posted[$field['name']] = ''; } // Format if (isset($field['format'])) { switch ($field['format']) { case 'postcode': $this->posted[$field['name']] = strtolower(str_replace(' ', '', $this->posted[$field['name']])); break; } } // Required if ($field['name'] == 'shipping_state' && fflcommerce_customer::has_valid_shipping_state()) { $field['required'] = false; } if (isset($field['required']) && $field['required'] && empty($this->posted[$field['name']])) { fflcommerce::add_error($field['label'] . __(' (shipping) is a required field.', 'fflcommerce')); } // Validation if (isset($field['validate']) && !empty($this->posted[$field['name']])) { switch ($field['validate']) { case 'postcode': if (!fflcommerce_validation::is_postcode($this->posted[$field['name']], $country)) { fflcommerce::add_error($field['label'] . __(' (shipping) is not a valid postcode/ZIP.', 'fflcommerce')); } else { $this->posted[$field['name']] = fflcommerce_validation::format_postcode($this->posted[$field['name']], $country); } break; } } } } if ($this->must_register && empty($this->posted['create_account'])) { fflcommerce::add_error(__('Sorry, you must agree to creating an account', 'fflcommerce')); } if ($this->must_register || empty($user_id) && $this->posted['create_account']) { if (!$this->show_signup) { fflcommerce::add_error(__('Sorry, the shop owner has disabled guest purchases.', 'fflcommerce')); } if (empty($this->posted['account_username'])) { fflcommerce::add_error(__('Please enter an account username.', 'fflcommerce')); } if (empty($this->posted['account_password'])) { fflcommerce::add_error(__('Please enter an account password.', 'fflcommerce')); } if ($this->posted['account_password_2'] !== $this->posted['account_password']) { fflcommerce::add_error(__('Passwords do not match.', 'fflcommerce')); } // Check the username if (!validate_username($this->posted['account_username'])) { fflcommerce::add_error(__('Invalid email/username.', 'fflcommerce')); } elseif (username_exists($this->posted['account_username'])) { fflcommerce::add_error(__('An account is already registered with that username. Please choose another.', 'fflcommerce')); } // Check the e-mail address if (email_exists($this->posted['billing_email'])) { fflcommerce::add_error(__('An account is already registered with your email address. Please login.', 'fflcommerce')); } } // Terms if (!isset($_POST['update_totals']) && empty($this->posted['terms']) && fflcommerce_get_page_id('terms') > 0) { fflcommerce::add_error(__('You must accept our Terms & Conditions.', 'fflcommerce')); } if (fflcommerce_cart::needs_shipping()) { // Shipping Method $available_methods = fflcommerce_shipping::get_available_shipping_methods(); if (!isset($available_methods[$this->posted['shipping_method']])) { fflcommerce::add_error(__('Invalid shipping method.', 'fflcommerce')); } } }
/** * Applies a coupon code * * @param string $coupon_code The code to apply * @return bool True if the coupon is applied, false if it does not exist or cannot be applied */ public static function add_discount($coupon_code) { if (!self::is_valid_coupon($coupon_code)) { return false; } // Check for other individual_use coupons before adding this coupon. foreach (self::get_coupons() as $code) { $current = JS_Coupons::get_coupon($code); if ($current['individual_use']) { fflcommerce::add_error(__("There is already an 'individual use' coupon on the Cart. No other coupons can be added until it is removed.", 'fflcommerce')); return false; } } $coupon = JS_Coupons::get_coupon($coupon_code); // Remove other coupons if this one is individual_use. if ($coupon['individual_use']) { if (!empty(self::$applied_coupons)) { fflcommerce::add_error(__("This is an 'individual use' coupon. All other discount coupons have been removed.", 'fflcommerce')); self::$applied_coupons = array(); } } // check if coupon is already applied and only add a new coupon if (!self::has_discount($coupon_code) && !empty($_POST['coupon_code'])) { self::$applied_coupons[] = $coupon_code; } fflcommerce_session::instance()->coupons = self::$applied_coupons; fflcommerce::add_message(__('Discount coupon applied successfully.', 'fflcommerce')); return true; }
/** * Process the payment and return the result **/ function process_payment($order_id) { $order = new fflcommerce_order($order_id); $order->update_status('waiting-for-payment', __('Awaiting Bank Transfer', 'fflcommerce')); fflcommerce_cart::empty_cart(); $checkout_redirect = apply_filters('fflcommerce_get_checkout_redirect_page_id', fflcommerce_get_page_id('thanks')); return array('result' => 'success', 'redirect' => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink($checkout_redirect)))); }
function fflcommerce_ajax_update_item_quantity() { /** @var fflcommerce_cart $cart */ $cart = fflcommerce_cart::instance(); $cart->set_quantity($_POST['item'], (int) $_POST['qty']); $items = $cart->get_cart(); $price = -1; if (isset($items[$_POST['item']])) { $item = $items[$_POST['item']]; /** @var fflcommerce_product $product */ $product = $item['data']; $price = apply_filters('fflcommerce_product_subtotal_display_in_cart', fflcommerce_price($product->get_defined_price() * $item['quantity']), $item['product_id'], $item); } if (fflcommerce_cart::show_retail_price()) { $subtotal = fflcommerce_cart::get_cart_subtotal(true, false, true); } else { if (fflcommerce_cart::show_retail_price() && FFLCommerce_Base::get_options()->get('fflcommerce_prices_include_tax') == 'no') { $subtotal = fflcommerce_cart::get_cart_subtotal(true, true); } else { $subtotal = fflcommerce_cart::$cart_contents_total_ex_tax + fflcommerce_cart::$shipping_total; $subtotal = fflcommerce_price($subtotal, array('ex_tax_label' => 1)); } } $tax = array(); foreach (fflcommerce_cart::get_applied_tax_classes() as $tax_class) { if (fflcommerce_cart::get_tax_for_display($tax_class)) { $tax[$tax_class] = fflcommerce_cart::get_tax_amount($tax_class); } } $shipping = fflcommerce_cart::get_cart_shipping_total(true, true) . '<small>' . fflcommerce_cart::get_cart_shipping_title() . '</small>'; $discount = '-' . fflcommerce_cart::get_total_discount(); $total = fflcommerce_cart::get_total(); echo json_encode(array('success' => true, 'item_price' => $price, 'subtotal' => $subtotal, 'shipping' => $shipping, 'discount' => $discount, 'tax' => $tax, 'total' => $total)); exit; }
function fflcommerce_init() { // Override default translations with custom .mo's found in wp-content/languages/fflcommerce first. load_textdomain('fflcommerce', WP_LANG_DIR . '/fflcommerce/fflcommerce-' . get_locale() . '.mo'); load_plugin_textdomain('fflcommerce', false, dirname(plugin_basename(__FILE__)) . '/languages/'); add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'fflcommerce_admin_bar_links'); // instantiate options -after- loading text domains $options = FFLCommerce_Base::get_options(); fflcommerce_post_type(); // register taxonomies new fflcommerce_cron(); // -after- text domains and Options instantiation allows settings translations fflcommerce_set_image_sizes(); // called -after- our Options are loaded // add Singletons here so that the taxonomies are loaded before calling them. fflcommerce_session::instance(); // Start sessions if they aren't already fflcommerce::instance(); // Utility functions, uses sessions fflcommerce_customer::instance(); // Customer class, sorts session data such as location // FFL Commerce will instantiate gateways and shipping methods on this same 'init' action hook // with a very low priority to ensure text domains are loaded first prior to installing any external options fflcommerce_shipping::instance(); // Shipping class. loads shipping methods fflcommerce_payment_gateways::instance(); // Payment gateways class. loads payment methods fflcommerce_cart::instance(); // Cart class, uses sessions add_filter('mce_external_plugins', 'fflcommerce_register_shortcode_editor'); add_filter('mce_buttons', 'fflcommerce_register_shortcode_buttons'); if (!is_admin()) { /* Catalog Filters */ add_filter('loop-shop-query', create_function('', 'return array("orderby" => "' . $options->get('fflcommerce_catalog_sort_orderby') . '","order" => "' . $options->get('fflcommerce_catalog_sort_direction') . '");')); add_filter('loop_shop_columns', create_function('', 'return ' . $options->get('fflcommerce_catalog_columns') . ';')); add_filter('loop_shop_per_page', create_function('', 'return ' . $options->get('fflcommerce_catalog_per_page') . ';')); fflcommerce_catalog_query::instance(); // front end queries class fflcommerce_request_api::instance(); // front end request api for URL's } fflcommerce_roles_init(); do_action('fflcommerce_initialize_plugins'); }
</td> <td> <?php echo fflcommerce_price($product->get_defined_price() * $values['quantity'], array('ex_tax_label' => Jigoshop_Base::get_options()->get('fflcommerce_show_prices_with_tax') == 'yes' ? 2 : 1)); ?> </td> </tr> <?php } } ?> </tbody> </table> <?php $coupons = fflcommerce_cart::get_coupons(); ?> <table> <tr> <td colspan="6" class="actions"> <?php if (JS_Coupons::has_coupons()) { ?> <div class="coupon"> <label for="coupon_code"><?php _e('Coupon', 'fflcommerce'); ?> :</label> <input type="text" name="coupon_code" class="input-text" id="coupon_code" value="" /> <input type="submit" class="button" name="apply_coupon" value="<?php _e('Apply Coupon', 'fflcommerce'); ?>
public function calculate_shipping() { $this->shipping_total = $this->get_fee($this->fee, fflcommerce_cart::get_total(false)); $this->shipping_tax = 0; $this->shipping_label = $this->title; }
/** * 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; }
</th> <td class="cart-row-discount">-<?php echo fflcommerce_cart::get_total_discount(); ?> </td> </tr> <?php } ?> <tr> <th class="cart-row-total-title"><strong><?php _e('Total', 'fflcommerce'); ?> </strong></th> <td class="cart-row-total"><strong><?php echo fflcommerce_cart::get_total(); ?> </strong></td> </tr> </tbody> </table> </div> <?php do_action('fflcommerce_after_cart_totals'); } else { echo '<p>' . __(fflcommerce_shipping::get_shipping_error_message(), 'fflcommerce') . '</p>'; } ?> </div> <?php do_action('fflcommerce_before_shipping_calculator');
function fflcommerce_breadcrumb($delimiter = ' › ', $wrap_before = '<div id="breadcrumb">', $wrap_after = '</div>', $before = '', $after = '', $home = null) { global $post, $wp_query, $author; $options = FFLCommerce_Base::get_options(); if (!$home) { $home = _x('Home', 'breadcrumb', 'fflcommerce'); } $home_link = home_url(); $prepend = ''; if ($options->get('fflcommerce_prepend_shop_page_to_urls') == "yes" && fflcommerce_get_page_id('shop') && get_option('page_on_front') !== fflcommerce_get_page_id('shop')) { $prepend = $before . '<a href="' . esc_url(fflcommerce_cart::get_shop_url()) . '">' . get_the_title(fflcommerce_get_page_id('shop')) . '</a> ' . $after . $delimiter; } if (!is_home() && !is_front_page() && !(is_post_type_archive() && get_option('page_on_front') == fflcommerce_get_page_id('shop')) || is_paged()) { echo $wrap_before; echo $before . '<a class="home" href="' . $home_link . '">' . $home . '</a> ' . $after . $delimiter; if (is_category()) { $cat_obj = $wp_query->get_queried_object(); $this_category = $cat_obj->term_id; $this_category = get_category($this_category); if ($this_category->parent != 0) { $parent_category = get_category($this_category->parent); echo get_category_parents($parent_category->term_id, true, $delimiter); } echo $before . single_cat_title('', false) . $after; } elseif (is_tax('product_cat')) { $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy')); $parents = array(); $parent = $term->parent; while ($parent) { $parents[] = $parent; $new_parent = get_term_by('id', $parent, get_query_var('taxonomy')); $parent = $new_parent->parent; } if (!empty($parents)) { $parents = array_reverse($parents); foreach ($parents as $parent) { $item = get_term_by('id', $parent, get_query_var('taxonomy')); echo $before . '<a href="' . get_term_link($item->slug, 'product_cat') . '">' . $item->name . '</a>' . $after . $delimiter; } } $queried_object = $wp_query->get_queried_object(); echo $prepend . $before . $queried_object->name . $after; } elseif (is_tax('product_tag')) { $queried_object = $wp_query->get_queried_object(); echo $prepend . $before . __('Products tagged “', 'fflcommerce') . $queried_object->name . '”' . $after; } elseif (is_day()) { echo $before . '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $after . $delimiter; echo $before . '<a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '">' . get_the_time('F') . '</a>' . $after . $delimiter; echo $before . get_the_time('d') . $after; } elseif (is_month()) { echo $before . '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $after . $delimiter; echo $before . get_the_time('F') . $after; } elseif (is_year()) { echo $before . get_the_time('Y') . $after; } elseif (is_post_type_archive('product') && get_option('page_on_front') !== fflcommerce_get_page_id('shop')) { $_name = fflcommerce_get_page_id('shop') ? get_the_title(fflcommerce_get_page_id('shop')) : ucwords($options->get('fflcommerce_shop_slug')); if (is_search()) { echo $before . '<a href="' . get_post_type_archive_link('product') . '">' . $_name . '</a>' . $delimiter . __('Search results for “', 'fflcommerce') . get_search_query() . '”' . $after; } else { echo $before . '<a href="' . get_post_type_archive_link('product') . '">' . $_name . '</a>' . $after; } } elseif (is_single() && !is_attachment()) { if (get_post_type() == 'product') { echo $prepend; if ($terms = get_the_terms($post->ID, 'product_cat')) { $term = apply_filters('fflcommerce_product_cat_breadcrumb_terms', current($terms), $terms); $parents = array(); $parent = $term->parent; while ($parent) { $parents[] = $parent; $new_parent = get_term_by('id', $parent, 'product_cat'); $parent = $new_parent->parent; } if (!empty($parents)) { $parents = array_reverse($parents); foreach ($parents as $parent) { $item = get_term_by('id', $parent, 'product_cat'); echo $before . '<a href="' . get_term_link($item->slug, 'product_cat') . '">' . $item->name . '</a>' . $after . $delimiter; } } echo $before . '<a href="' . get_term_link($term->slug, 'product_cat') . '">' . $term->name . '</a>' . $after . $delimiter; } echo $before . get_the_title() . $after; } elseif (get_post_type() != 'post') { $post_type = get_post_type_object(get_post_type()); echo $before . '<a href="' . get_post_type_archive_link(get_post_type()) . '">' . $post_type->labels->singular_name . '</a>' . $after . $delimiter; echo $before . get_the_title() . $after; } else { $cat = current(get_the_category()); echo get_category_parents($cat, true, $delimiter); echo $before . get_the_title() . $after; } } elseif (is_404()) { echo $before . __('Error 404', 'fflcommerce') . $after; } elseif (!is_single() && !is_page() && get_post_type() != 'post') { $post_type = get_post_type_object(get_post_type()); if ($post_type) { echo $before . $post_type->labels->singular_name . $after; } } elseif (is_attachment()) { $parent = get_post($post->post_parent); $cat = get_the_category($parent->ID); $cat = $cat[0]; echo get_category_parents($cat, true, '' . $delimiter); echo $before . '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a>' . $after . $delimiter; echo $before . get_the_title() . $after; } elseif (is_page() && !$post->post_parent) { echo $before . get_the_title() . $after; } elseif (is_page() && $post->post_parent) { $parent_id = $post->post_parent; $breadcrumbs = array(); while ($parent_id) { $page = get_post($parent_id); $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>'; $parent_id = $page->post_parent; } $breadcrumbs = array_reverse($breadcrumbs); foreach ($breadcrumbs as $crumb) { echo $crumb . '' . $delimiter; } echo $before . get_the_title() . $after; } elseif (is_search()) { echo $before . __('Search results for “', 'fflcommerce') . get_search_query() . '”' . $after; } elseif (is_tag()) { echo $before . __('Posts tagged “', 'fflcommerce') . single_tag_title('', false) . '”' . $after; } elseif (is_author()) { $userdata = get_userdata($author); echo $before . __('Author: ', 'fflcommerce') . $userdata->display_name . $after; } if (get_query_var('paged')) { echo ' (' . __('Page', 'fflcommerce') . ' ' . get_query_var('paged') . ')'; } echo $wrap_after; } }
* versions in the future. If you wish to customise FFL Commerce core for your needs, * please use our GitHub repository to publish essential changes for consideration. * * @package FFLCommerce * @category Checkout * @author Tampa Bay Tactical Supply, Inc. * @copyright Copyright © 2011-2014 Tampa Bay Tactical Supply, Inc. & Jigoshop. * @license GNU General Public License v3 * */ ?> <?php do_action('before_checkout_form'); // filter hook for include new pages inside the payment method $get_checkout_url = apply_filters('fflcommerce_get_checkout_url', fflcommerce_cart::get_checkout_url()); ?> <form name="checkout" method="post" class="checkout" action="<?php echo esc_url($get_checkout_url); ?> "> <h3 id="order_review_heading"><?php _e('Your Order', 'fflcommerce'); ?> </h3> <?php do_action('fflcommerce_checkout_order_review'); ?>