Esempio n. 1
0
 /**
  * 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)
 {
     extract($args);
     // Print the widget wrapper
     echo $before_widget;
     if (is_user_logged_in()) {
         // Get current user instance
         global $current_user;
         // Print title
         $title = $instance['title_user'] ? $instance['title_user'] : __('Hey %s!', 'fflcommerce');
         if ($title) {
             echo $before_title . sprintf($title, ucwords($current_user->display_name)) . $after_title;
         }
         // Create the default set of links
         $links = apply_filters('fflcommerce_widget_logout_user_links', array(__('My Account', 'fflcommerce') => get_permalink(fflcommerce_get_page_id('myaccount')), __('Change Password', 'fflcommerce') => get_permalink(fflcommerce_get_page_id('change_password')), __('Logout', 'fflcommerce') => wp_logout_url(home_url())));
     } else {
         // Print title
         $title = $instance['title_guest'] ? $instance['title_guest'] : __('Login', 'fflcommerce');
         if ($title) {
             echo $before_title . $title . $after_title;
         }
         do_action('fflcommerce_widget_login_before_form');
         // Get redirect URI
         $redirect_to = apply_filters('fflcommerce_widget_login_redirect', get_permalink(fflcommerce_get_page_id('myaccount')));
         $fields = array();
         // Support for other plugins which uses GET parameters
         $fields = apply_filters('fflcommerce_get_hidden_fields', $fields);
         echo "<form action='" . esc_url(wp_login_url($redirect_to)) . "' method='post' class='fflcommerce_login_widget'>";
         foreach ($fields as $key => $value) {
             echo '<input type="hidden" name="' . $key . '" value="' . $value . '" />';
         }
         // Username
         echo "\n\t\t\t<p>\n\t\t\t\t<label for='log'>" . __('Username', 'fflcommerce') . "</label>\n\t\t\t\t<input type='text' name='log' id='log' class='input-text username' />\n\t\t\t</p>\n\t\t\t";
         // Password
         echo "\n\t\t\t<p>\n\t\t\t\t<label for='pwd'>" . __('Password', 'fflcommerce') . "</label>\n\t\t\t\t<input type='password' name='pwd' id='pwd' class='input-text password' />\n\t\t\t</p>\n\t\t\t";
         echo "\n\t\t\t<p>\n\t\t\t\t<input type='submit' name='submit' value='" . __('Login', 'fflcommerce') . "' class='input-submit' />\n\t\t\t\t<a class='forgot' href='" . esc_url(wp_lostpassword_url($redirect_to)) . "'>" . __('Forgot it?', 'fflcommerce') . "</a>\n\t\t\t</p>\n\t\t\t";
         if (FFLCommerce_Base::get_options()->get('fflcommerce_enable_signup_form') == 'yes') {
             echo '<p class="register">';
             wp_register(__('New user?', 'fflcommerce') . ' ', '');
             echo '</p>';
         }
         echo "</form>";
         do_action('fflcommerce_widget_login_after_form');
         $links = apply_filters('fflcommerce_widget_login_user_links', array());
     }
     // Loop & print out the links
     if ($links) {
         echo "\n\t\t\t<nav role='navigation'>\n\t\t\t\t<ul class='pagenav'>";
         foreach ($links as $title => $href) {
             $href = esc_url($href);
             echo "<li><a title='Go to {$title}' href='{$href}'>{$title}</a></li>";
         }
         echo "\n\t\t\t\t</ul>\n\t\t\t</nav>";
     }
     // Print closing widget wrapper
     echo $after_widget;
 }
Esempio n. 2
0
 /**
  * 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))));
 }
Esempio n. 3
0
 /**
  * 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))));
 }
/**
 * @param $template
 * @return string
 */
function fflcommerce_template_loader($template)
{
    if (is_single() && get_post_type() == 'product') {
        fflcommerce_add_body_class(array('fflcommerce', 'fflcommerce-product'));
        $template = locate_template(array('single-product.php', FFLCOMMERCE_TEMPLATE_URL . 'single-product.php'));
        if (!$template) {
            $template = FFLCOMMERCE_DIR . '/templates/single-product.php';
        }
    } elseif (is_tax('product_cat')) {
        fflcommerce_add_body_class(array('fflcommerce', 'fflcommerce-products', 'fflcommerce-product_cat'));
        global $posts;
        $templates = array();
        if (count($posts)) {
            $category = get_the_terms($posts[0]->ID, 'product_cat');
            $slug = $category[key($category)]->slug;
            $templates[] = 'taxonomy-product_cat-' . $slug . '.php';
            $templates[] = FFLCOMMERCE_TEMPLATE_URL . 'taxonomy-product_cat-' . $slug . '.php';
        }
        $templates[] = 'taxonomy-product_cat.php';
        $templates[] = FFLCOMMERCE_TEMPLATE_URL . 'taxonomy-product_cat.php';
        $template = locate_template($templates);
        if (!$template) {
            $template = FFLCOMMERCE_DIR . '/templates/taxonomy-product_cat.php';
        }
    } elseif (is_tax('product_tag')) {
        fflcommerce_add_body_class(array('fflcommerce', 'fflcommerce-products', 'fflcommerce-product_tag'));
        global $posts;
        $templates = array();
        if (count($posts)) {
            $tag = get_the_terms($posts[0]->ID, 'product_tag');
            $slug = $tag[key($tag)]->slug;
            $templates[] = 'taxonomy-product_tag-' . $slug . '.php';
            $templates[] = FFLCOMMERCE_TEMPLATE_URL . 'taxonomy-product_tag-' . $slug . '.php';
        }
        $templates[] = 'taxonomy-product_tag.php';
        $templates[] = FFLCOMMERCE_TEMPLATE_URL . 'taxonomy-product_tag.php';
        $template = locate_template($templates);
        if (!$template) {
            $template = FFLCOMMERCE_DIR . '/templates/taxonomy-product_tag.php';
        }
    } elseif (is_post_type_archive('product') || is_page(fflcommerce_get_page_id('shop'))) {
        fflcommerce_add_body_class(array('fflcommerce', 'fflcommerce-shop', 'fflcommerce-products'));
        $template = locate_template(array('archive-product.php', FFLCOMMERCE_TEMPLATE_URL . 'archive-product.php'));
        if (!$template) {
            $template = FFLCOMMERCE_DIR . '/templates/archive-product.php';
        }
    }
    return $template;
}
Esempio n. 5
0
function fflcommerce_edit_address()
{
    $account_url = get_permalink(fflcommerce_get_page_id(FFLCOMMERCE_MY_ACCOUNT));
    $user_id = get_current_user_id();
    $load_address = fflcommerce_get_address_to_edit();
    $address = fflcommerce_get_address_fields($load_address, $user_id);
    if (isset($_POST['save_address']) && fflcommerce::verify_nonce(FFLCOMMERCE_EDIT_ADDRESS)) {
        if ($user_id > 0) {
            foreach ($address as &$field) {
                if (isset($_POST[$field['name']])) {
                    $field['value'] = fflcommerce_clean($_POST[$field['name']]);
                    update_user_meta($user_id, $field['name'], $field['value']);
                }
            }
            do_action('fflcommerce_user_edit_address', $user_id, $address);
        }
    }
    fflcommerce_render('shortcode/my_account/edit_address', array('url' => add_query_arg('address', $load_address, apply_filters('fflcommerce_get_edit_address_page_id', get_permalink(fflcommerce_get_page_id(FFLCOMMERCE_EDIT_ADDRESS)))), 'account_url' => $account_url, 'load_address' => $load_address, 'address' => $address));
}
Esempio n. 6
0
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;
    }
}
 /** gets the url to remove an item from the cart
  *
  * @param $cart_item_key
  * @return mixed|string|void
  */
 public static function get_remove_url($cart_item_key)
 {
     $cart_page_id = fflcommerce_get_page_id('cart');
     if ($cart_page_id) {
         return apply_filters('fflcommerce_get_remove_url', fflcommerce::nonce_url('cart', add_query_arg('remove_item', $cart_item_key, get_permalink($cart_page_id))));
     }
     return '';
 }
/**
 * Properly sets the WP Nav Menus items classes for FFL Commerce queried objects
 *
 * @param $menu_items
 * @param array $args
 * @return
 * @TODO set parent items classes when the shop page is not at the nav menu root
 */
function fflcommerce_nav_menu_items_classes($menu_items, $args)
{
    $options = FFLCommerce_Base::get_options();
    $shop_page_id = (int) fflcommerce_get_page_id('shop');
    // only add nav menu classes if the queried object is the Shop page or derivative (Product, Category, Tag)
    if (empty($shop_page_id) || !is_content_wrapped()) {
        return $menu_items;
    }
    $home_page_id = (int) $options->get('page_for_posts');
    foreach ((array) $menu_items as $key => $menu_item) {
        $classes = (array) $menu_item->classes;
        // unset classes set by WP on the home page item
        // shouldn't need a content wrap check as we can't get here without it  -JAP-
        if (is_content_wrapped() && $home_page_id == $menu_item->object_id) {
            $menu_items[$key]->current = false;
            unset($classes[array_search('current_page_parent', $classes)]);
            unset($classes[array_search('current-menu-item', $classes)]);
        }
        if (is_shop() && $shop_page_id == $menu_item->object_id) {
            // is products archive
            $menu_items[$key]->current = true;
            $classes[] = 'current-menu-item';
            $classes[] = 'current_page_item';
        } elseif ((is_product() || is_product_category() || is_product_tag()) && $shop_page_id == $menu_item->object_id) {
            // is another fflcommerce object
            $classes[] = 'current_page_parent';
            $classes[] = 'current_menu_parent';
        }
        $menu_items[$key]->classes = array_unique($classes);
    }
    return $menu_items;
}
Esempio n. 9
0
    if (!$formatted_address) {
        _e('You have not set up a billing address yet.', 'fflcommerce');
    } else {
        echo $formatted_address;
    }
    ?>
		</address>
	</div>
	<div class="col-2">
		<header class="title">
			<h3><?php 
    _e('Shipping Address', 'fflcommerce');
    ?>
</h3>
			<a href="<?php 
    echo esc_url(add_query_arg('address', 'shipping', apply_filters('fflcommerce_get_edit_address_page_id', get_permalink(fflcommerce_get_page_id('edit_address')))));
    ?>
" class="edit"><?php 
    _e('Edit', 'fflcommerce');
    ?>
</a>
		</header>
		<address>
			<?php 
    $country = get_user_meta(get_current_user_id(), 'shipping_country', true);
    $country = fflcommerce_countries::has_country($country) ? fflcommerce_countries::get_country($country) : '';
    $address = array(get_user_meta(get_current_user_id(), 'shipping_first_name', true) . ' ' . get_user_meta(get_current_user_id(), 'shipping_last_name', true), get_user_meta(get_current_user_id(), 'shipping_company', true), get_user_meta(get_current_user_id(), 'shipping_address_1', true), get_user_meta(get_current_user_id(), 'shipping_address_2', true), get_user_meta(get_current_user_id(), 'shipping_city', true), get_user_meta(get_current_user_id(), 'shipping_state', true), get_user_meta(get_current_user_id(), 'shipping_postcode', true), $country);
    $address = array_map('trim', $address);
    $formatted_address = implode(', ', array_filter($address));
    if (!$formatted_address) {
        _e('You have not set up a shipping address yet.', 'fflcommerce');
Esempio n. 10
0
 /**
  * Process Response from WorldPay
  */
 private function process_response($posted)
 {
     $installation_id = $this->get_post('instId');
     $cartId = $this->get_post('cartId');
     $transId = $this->get_post('transId');
     $processed_transID = get_post_meta($cartId, '_worldpay_processed_transID', true);
     $amount = $this->get_post('amount');
     $authAmount = $this->get_post('authAmount');
     $authCurrency = $this->get_post('authCurrency');
     $currency = $this->get_post('currency');
     $shop_currency = FFLCommerce_Base::get_options()->get('fflcommerce_currency');
     $testMode = $this->get_post('testMode');
     $error = array();
     $order = new fflcommerce_order((int) $cartId);
     // Do all checks only if transaction was processed.
     switch ($this->get_post('transStatus')) {
         case 'Y':
             // If the currency is locked.
             if ($this->fixed_currency == 'yes') {
                 // All currencies should be the same.
                 if ($currency != $authCurrency || $authCurrency != $shop_currency || $currency != $shop_currency) {
                     $error['Locked_Currency_Error'] = sprintf(__('The currency paid in was different than the one requested. Order #: %s. Currency paid in: %s, the amount paid: %s. You should investigate further.', 'fflcommerce'), $order->id, $authCurrency, $authAmount);
                 }
                 // All amounts should be the same
                 if ($order->order_total != $amount || $authAmount != $order->order_total || $authAmount != $amount) {
                     $error['Locked_Amount_Error'] = sprintf(__('There were differences in the amounts received. Order #: %s. Submitted: %s, Paid: %s, Order Total: %s. You should investigate further.', 'fflcommerce'), $order->id, $amount, $authAmount, $order->order_total);
                 }
             } else {
                 // If currency submitted to WorldPay is the same as your store one.
                 // They should always be the same even if you accept multiple currency payments.
                 if ($currency != $shop_currency) {
                     $error['currency'] = sprintf(__('The currency submitted to WorldPay (%s) is different than the main currency of your shop (%s). You should investigate further.', 'fflcommerce'), $currency, $shop_currency);
                 }
                 // If multi-currency is supported, at least the amount submitted to WorldPay should be the same as the order total.
                 if ($order->order_total != $amount) {
                     $error['amount'] = sprintf(__('The order total (%s) is different than the amount submitted to WorldPay (%s). You should investigate further.', 'fflcommerce'), $order->order_total, $amount);
                 }
             }
             // Check merchant.
             if ($installation_id != $this->installation_id) {
                 $error['instId'] = sprintf(__('Order was paid to installation ID: %s, which is different than the Installation ID set in your shop: %s. You should investigate further.', 'fflcommerce'), $installation_id, $this->installation_id);
             }
             if ($transId == $processed_transID) {
                 $error['already_processed'] = sprintf(__('Payment with the same transaction ID (%s) was already processed for this order. You should investigate further.', 'fflcommerce'), $transId);
             }
             if ($this->testmode == 'no' && $testMode > 0) {
                 $error['testmode'] = sprintf(__('Your shop is in Live mode, but you received a Test mode transaction. You should investigate further.', 'fflcommerce'));
             }
             if (empty($error) && $testMode == 0) {
                 // Payment completed as live response
                 $order->add_order_note(__('WorldPay payment completed. Transaction ID: ' . $transId, 'fflcommerce'));
                 update_post_meta($order->id, '_worldpay_processed_transID', $transId, $processed_transID);
                 $order->payment_complete();
                 $args = array('key' => $order->order_key, 'order' => $order->id);
                 $redirect_url = add_query_arg($args, get_permalink(fflcommerce_get_page_id('thanks')));
             } elseif (empty($error) && $testMode > 0) {
                 // Payment completed as test response
                 $order->add_order_note(__('TESTMODE: WorldPay payment completed. Transaction ID: ' . $transId, 'fflcommerce'));
                 update_post_meta($order->id, '_worldpay_processed_transID', $transId, $processed_transID);
                 $order->payment_complete();
                 $args = array('key' => $order->order_key, 'order' => $order->id);
                 $redirect_url = add_query_arg($args, get_permalink(fflcommerce_get_page_id('thanks')));
             }
             if (!empty($error) && $this->receive_err_log == 'yes') {
                 $info = sprintf(__('Order #%s ', 'fflcommerce'), $order->id);
                 $this->email_worldpay_error_logs($error, $posted, $info);
                 $redirect_url = get_permalink(fflcommerce_get_page_id('checkout'));
             }
             break;
         case 'C':
             if ($testMode == 0) {
                 // Payment was canceled live.
                 $order->cancel_order(__('Order was canceled by customer at WorldPay.', 'fflcommerce'));
             }
             if ($testMode > 0) {
                 // Payment was canceled in test mode.
                 $order->cancel_order(__('TESTMODE: Order was canceled by customer at WorldPay.', 'fflcommerce'));
             }
             $redirect_url = $this->get_post('MC_cancel_return');
             break;
         default:
             // No action
             $redirect_url = $this->get_post('MC_cancel_return');
             break;
     }
     echo '<html><head><meta http-equiv="refresh" content="2;url=' . $redirect_url . '"></head><body><WPDISPLAY ITEM=banner></body></html>';
     exit;
 }
Esempio n. 11
0
 /**
  * Process the payment and return the result
  **/
 function process_payment($order_id)
 {
     $order = new fflcommerce_order($order_id);
     return array('result' => 'success', 'redirect' => add_query_arg('order', $order->id, add_query_arg('key', $order->order_key, get_permalink(fflcommerce_get_page_id('pay')))));
 }
Esempio n. 12
0
fflcommerce::nonce_field('process_checkout');
?>

		<?php 
do_action('fflcommerce_review_order_before_submit');
?>

		<?php 
if (fflcommerce_get_page_id('terms') > 0) {
    ?>
			<p class="form-row terms">
				<label for="terms" class="checkbox"><?php 
    _e('I accept the', 'fflcommerce');
    ?>
					<a href="<?php 
    echo esc_url(get_permalink(fflcommerce_get_page_id('terms')));
    ?>
" target="_blank"><?php 
    _e('terms &amp; conditions', 'fflcommerce');
    ?>
</a>
				</label>
				<input type="checkbox" class="input-checkbox" name="terms" id="terms"<?php 
    isset($_POST['terms']) and print ' checked="checked"';
    ?>
 />
			</p>
		<?php 
}
?>
 /**  Generates a URL so that a customer can checkout/pay for their (unpaid - pending) order via a link */
 public function get_checkout_payment_url()
 {
     $payment_page = apply_filters('fflcommerce_get_checkout_payment_url', get_permalink(fflcommerce_get_page_id('pay')));
     if (self::get_options()->get('fflcommerce_force_ssl_checkout') == 'yes' || is_ssl()) {
         $payment_page = str_replace('http:', 'https:', $payment_page);
     }
     return add_query_arg('pay_for_order', 'true', add_query_arg('order', $this->order_key, add_query_arg('order_id', $this->id, $payment_page)));
 }
 function fflcommerce_breadcrumb($delimiter = ' &rsaquo; ', $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 &ldquo;', 'fflcommerce') . $queried_object->name . '&rdquo;' . $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 &ldquo;', 'fflcommerce') . get_search_query() . '&rdquo;' . $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 &ldquo;', 'fflcommerce') . get_search_query() . '&rdquo;' . $after;
         } elseif (is_tag()) {
             echo $before . __('Posts tagged &ldquo;', 'fflcommerce') . single_tag_title('', false) . '&rdquo;' . $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;
     }
 }
 /**
  * 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 &rarr;</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 &amp; 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'));
         }
     }
 }
Esempio n. 16
0
 /**
  * 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))));
 }
Esempio n. 17
0
/**
 * Create pages
 *
 * Creates pages that the plugin relies on, storing page id's in options.
 *
 * @since 		0.9.9.1
 */
function fflcommerce_create_pages()
{
    $fflcommerce_options = FFLCommerce_Base::get_options();
    // start out with basic page parameters, modify as we go
    $page_data = array('post_status' => 'publish', 'post_type' => 'page', 'post_author' => 1, 'post_name' => '', 'post_title' => __('Shop', 'fflcommerce'), 'post_content' => '', 'comment_status' => 'closed');
    fflcommerce_create_single_page('shop', 'fflcommerce_shop_page_id', $page_data);
    $shop_page = $fflcommerce_options->get('fflcommerce_shop_page_id');
    $fflcommerce_options->set('fflcommerce_shop_redirect_page_id', $shop_page);
    $page_data['post_title'] = __('Cart', 'fflcommerce');
    $page_data['post_content'] = '[fflcommerce_cart]';
    fflcommerce_create_single_page('cart', 'fflcommerce_cart_page_id', $page_data);
    $page_data['post_title'] = __('Track your order', 'fflcommerce');
    $page_data['post_content'] = '[fflcommerce_order_tracking]';
    fflcommerce_create_single_page('order-tracking', 'fflcommerce_track_order_page_id', $page_data);
    $page_data['post_title'] = __('My Account', 'fflcommerce');
    $page_data['post_content'] = '[fflcommerce_my_account]';
    fflcommerce_create_single_page('my-account', 'fflcommerce_myaccount_page_id', $page_data);
    $page_data['post_title'] = __('Edit My Address', 'fflcommerce');
    $page_data['post_content'] = '[fflcommerce_edit_address]';
    $page_data['post_parent'] = fflcommerce_get_page_id('myaccount');
    fflcommerce_create_single_page('edit-address', 'fflcommerce_edit_address_page_id', $page_data);
    $page_data['post_title'] = __('Change Password', 'fflcommerce');
    $page_data['post_content'] = '[fflcommerce_change_password]';
    $page_data['post_parent'] = fflcommerce_get_page_id('myaccount');
    fflcommerce_create_single_page('change-password', 'fflcommerce_change_password_page_id', $page_data);
    $page_data['post_title'] = __('View Order', 'fflcommerce');
    $page_data['post_content'] = '[fflcommerce_view_order]';
    $page_data['post_parent'] = fflcommerce_get_page_id('myaccount');
    fflcommerce_create_single_page('view-order', 'fflcommerce_view_order_page_id', $page_data);
    $page_data['post_title'] = __('Checkout', 'fflcommerce');
    $page_data['post_content'] = '[fflcommerce_checkout]';
    unset($page_data['post_parent']);
    fflcommerce_create_single_page('checkout', 'fflcommerce_checkout_page_id', $page_data);
    $page_data['post_title'] = __('Checkout &rarr; Pay', 'fflcommerce');
    $page_data['post_content'] = '[fflcommerce_pay]';
    $page_data['post_parent'] = fflcommerce_get_page_id('checkout');
    fflcommerce_create_single_page('pay', 'fflcommerce_pay_page_id', $page_data);
    $page_data['post_title'] = __('Thank you', 'fflcommerce');
    $page_data['post_content'] = '[fflcommerce_thankyou]';
    $page_data['post_parent'] = fflcommerce_get_page_id('checkout');
    fflcommerce_create_single_page('thanks', 'fflcommerce_thanks_page_id', $page_data);
}
Esempio n. 18
0
function fflcommerce_download_product()
{
    if (isset($_GET['download_file']) && isset($_GET['order']) && isset($_GET['email'])) {
        global $wpdb;
        $download_file = (int) urldecode($_GET['download_file']);
        $order = urldecode($_GET['order']);
        $email = urldecode($_GET['email']);
        if (!is_email($email)) {
            wp_die(__('Invalid email address.', 'fflcommerce') . ' <a href="' . home_url() . '">' . __('Go to homepage &rarr;', 'fflcommerce') . '</a>');
        }
        $download_result = $wpdb->get_row($wpdb->prepare("\n\t\t\tSELECT downloads_remaining, user_id\n\t\t\tFROM " . $wpdb->prefix . "fflcommerce_downloadable_product_permissions\n\t\t\tWHERE user_email = %s\n\t\t\tAND order_key = %s\n\t\t\tAND product_id = %s\n\t\t;", $email, $order, $download_file));
        if (!$download_result) {
            wp_die(__('Invalid downloads.', 'fflcommerce') . ' <a href="' . home_url() . '">' . __('Go to homepage &rarr;', 'fflcommerce') . '</a>');
            exit;
        }
        $order_id = isset($download_result->order_id) ? $download_result->order_id : false;
        $user_id = $download_result->user_id;
        $downloads_remaining = $download_result->downloads_remaining;
        if ($user_id && FFLCommerce_Base::get_options()->get('fflcommerce_downloads_require_login') == 'yes') {
            if (!is_user_logged_in()) {
                wp_die(__('You must be logged in to download files.', 'fflcommerce') . ' <a href="' . wp_login_url(get_permalink(fflcommerce_get_page_id('myaccount'))) . '">' . __('Login &rarr;', 'fflcommerce') . '</a>');
                exit;
            } else {
                $current_user = wp_get_current_user();
                if ($user_id != $current_user->ID) {
                    wp_die(__('This is not your download link.', 'fflcommerce'));
                    exit;
                }
            }
        }
        if ($order_id) {
            $order = new fflcommerce_order($order_id);
            if ($order->status != 'completed' && $order->status != 'processing' && $order->status != 'publish') {
                wp_die(__('Invalid order.', 'fflcommerce') . ' <a href="' . home_url() . '">' . __('Go to homepage &rarr;', 'fflcommerce') . '</a>');
                exit;
            }
        }
        if ($downloads_remaining == '0') {
            wp_die(sprintf(__('Sorry, you have reached your download limit for this file. <a href="%s">Go to homepage &rarr;</a>', 'fflcommerce'), home_url()));
        } else {
            if ($downloads_remaining > 0) {
                $wpdb->update($wpdb->prefix . "fflcommerce_downloadable_product_permissions", array('downloads_remaining' => $downloads_remaining - 1), array('user_email' => $email, 'order_key' => $order, 'product_id' => $download_file), array('%d'), array('%s', '%s', '%d'));
            }
            $file_path = get_post_meta($download_file, 'file_path', true);
            if (!$file_path) {
                wp_die(sprintf(__('File not found. <a href="%s">Go to homepage &rarr;</a>', 'fflcommerce'), home_url()));
            }
            // Get URLS with https
            $site_url = site_url();
            $network_url = network_admin_url();
            if (is_ssl()) {
                $site_url = str_replace('https:', 'http:', $site_url);
                $network_url = str_replace('https:', 'http:', $network_url);
            }
            if (!is_multisite()) {
                $file_path = str_replace(trailingslashit($site_url), ABSPATH, $file_path);
            } else {
                $upload_dir = wp_upload_dir();
                // Try to replace network url
                $file_path = str_replace(trailingslashit($network_url), ABSPATH, $file_path);
                // Now try to replace upload URL
                $file_path = str_replace($upload_dir['baseurl'], $upload_dir['basedir'], $file_path);
            }
            $file_path = apply_filters('fflcommerce_download_file_path', $file_path, $download_file, $order, $email);
            // See if its local or remote
            if (strstr($file_path, 'http:') || strstr($file_path, 'https:') || strstr($file_path, 'ftp:')) {
                $remote_file = true;
            } else {
                $remote_file = false;
                $file_path = realpath($file_path);
            }
            // Download the file
            $file_extension = strtolower(substr(strrchr($file_path, "."), 1));
            switch ($file_extension) {
                case "pdf":
                    $ctype = "application/pdf";
                    break;
                case "exe":
                    $ctype = "application/octet-stream";
                    break;
                case "zip":
                    $ctype = "application/zip";
                    break;
                case "doc":
                    $ctype = "application/msword";
                    break;
                case "xls":
                    $ctype = "application/vnd.ms-excel";
                    break;
                case "ppt":
                    $ctype = "application/vnd.ms-powerpoint";
                    break;
                case "gif":
                    $ctype = "image/gif";
                    break;
                case "png":
                    $ctype = "image/png";
                    break;
                case "jpe":
                case "jpeg":
                case "jpg":
                    $ctype = "image/jpg";
                    break;
                default:
                    $ctype = "application/force-download";
            }
            do_action('fflcommerce_before_download', $file_path, $order);
            @session_write_close();
            @set_time_limit(0);
            @set_magic_quotes_runtime(0);
            @ob_end_clean();
            if (ob_get_level()) {
                @ob_end_clean();
            }
            // required for IE, otherwise Content-Disposition may be ignored
            if (ini_get('zlib.output_compression')) {
                ini_set('zlib.output_compression', 'Off');
            }
            header("Pragma: no-cache");
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Robots: none");
            header("Content-Type: " . $ctype . "");
            header("Content-Description: File Transfer");
            header("Content-Transfer-Encoding: binary");
            if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
                // workaround for IE filename bug with multiple periods / multiple dots in filename
                $iefilename = preg_replace('/\\./', '%2e', basename($file_path), substr_count(basename($file_path), '.') - 1);
                header("Content-Disposition: attachment; filename=\"" . $iefilename . "\";");
            } else {
                header("Content-Disposition: attachment; filename=\"" . basename($file_path) . "\";");
            }
            header("Content-Length: " . @filesize($file_path));
            if ($remote_file) {
                header('Location: ' . $file_path);
            } else {
                @readfile("{$file_path}") or wp_die(sprintf(__('File not found. <a href="%s">Go to homepage &rarr;</a>', 'fflcommerce'), home_url()));
            }
            exit;
        }
    }
}
Esempio n. 19
0
function fflcommerce_page_body_classes()
{
    global $fflcommerce_body_classes;
    $fflcommerce_body_classes = (array) $fflcommerce_body_classes;
    if (is_order_tracker()) {
        fflcommerce_add_body_class(array('fflcommerce', 'fflcommerce-tracker'));
    }
    if (is_checkout()) {
        fflcommerce_add_body_class(array('fflcommerce', 'fflcommerce-checkout'));
    }
    if (is_cart()) {
        fflcommerce_add_body_class(array('fflcommerce', 'fflcommerce-cart'));
    }
    if (is_page(fflcommerce_get_page_id('thanks'))) {
        fflcommerce_add_body_class(array('fflcommerce', 'fflcommerce-thanks'));
    }
    if (is_page(fflcommerce_get_page_id('pay'))) {
        fflcommerce_add_body_class(array('fflcommerce', 'fflcommerce-pay'));
    }
    if (is_account()) {
        fflcommerce_add_body_class(array('fflcommerce', 'fflcommerce-myaccount'));
    }
}
Esempio n. 20
0
    /**
     * 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)
    {
        // Otherwise Start buffering and output the Widget
        ob_start();
        extract($args);
        // Set the widget title
        $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Product Categories', 'fflcommerce'), $instance, $this->id_base);
        // Get options
        $count = (bool) isset($instance['count']) ? $instance['count'] : false;
        $is_hierarchial = (bool) isset($instance['hierarchical']) ? $instance['hierarchical'] : false;
        $is_dropdown = (bool) isset($instance['dropdown']) ? $instance['dropdown'] : false;
        // Print the widget wrapper & title
        echo $before_widget;
        if ($title) {
            echo $before_title . $title . $after_title;
        }
        // Define options for the list
        $args = array('orderby' => 'name', 'show_count' => $count, 'hierarchical' => $is_hierarchial, 'taxonomy' => 'product_cat', 'title_li' => null);
        if (is_product()) {
            global $post;
            $categories = get_the_terms($post->ID, 'product_cat');
            if (!empty($categories)) {
                foreach ($categories as $id => $cat) {
                    $args['current_category'] = apply_filters('fflcommerce_product_cat_widget_terms', $cat->term_id, $categories);
                    break;
                    // we can only take the first one
                }
            }
        }
        // Output as dropdown or unordered list
        if ($is_dropdown) {
            // Set up arguments
            $args['name'] = 'dropdown_product_cat';
            // Print dropdown
            // wp_dropdown_categories($args); Commented out due to wordpress bug 13258 not supporting custom taxonomies
            // See: http://core.trac.wordpress.org/ticket/13258
            fflcommerce_product_dropdown_categories($args['show_count'], $args['hierarchical']);
            // TODO: Move this javascript to its own file (plugins.js?)
            ?>
			<script type='text/javascript'>
				/* <![CDATA[ */
				var dropdown = document.getElementById("dropdown_product_cat");
				function onCatChange(){
					if(dropdown.options[dropdown.selectedIndex].value !== ''){
						location.href = "<?php 
            echo home_url();
            ?>
/?product_cat=" + dropdown.options[dropdown.selectedIndex].value;
					} else {
						location.href = "<?php 
            echo get_permalink(fflcommerce_get_page_id('shop'));
            ?>
"
					}
				}
				dropdown.onchange = onCatChange;
				/* ]]> */
			</script>
		<?php 
        } else {
            // Print list of categories
            echo '<ul>';
            wp_list_categories(apply_filters('widget_product_categories_args', $args));
            echo '</ul>';
        }
        // Print closing widget wrapper
        echo $after_widget;
        // Flush output buffer and save to transient cache
        $result = ob_get_flush();
        $cache[$this->id] = $result;
        set_transient('fflcommerce_widget_cache', $cache, 3600 * 3);
        // 3 hours ahead
    }
Esempio n. 21
0
<?php

fflcommerce::show_messages();
?>
<form action="<?php 
echo esc_url(apply_filters('fflcommerce_get_change_password_page_id', get_permalink(fflcommerce_get_page_id('change_password'))));
?>
" method="post">
	<p class="form-row form-row-first">
		<label for="password-1"><?php 
_e('New password', 'fflcommerce');
?>
 <span class="required">*</span></label>
		<input type="password" class="input-text" name="password-1" id="password-1" />
	</p>

	<p class="form-row form-row-last">
		<label for="password-2"><?php 
_e('Re-enter new password', 'fflcommerce');
?>
 <span class="required">*</span></label>
		<input type="password" class="input-text" name="password-2" id="password-2" />
	</p>

	<div class="clear"></div>
	<?php 
fflcommerce::nonce_field('change_password');
?>
	<p><input type="submit" class="button" name="save_password" value="<?php 
_e('Save', 'fflcommerce');
?>
Esempio n. 22
0
 /**
  * Generate the paypal button link
  *
  * @param int $order_id
  * @return string
  */
 public function generate_paypal_form($order_id)
 {
     $order = new fflcommerce_order($order_id);
     if ($this->testmode == 'yes') {
         $url = $this->testurl . '?test_ipn=1&';
     } else {
         $url = $this->liveurl . '?';
     }
     if (in_array($order->billing_country, array('US', 'CA'))) {
         $order->billing_phone = str_replace(array('(', '-', ' ', ')'), '', $order->billing_phone);
         $phone_args = array('night_phone_a' => substr($order->billing_phone, 0, 3), 'night_phone_b' => substr($order->billing_phone, 3, 3), 'night_phone_c' => substr($order->billing_phone, 6, 4), 'day_phone_a' => substr($order->billing_phone, 0, 3), 'day_phone_b' => substr($order->billing_phone, 3, 3), 'day_phone_c' => substr($order->billing_phone, 6, 4));
     } else {
         $phone_args = array('night_phone_b' => $order->billing_phone, 'day_phone_b' => $order->billing_phone);
     }
     // filter redirect page
     $checkout_redirect = apply_filters('fflcommerce_get_checkout_redirect_page_id', fflcommerce_get_page_id('thanks'));
     $paypal_args = array_merge(array('cmd' => '_cart', 'business' => $this->testmode == 'yes' ? $this->testemail : $this->email, 'no_note' => 1, 'currency_code' => FFLCommerce_Base::get_options()->get('fflcommerce_currency'), 'charset' => 'UTF-8', 'rm' => 2, 'upload' => 1, 'return' => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink($checkout_redirect))), 'cancel_return' => $order->get_cancel_order_url(), 'custom' => $order_id, 'notify_url' => $this->notify_url, 'first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'company' => $order->billing_company, 'address1' => $order->billing_address_1, 'address2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'zip' => $order->billing_postcode, 'country' => $order->billing_country, 'email' => $order->billing_email, 'invoice' => $order->get_order_number(), 'amount' => number_format((double) $order->order_total, $this->decimals), 'bn' => 'FFLCommerce_SP'), $phone_args);
     if ($this->send_shipping == 'yes') {
         $paypal_args['no_shipping'] = 1;
         $paypal_args['address_override'] = 1;
         $paypal_args['first_name'] = $order->shipping_first_name;
         $paypal_args['last_name'] = $order->shipping_last_name;
         $paypal_args['address1'] = $order->shipping_address_1;
         $paypal_args['address2'] = $order->shipping_address_2;
         $paypal_args['city'] = $order->shipping_city;
         $paypal_args['state'] = $order->shipping_state;
         $paypal_args['zip'] = $order->shipping_postcode;
         $paypal_args['country'] = $order->shipping_country;
         // PayPal counts Puerto Rico as a US Territory, won't allow payment without it
         if ($paypal_args['country'] == 'PR') {
             $paypal_args['country'] = 'US';
             $paypal_args['state'] = 'PR';
         }
     } else {
         $paypal_args['no_shipping'] = 1;
         $paypal_args['address_override'] = 0;
     }
     // If prices include tax, send the whole order as a single item
     if (FFLCommerce_Base::get_options()->get('fflcommerce_prices_include_tax') == 'yes') {
         // Discount
         $paypal_args['discount_amount_cart'] = number_format((double) $order->order_discount, $this->decimals);
         // Don't pass items - PayPal breaks tax due to catalog prices include tax.
         // PayPal has no option for tax inclusive pricing.
         // Pass 1 item for the order items overall
         $item_names = array();
         foreach ($order->items as $item) {
             $_product = $order->get_product_from_item($item);
             $title = $_product->get_title();
             //if variation, insert variation details into product title
             if ($_product instanceof fflcommerce_product_variation) {
                 $title .= ' (' . fflcommerce_get_formatted_variation($_product, $item['variation'], true) . ')';
             }
             $item_names[] = $title . ' x ' . $item['qty'];
         }
         $paypal_args['item_name_1'] = sprintf(__('Order %s', 'fflcommerce'), $order->get_order_number()) . ' - ' . implode(', ', $item_names);
         $paypal_args['quantity_1'] = 1;
         $paypal_args['amount_1'] = number_format($order->order_total - $order->order_shipping - $order->order_shipping_tax + $order->order_discount, $this->decimals, '.', '');
         if ($order->order_shipping + $order->order_shipping_tax > 0) {
             $paypal_args['item_name_2'] = __('Shipping cost', 'fflcommerce');
             $paypal_args['quantity_2'] = '1';
             $paypal_args['amount_2'] = number_format($order->order_shipping + $order->order_shipping_tax, $this->decimals, '.', '');
         }
     } else {
         // Cart Contents
         $item_loop = 0;
         foreach ($order->items as $item) {
             $_product = $order->get_product_from_item($item);
             if ($_product->exists() && $item['qty']) {
                 $item_loop++;
                 $title = $_product->get_title();
                 //if variation, insert variation details into product title
                 if ($_product instanceof fflcommerce_product_variation) {
                     $title .= ' (' . fflcommerce_get_formatted_variation($_product, $item['variation'], true) . ')';
                 }
                 $paypal_args['item_name_' . $item_loop] = $title;
                 $paypal_args['quantity_' . $item_loop] = $item['qty'];
                 $paypal_args['amount_' . $item_loop] = number_format(apply_filters('fflcommerce_paypal_adjust_item_price', $item['cost'], $item, 10, 2), $this->decimals);
                 //Apparently, Paypal did not like "28.4525" as the amount. Changing that to "28.45" fixed the issue.
             }
         }
         // Shipping Cost
         if (fflcommerce_shipping::is_enabled() && $order->order_shipping > 0) {
             $item_loop++;
             $paypal_args['item_name_' . $item_loop] = __('Shipping cost', 'fflcommerce');
             $paypal_args['quantity_' . $item_loop] = '1';
             $paypal_args['amount_' . $item_loop] = number_format((double) $order->order_shipping, $this->decimals);
         }
         $paypal_args['tax'] = $order->get_total_tax(false, false);
         // no currency sign or pricing options for separators
         $paypal_args['tax_cart'] = $order->get_total_tax(false, false);
         // no currency sign or pricing options for separators
         $paypal_args['discount_amount_cart'] = $order->order_discount;
         if ($this->force_payment == 'yes') {
             $sum = 0;
             for ($i = 1; $i < $item_loop; $i++) {
                 $sum += $paypal_args['amount_' . $i];
             }
             $item_loop++;
             if ($sum == 0 || $order->order_discount && $sum - $order->order_discount == 0) {
                 $paypal_args['item_name_' . $item_loop] = __('Force payment on free', 'fflcommerce');
                 $paypal_args['quantity_' . $item_loop] = '1';
                 $paypal_args['amount_' . $item_loop] = 0.01;
                 // force payment
             }
         }
     }
     $paypal_args = apply_filters('fflcommerce_paypal_args', $paypal_args);
     return fflcommerce_render_result('gateways/paypal', array('url' => $url, 'fields' => $paypal_args));
 }
Esempio n. 23
0
        echo ' &mdash; Page ' . get_query_var('paged');
    }
    ?>
</h1>
	<?php 
} else {
    ?>
		<?php 
    echo apply_filters('fflcommerce_products_list_title', '<h1 class="page-title">' . __('All Products', 'fflcommerce') . '</h1>');
    ?>
	<?php 
}
?>

	<?php 
$shop_page_id = fflcommerce_get_page_id('shop');
$shop_page = get_post($shop_page_id);
if (post_password_required($shop_page)) {
    echo get_the_password_form($shop_page);
} else {
    echo apply_filters('the_content', $shop_page->post_content);
    ?>

	<?php 
    ob_start();
    fflcommerce_get_template_part('loop', 'shop');
    $products_list_html = ob_get_clean();
    echo apply_filters('fflcommerce_products_list', $products_list_html);
    ?>

	<?php 
Esempio n. 24
0
function fflcommerce_pay_action()
{
    if (!is_fflcommerce_single_page(FFLCOMMERCE_PAY)) {
        return;
    }
    if (isset($_GET['pay_for_order']) && isset($_GET['order']) && isset($_GET['order_id'])) {
        // Pay for existing order
        $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') {
            // Set customer location to order location
            if ($order->billing_country) {
                fflcommerce_customer::set_country($order->billing_country);
            }
            if ($order->billing_state) {
                fflcommerce_customer::set_state($order->billing_state);
            }
            if ($order->billing_postcode) {
                fflcommerce_customer::set_postcode($order->billing_postcode);
            }
            // Pay form was posted - process payment
            if (isset($_POST['pay']) && fflcommerce::verify_nonce('pay')) {
                // Update payment method
                if ($order->order_total > 0) {
                    $payment_method = fflcommerce_clean($_POST['payment_method']);
                    $data = (array) maybe_unserialize(get_post_meta($order_id, 'order_data', true));
                    $data['payment_method'] = $payment_method;
                    update_post_meta($order_id, 'order_data', $data);
                    $available_gateways = fflcommerce_payment_gateways::get_available_payment_gateways();
                    $result = $available_gateways[$payment_method]->process_payment($order_id);
                    // Redirect to success/confirmation/payment page
                    if ($result['result'] == 'success') {
                        wp_safe_redirect($result['redirect']);
                        exit;
                    }
                } else {
                    // No payment was required for order
                    $order->payment_complete();
                    // filter redirect page
                    $checkout_redirect = apply_filters('fflcommerce_get_checkout_redirect_page_id', fflcommerce_get_page_id('thanks'));
                    wp_safe_redirect(get_permalink($checkout_redirect));
                    exit;
                }
            }
        } elseif ($order->status != 'pending') {
            fflcommerce::add_error(__('Your order has already been paid for. Please contact us if you need assistance.', 'fflcommerce'));
        } else {
            fflcommerce::add_error(__('Invalid order.', 'fflcommerce'));
        }
    } else {
        // 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 || $order->status != 'pending') {
                wp_safe_redirect(apply_filters('fflcommerce_get_myaccount_page_id', get_permalink(fflcommerce_get_page_id('myaccount'))));
                exit;
            }
        } else {
            wp_safe_redirect(apply_filters('fflcommerce_get_myaccount_page_id', get_permalink(fflcommerce_get_page_id('myaccount'))));
            exit;
        }
    }
}
Esempio n. 25
0
 /**
  *  Check for Futurepay Response
  */
 public function check_response()
 {
     // Only run the following code if theres a response from futurepay
     if (isset($_GET['futurepay'])) {
         $data = array('gmid' => $this->gmid, 'otxnid' => $_GET['futurepay']);
         $response = wp_remote_post(self::$request_url . 'merchant-order-verification?', array('body' => http_build_query($data), 'sslverify' => false));
         $response = json_decode(wp_remote_retrieve_body($response), true);
         if (!empty($response['OrderReference'])) {
             // Get the order
             $order_id = substr($response['OrderReference'], 0, strpos($response['OrderReference'], '-'));
             $order = new fflcommerce_order($order_id);
             // Response is valid but lets check it more closly
             do_action("valid-futurepay-request", $response, $order);
             // set the $_GET query vars for the thankyou page, this empties the Cart
             wp_safe_redirect(add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink(fflcommerce_get_page_id('thanks')))));
             exit;
         }
     }
 }