Ejemplo n.º 1
0
function get_order_email_arguments($order_id)
{
    $options = FFLCommerce_Base::get_options();
    $order = new fflcommerce_order($order_id);
    $inc_tax = $options->get('fflcommerce_calc_taxes') == 'no' || $options->get('fflcommerce_prices_include_tax') == 'yes';
    $can_show_links = $order->status == 'completed' || $order->status == 'processing';
    $statuses = $order->get_order_statuses_and_names();
    $variables = array('blog_name' => get_bloginfo('name'), 'order_number' => $order->get_order_number(), 'order_date' => date_i18n(get_option('date_format')), 'order_status' => $statuses[$order->status], 'shop_name' => $options->get('fflcommerce_company_name'), 'shop_address_1' => $options->get('fflcommerce_address_1'), 'shop_address_2' => $options->get('fflcommerce_address_2'), 'shop_tax_number' => $options->get('fflcommerce_tax_number'), 'shop_phone' => $options->get('fflcommerce_company_phone'), 'shop_email' => $options->get('fflcommerce_company_email'), 'customer_note' => $order->customer_note, 'order_items_table' => fflcommerce_get_order_items_table($order, $can_show_links, true, $inc_tax), 'order_items' => $order->email_order_items_list($can_show_links, true, $inc_tax), 'order_taxes' => fflcommerce_get_order_taxes_list($order), 'subtotal' => $order->get_subtotal_to_display(), 'shipping' => $order->get_shipping_to_display(), 'shipping_cost' => fflcommerce_price($order->order_shipping), 'shipping_method' => $order->shipping_service, 'discount' => fflcommerce_price($order->order_discount), 'total_tax' => fflcommerce_price($order->get_total_tax()), 'total' => fflcommerce_price($order->order_total), 'is_local_pickup' => $order->shipping_method == 'local_pickup' ? true : null, 'checkout_url' => $order->status == 'pending' ? $order->get_checkout_payment_url() : null, 'payment_method' => $order->payment_method_title, 'is_bank_transfer' => $order->payment_method == 'bank_transfer' ? true : null, 'is_cash_on_delivery' => $order->payment_method == 'cod' ? true : null, 'is_cheque' => $order->payment_method == 'cheque' ? true : null, 'bank_info' => str_replace(PHP_EOL, '', fflcommerce_bank_transfer::get_bank_details()), 'cheque_info' => str_replace(PHP_EOL, '', $options->get('fflcommerce_cheque_description')), 'billing_first_name' => $order->billing_first_name, 'billing_last_name' => $order->billing_last_name, 'billing_company' => $order->billing_company, 'billing_euvatno' => $order->billing_euvatno, 'billing_address_1' => $order->billing_address_1, 'billing_address_2' => $order->billing_address_2, 'billing_postcode' => $order->billing_postcode, 'billing_city' => $order->billing_city, 'billing_country' => fflcommerce_countries::get_country($order->billing_country), 'billing_state' => strlen($order->billing_state) == 2 ? fflcommerce_countries::get_state($order->billing_country, $order->billing_state) : $order->billing_state, 'billing_country_raw' => $order->billing_country, 'billing state_raw' => $order->billing_state, 'billing_email' => $order->billing_email, 'billing_phone' => $order->billing_phone, 'shipping_first_name' => $order->shipping_first_name, 'shipping_last_name' => $order->shipping_last_name, 'shipping_company' => $order->shipping_company, 'shipping_address_1' => $order->shipping_address_1, 'shipping_address_2' => $order->shipping_address_2, 'shipping_postcode' => $order->shipping_postcode, 'shipping_city' => $order->shipping_city, 'shipping_country' => fflcommerce_countries::get_country($order->shipping_country), 'shipping_state' => strlen($order->shipping_state) == 2 ? fflcommerce_countries::get_state($order->shipping_country, $order->shipping_state) : $order->shipping_state, 'shipping_country_raw' => $order->shipping_country, 'shipping_state_raw' => $order->shipping_state);
    if ($options->get('fflcommerce_calc_taxes') == 'yes') {
        $variables['all_tax_classes'] = $variables['order_taxes'];
    } else {
        unset($variables['order_taxes']);
    }
    return apply_filters('fflcommerce_order_email_variables', $variables, $order_id);
}
Ejemplo n.º 2
0
/**
 * Outputs the pay page - payment gateways can hook in here to show payment forms etc
 **/
function fflcommerce_pay()
{
    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);
        fflcommerce::show_messages();
        if ($order->id == $order_id && $order->order_key == $order_key && $order->status == 'pending') {
            fflcommerce_pay_for_existing_order($order);
        }
    } 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') {
                fflcommerce::show_messages();
                ?>
				<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>

				<?php 
                do_action('receipt_' . $order->payment_method, $order_id);
                ?>

				<div class="clear"></div>
			<?php 
            }
        }
    }
}
Ejemplo n.º 3
0
function fflcommerce_order_tracking($atts)
{
    extract(shortcode_atts(array(), $atts));
    global $post;
    $fflcommerce_options = FFLCommerce_Base::get_options();
    if ($_POST) {
        $order = new fflcommerce_order();
        $order->id = !empty($_POST['orderid']) ? $_POST['orderid'] : 0;
        if (isset($_POST['order_email']) && $_POST['order_email']) {
            $order_email = trim($_POST['order_email']);
        } else {
            $order_email = '';
        }
        if (!fflcommerce::verify_nonce('order_tracking')) {
            echo '<p>' . __('You have taken too long. Please refresh the page and retry.', 'fflcommerce') . '</p>';
        } elseif ($order->id && $order_email && $order->get_order(apply_filters('fflcommerce_shortcode_order_tracking_order_id', $order->id))) {
            if ($order->billing_email == $order_email) {
                echo '<p>' . sprintf(__('Order %s which was made %s ago and has the status "%s"', 'fflcommerce'), $order->get_order_number(), human_time_diff(strtotime($order->order_date), current_time('timestamp')), __($order->status, 'fflcommerce'));
                if ($order->status == 'completed') {
                    $completed = (array) get_post_meta($order->id, '_js_completed_date', true);
                    if (!empty($completed)) {
                        $completed = $completed[0];
                    } else {
                        $completed = '';
                    }
                    // shouldn't happen, reset to be sure
                    echo sprintf(__(' was completed %s ago', 'fflcommerce'), human_time_diff(strtotime($completed), current_time('timestamp')));
                }
                echo '.</p>';
                do_action('fflcommerce_tracking_details_info', $order);
                ?>
				<?php 
                do_action('fflcommerce_before_track_order_details', $order->id);
                ?>
				<h2><?php 
                _e('Order Details', 'fflcommerce');
                ?>
</h2>
				<table class="shop_table">
					<thead>
						<tr>
							<th><?php 
                _e('ID/SKU', 'fflcommerce');
                ?>
</th>
							<th><?php 
                _e('Title', 'fflcommerce');
                ?>
</th>
							<th><?php 
                _e('Price', 'fflcommerce');
                ?>
</th>
							<th><?php 
                _e('Quantity', 'fflcommerce');
                ?>
</th>
						</tr>
					</thead>
					<tfoot>
                        <tr>
                            <?php 
                if ($fflcommerce_options->get('fflcommerce_calc_taxes') == 'yes' && $order->has_compound_tax() || $fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'yes' && $order->order_discount > 0) {
                    ?>
                                <td colspan="3"><?php 
                    _e('Retail Price', 'fflcommerce');
                    ?>
</td>
                            <?php 
                } else {
                    ?>
                                <td colspan="3"><?php 
                    _e('Subtotal', 'fflcommerce');
                    ?>
</td>
                            <?php 
                }
                ?>
                                <td><?php 
                echo $order->get_subtotal_to_display();
                ?>
</td>
                        </tr>
                        <?php 
                if ($order->order_shipping > 0) {
                    ?>
                            <tr>
                                <td colspan="3"><?php 
                    _e('Shipping', 'fflcommerce');
                    ?>
</td>
                                <td><?php 
                    echo $order->get_shipping_to_display();
                    ?>
</td>
                            </tr>
                            <?php 
                }
                do_action('fflcommerce_processing_fee_after_shipping');
                if ($fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'yes' && $order->order_discount > 0) {
                    ?>
                            <tr class="discount">
                                <td colspan="3"><?php 
                    _e('Discount', 'fflcommerce');
                    ?>
</td>
                                <td>-<?php 
                    echo fflcommerce_price($order->order_discount);
                    ?>
</td>
                            </tr>
                            <?php 
                }
                if ($fflcommerce_options->get('fflcommerce_calc_taxes') == 'yes' && $order->has_compound_tax() || $fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'yes' && $order->order_discount > 0) {
                    ?>
                            <tr>
                                <td colspan="3"><?php 
                    _e('Subtotal', 'fflcommerce');
                    ?>
</td>
                                <td><?php 
                    echo fflcommerce_price($order->order_discount_subtotal);
                    ?>
</td>
                            </tr>
                            <?php 
                }
                if ($fflcommerce_options->get('fflcommerce_calc_taxes') == 'yes') {
                    foreach ($order->get_tax_classes() as $tax_class) {
                        if ($order->show_tax_entry($tax_class)) {
                            ?>
                                    <tr>
                                        <td colspan="3"><?php 
                            echo $order->get_tax_class_for_display($tax_class) . ' (' . (double) $order->get_tax_rate($tax_class) . '%):';
                            ?>
</td>
                                        <td><?php 
                            echo $order->get_tax_amount($tax_class);
                            ?>
</td>
                                    </tr>
                                    <?php 
                        }
                    }
                }
                ?>
						<?php 
                if ($fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'no' && $order->order_discount > 0) {
                    ?>
<tr class="discount">
							<td colspan="3"><?php 
                    _e('Discount', 'fflcommerce');
                    ?>
</td>
							<td>-<?php 
                    echo fflcommerce_price($order->order_discount);
                    ?>
</td>
						</tr><?php 
                }
                ?>
						<tr>
							<td colspan="3"><strong><?php 
                _e('Grand Total', 'fflcommerce');
                ?>
</strong></td>
							<td><strong><?php 
                echo fflcommerce_price($order->order_total);
                ?>
</strong></td>
						</tr>
					</tfoot>
					<tbody>
						<?php 
                foreach ($order->items as $order_item) {
                    if (isset($order_item['variation_id']) && $order_item['variation_id'] > 0) {
                        $_product = new fflcommerce_product_variation($order_item['variation_id']);
                    } else {
                        $_product = new fflcommerce_product($order_item['id']);
                    }
                    echo '<tr>';
                    echo '<td>' . $_product->sku . '</td>';
                    echo '<td class="product-name">' . $_product->get_title();
                    if ($_product instanceof fflcommerce_product_variation) {
                        echo fflcommerce_get_formatted_variation($_product, $order_item['variation']);
                    }
                    do_action('fflcommerce_display_item_meta_data', $order_item);
                    echo '</td>';
                    echo '<td>' . fflcommerce_price($order_item['cost']) . '</td>';
                    echo '<td>' . $order_item['qty'] . '</td>';
                    echo '</tr>';
                }
                ?>
					</tbody>
				</table>
				<?php 
                do_action('fflcommerce_after_track_order_details', $order->id);
                ?>

				<div style="width: 49%; float:left;">
					<h2><?php 
                _e('Billing Address', 'fflcommerce');
                ?>
</h2>
					<p><?php 
                $address = $order->billing_first_name . ' ' . $order->billing_last_name . '<br/>';
                if ($order->billing_company) {
                    $address .= $order->billing_company . '<br/>';
                }
                $address .= $order->formatted_billing_address;
                echo $address;
                ?>
</p>
				</div>
				<div style="width: 49%; float:right;">
					<h2><?php 
                _e('Shipping Address', 'fflcommerce');
                ?>
</h2>
					<p><?php 
                $address = $order->shipping_first_name . ' ' . $order->shipping_last_name . '<br/>';
                if ($order->shipping_company) {
                    $address .= $order->shipping_company . '<br/>';
                }
                $address .= $order->formatted_shipping_address;
                echo $address;
                ?>
</p>
				</div>
				<div class="clear"></div>
				<?php 
            } else {
                echo '<p>' . __('Sorry, we could not find that order id in our database. <a href="' . get_permalink($post->ID) . '">Want to retry?</a>', 'fflcommerce') . '</p>';
            }
        } else {
            echo '<p>' . sprintf(__('Sorry, we could not find that order id in our database. <a href="%s">Want to retry?</a></p>', 'fflcommerce'), get_permalink($post->ID));
        }
    } else {
        ?>
		<form action="<?php 
        echo esc_url(get_permalink($post->ID));
        ?>
" method="post" class="track_order">

			<p><?php 
        _e('To track your order please enter your Order ID and email address in the boxes below and press return. This was given to you on your receipt and in the confirmation email you should have received.', 'fflcommerce');
        ?>
</p>

			<p class="form-row form-row-first"><label for="orderid"><?php 
        _e('Order ID', 'fflcommerce');
        ?>
</label> <input class="input-text" type="text" name="orderid" id="orderid" placeholder="<?php 
        _e('Found in your order confirmation email.', 'fflcommerce');
        ?>
" /></p>
			<p class="form-row form-row-last"><label for="order_email"><?php 
        _e('Billing Email', 'fflcommerce');
        ?>
</label> <input class="input-text" type="text" name="order_email" id="order_email" placeholder="<?php 
        _e('Email you used during checkout.', 'fflcommerce');
        ?>
" /></p>
			<div class="clear"></div>
			<p class="form-row"><input type="submit" class="button" name="track" value="<?php 
        _e('Track"', 'fflcommerce');
        ?>
" /></p>
			<?php 
        fflcommerce::nonce_field('order_tracking');
        ?>
		</form>
		<?php 
    }
}
Ejemplo n.º 4
0
    function column_default($user, $column_name)
    {
        switch ($column_name) {
            case 'customer_name':
                if ($user->last_name && $user->first_name) {
                    return $user->last_name . ', ' . $user->first_name;
                } else {
                    return '-';
                }
            case 'username':
                return $user->user_login;
            case 'location':
                $state_code = get_user_meta($user->ID, 'billing_state', true);
                $country_code = get_user_meta($user->ID, 'billing_country', true);
                $state = fflcommerce_countries::has_state($country_code, $state_code) ? fflcommerce_countries::get_state($country_code, $state_code) : $state_code;
                $country = fflcommerce_countries::has_country($country_code) ? fflcommerce_countries::get_country($country_code) : $country_code;
                $value = '';
                if ($state) {
                    $value .= $state . ', ';
                }
                $value .= $country;
                if ($value) {
                    return $value;
                } else {
                    return '-';
                }
            case 'email':
                return '<a href="mailto:' . $user->user_email . '">' . $user->user_email . '</a>';
            case 'spent':
                return fflcommerce_price(fflcommerce_get_customer_total_spent($user->ID));
            case 'orders':
                return fflcommerce_get_customer_order_count($user->ID);
            case 'last_order':
                $order_ids = get_posts(array('posts_per_page' => 1, 'post_type' => 'shop_order', 'post_status' => array('publish'), 'orderby' => 'date', 'order' => 'desc', 'meta_query' => array(array('key' => 'customer_user', 'value' => $user->ID)), 'fields' => 'ids'));
                if ($order_ids) {
                    $order = new fflcommerce_order($order_ids[0]);
                    return '<a href="' . admin_url('post.php?post=' . $order->id . '&action=edit') . '">' . $order->get_order_number() . '</a> &ndash; ' . date_i18n(get_option('date_format'), strtotime($order->order_date));
                } else {
                    return '-';
                }
                break;
            case 'user_actions':
                ob_start();
                ?>
<p>
				<?php 
                do_action('fflcommerce_admin_user_actions_start', $user);
                $actions = array();
                $actions['refresh'] = array('url' => wp_nonce_url(add_query_arg('refresh', $user->ID), 'refresh'), 'name' => __('Refresh stats', 'fflcommerce'), 'action' => 'refresh');
                $actions['edit'] = array('url' => admin_url('user-edit.php?user_id=' . $user->ID), 'name' => __('Edit', 'fflcommerce'), 'action' => 'edit');
                $order_ids = $this->get_guest_orders();
                $order_ids = array_map(function ($order) {
                    return $order->ID;
                }, array_filter($order_ids, function ($order) use($user) {
                    return $order->data['billing_email'] == $user->user_email;
                }));
                if ($order_ids) {
                    $actions['link'] = array('url' => wp_nonce_url(add_query_arg('link_orders', $user->ID), 'link_orders'), 'name' => __('Link previous orders', 'fflcommerce'), 'action' => 'link');
                }
                $actions = apply_filters('fflcommerce_admin_user_actions', $actions, $user);
                foreach ($actions as $action) {
                    printf('<a class="button tips %s" href="%s" data-tip="%s">%s</a>', esc_attr($action['action']), esc_url($action['url']), esc_attr($action['name']), esc_attr($action['name']));
                }
                do_action('fflcommerce_admin_user_actions_end', $user);
                ?>
				</p><?php 
                $user_actions = ob_get_contents();
                ob_end_clean();
                return $user_actions;
        }
        return '';
    }
Ejemplo n.º 5
0
 /**
  * Successful payment processing
  *
  * @param array $posted
  */
 function successful_request($posted)
 {
     $posted = stripslashes_deep($posted);
     // 'custom' holds post ID (Order ID)
     if (!empty($posted['custom']) && !empty($posted['txn_type']) && !empty($posted['invoice'])) {
         $accepted_types = array('cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money', 'subscr_payment');
         $order = new fflcommerce_order((int) $posted['custom']);
         // Sandbox fix
         if (isset($posted['test_ipn']) && $posted['test_ipn'] == 1 && strtolower($posted['payment_status']) == 'pending') {
             $posted['payment_status'] = 'completed';
         }
         $merchant = $this->testmode == 'no' ? $this->email : $this->testemail;
         if ($order->status !== 'completed') {
             // We are here so lets check status and do actions
             switch (strtolower($posted['payment_status'])) {
                 case 'completed':
                     if (!in_array(strtolower($posted['txn_type']), $accepted_types)) {
                         // Put this order on-hold for manual checking
                         $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Unknown "txn_type" of "%s" for Order ID: %s.', 'fflcommerce'), $posted['txn_type'], $posted['custom']));
                         exit;
                     }
                     if ($order->get_order_number() !== $posted['invoice']) {
                         // Put this order on-hold for manual checking
                         $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Order Invoice Number does NOT match PayPal posted invoice (%s) for Order ID: .', 'fflcommerce'), $posted['invoice'], $posted['custom']));
                         exit;
                     }
                     // Validate Amount
                     if (number_format((double) $order->order_total, $this->decimals, '.', '') != $posted['mc_gross']) {
                         // Put this order on-hold for manual checking
                         $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Payment amounts do not match initial order (gross %s).', 'fflcommerce'), $posted['mc_gross']));
                         exit;
                     }
                     if (strcasecmp(trim($posted['business']), trim($merchant)) != 0) {
                         // Put this order on-hold for manual checking
                         $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Payment Merchant email received does not match PayPal Gateway settings. (%s)', 'fflcommerce'), $posted['business']));
                         exit;
                     }
                     if (!in_array($posted['mc_currency'], apply_filters('fflcommerce_multi_currencies_available', array(FFLCommerce_Base::get_options()->get('fflcommerce_currency'))))) {
                         // Put this order on-hold for manual checking
                         $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Payment currency received (%s) does not match Shop currency.', 'fflcommerce'), $posted['mc_currency']));
                         exit;
                     }
                     $order->add_order_note(__('PayPal Standard payment completed', 'fflcommerce'));
                     $order->payment_complete();
                     fflcommerce_log('PAYPAL: IPN payment completed for Order ID: ' . $posted['custom']);
                     break;
                 case 'denied':
                 case 'expired':
                 case 'failed':
                 case 'voided':
                     // Failed order
                     $order->update_status('failed', sprintf(__('Payment %s via IPN.', 'fflcommerce'), strtolower($posted['payment_status'])));
                     fflcommerce_log("PAYPAL: failed order with status = " . strtolower($posted['payment_status']) . "for Order ID: " . $posted['custom']);
                     break;
                 case 'refunded':
                 case 'reversed':
                 case 'chargeback':
                     fflcommerce_log("PAYPAL: payment status type - '" . $posted['payment_status'] . "' - not supported for Order ID: " . $posted['custom']);
                     break;
             }
         }
         exit;
     } else {
         fflcommerce_log("PAYPAL: function 'successful_request' -- empty initial required values -- EXITING!\n'posted' values = " . print_r($posted, true));
     }
 }
Ejemplo n.º 6
0
/**
 * 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()) . '">' . __('&larr; Continue Shopping', 'fflcommerce') . '</a></p>';
}
    /**
     * Recent Orders
     */
    function fflcommerce_dash_recent_orders()
    {
        $args = array('numberposts' => 10, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'shop_order', 'post_status' => 'publish');
        $orders = get_posts($args);
        if ($orders) {
            echo '<ul class="recent-orders">';
            foreach ($orders as $order) {
                $this_order = new fflcommerce_order($order->ID);
                $user = get_userdata($this_order->user_id);
                if ($user) {
                    $user = array('link' => get_edit_user_link($user->ID), 'name' => $user->display_name);
                } else {
                    $user = array('link' => '', 'name' => __('guest', 'fflcommerce'));
                }
                $total_items = 0;
                foreach ($this_order->items as $index => $item) {
                    $total_items += $item['qty'];
                }
                echo '
				<li>
					<span class="order-status ' . sanitize_title($this_order->status) . '">' . ucwords(__($this_order->status, 'fflcommerce')) . '</span> <a href="' . admin_url('post.php?post=' . $order->ID) . '&action=edit">' . $this_order->get_order_number() . '</a>
					<span class="order-time">' . get_the_time(__('M d, Y', 'fflcommerce'), $order->ID) . '</span> <span class="order-customer"><a href="' . $user['link'] . '">' . $user['name'] . '</a></span>
					<small>' . sizeof($this_order->items) . ' ' . _n('Item', 'Items', sizeof($this_order->items), 'fflcommerce') . ', <span class="total-quantity">' . __('Total Quantity', 'fflcommerce') . ' ' . $total_items . '</span> <span class="order-cost">' . fflcommerce_price($this_order->order_total) . '</span></small>
				</li>';
            }
            echo '</ul>';
        }
    }
Ejemplo n.º 8
0
function fflcommerce_ga_ecommerce_tracking($order_id)
{
    $options = FFLCommerce_Base::get_options();
    // Skip if disabled
    if ($options->get('fflcommerce_ga_ecommerce_tracking_enabled') != 'yes') {
        return;
    }
    // Don't track the shop owners roaming
    if (current_user_can('manage_fflcommerce')) {
        return;
    }
    $tracking_id = $options->get('fflcommerce_ga_id');
    if (!$tracking_id) {
        return;
    }
    // Get the order and output tracking code
    $order = new fflcommerce_order($order_id);
    ?>
	<script type="text/javascript">
		fflcommerceGA('require', 'ecommerce');

		fflcommerceGA('ecommerce:addTransaction', {
			'id': '<?php 
    echo $order->get_order_number();
    ?>
', // Transaction ID. Required.
			'affiliation': '<?php 
    bloginfo('name');
    ?>
', // Affiliation or store name.
			'revenue': '<?php 
    echo $order->order_total;
    ?>
', // Grand Total.
			'shipping': '<?php 
    echo $order->order_shipping;
    ?>
', // Shipping.
			'tax': '<?php 
    echo $order->get_total_tax();
    ?>
' // Tax.
		});

		<?php 
    foreach ($order->items as $item) {
        $_product = $order->get_product_from_item($item);
        ?>
		fflcommerceGA('ecommerce:addItem', {
			'id': '<?php 
        echo $order->get_order_number();
        ?>
', // Transaction ID. Required.
			'name': '<?php 
        echo $item['name'];
        ?>
', // Product name. Required.
			'sku': '<?php 
        echo $_product->sku;
        ?>
', // SKU/code.
			'category': '<?php 
        if (isset($_product->variation_data)) {
            echo fflcommerce_get_formatted_variation($_product, $item['variation'], true);
        }
        ?>
', // Category or variation.
			'price': '<?php 
        echo $item['cost'] / $item['qty'];
        ?>
', // Unit price.
			'quantity': '<?php 
        echo $item['qty'];
        ?>
' // Quantity.
		});
		<?php 
    }
    ?>

		fflcommerceGA('ecommerce:send');
	</script>
	<?php 
}
function fflcommerce_custom_order_columns($column)
{
    global $post;
    $fflcommerce_options = FFLCommerce_Base::get_options();
    $order = new fflcommerce_order($post->ID);
    switch ($column) {
        case "order_status":
            echo sprintf('<mark class="%s">%s</mark>', sanitize_title($order->status), __($order->status, 'fflcommerce'));
            break;
        case "order_title":
            echo '<a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '">' . sprintf(__('Order %s', 'fflcommerce'), $order->get_order_number()) . '</a>';
            echo '<time title="' . date_i18n(_x('c', 'date', 'fflcommerce'), strtotime($post->post_date)) . '">' . date_i18n(__('F j, Y, g:i a', 'fflcommerce'), strtotime($post->post_date)) . '</time>';
            break;
        case "customer":
            if ($order->user_id) {
                $user_info = get_userdata($order->user_id);
            }
            ?>
            <dl>
                <dt><?php 
            _e('User:'******'fflcommerce');
            ?>
</dt>
                <dd><?php 
            if (isset($user_info) && $user_info) {
                echo '<a href="user-edit.php?user_id=' . $user_info->ID . '">#' . $user_info->ID . ' &ndash; <strong>';
                if ($user_info->first_name || $user_info->last_name) {
                    echo $user_info->first_name . ' ' . $user_info->last_name;
                } else {
                    echo $user_info->display_name;
                }
                echo '</strong></a>';
            } else {
                _e('Guest', 'fflcommerce');
            }
            ?>
</dd>
                <?php 
            if ($order->billing_email) {
                ?>
<dt><?php 
                _e('Billing Email:', 'fflcommerce');
                ?>
</dt>
                    <dd><a href="mailto:<?php 
                echo $order->billing_email;
                ?>
"><?php 
                echo $order->billing_email;
                ?>
</a></dd><?php 
            }
            ?>
                <?php 
            if ($order->billing_phone) {
                ?>
<dt><?php 
                _e('Billing Phone:', 'fflcommerce');
                ?>
</dt>
                    <dd><?php 
                echo $order->billing_phone;
                ?>
</dd><?php 
            }
            ?>
            </dl>
            <?php 
            break;
        case "billing_address":
            echo '<strong>' . $order->billing_first_name . ' ' . $order->billing_last_name;
            if ($order->billing_company) {
                echo ', ' . $order->billing_company;
            }
            echo '</strong><br/>';
            echo '<a target="_blank" href="http://maps.google.co.uk/maps?&q=' . urlencode($order->formatted_billing_address) . '&z=16">' . $order->formatted_billing_address . '</a>';
            break;
        case "shipping_address":
            if ($order->formatted_shipping_address) {
                echo '<strong>' . $order->shipping_first_name . ' ' . $order->shipping_last_name;
                if ($order->shipping_company) {
                    echo ', ' . $order->shipping_company;
                }
                echo '</strong><br/>';
                echo '<a target="_blank" href="http://maps.google.co.uk/maps?&q=' . urlencode($order->formatted_shipping_address) . '&z=16">' . $order->formatted_shipping_address . '</a>';
            } else {
                echo '&ndash;';
            }
            break;
        case "billing_and_shipping":
            ?>
            <dl>
	              <?php 
            if ($order->payment_method_title) {
                ?>
                <dt><?php 
                _e('Payment:', 'fflcommerce');
                ?>
</dt>
                <dd><?php 
                echo $order->payment_method_title;
                ?>
</dd>
	              <?php 
            }
            ?>
	              <?php 
            if ($order->shipping_service) {
                ?>
                <dt><?php 
                _e('Shipping:', 'fflcommerce');
                ?>
</dt>
                <dd><?php 
                echo sprintf(__('%s', 'fflcommerce'), $order->shipping_service);
                ?>
</dd>
	              <?php 
            }
            ?>
            </dl>
            <?php 
            break;
        case "total_cost":
            ?>
            <table cellpadding="0" cellspacing="0" class="cost">
                <tr>
                    <?php 
            if ($fflcommerce_options->get('fflcommerce_calc_taxes') == 'yes' && $order->has_compound_tax() || $fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'yes' && $order->order_discount > 0) {
                ?>
                        <th><?php 
                _e('Retail Price', 'fflcommerce');
                ?>
</th>
                    <?php 
            } else {
                ?>
                        <th><?php 
                _e('Subtotal', 'fflcommerce');
                ?>
</th>
                    <?php 
            }
            ?>
                    <td><?php 
            echo fflcommerce_price($order->order_subtotal);
            ?>
</td>
                </tr>
                <?php 
            if ($order->order_shipping > 0) {
                ?>
<tr>
                        <th><?php 
                _e('Shipping', 'fflcommerce');
                ?>
</th>
                        <td><?php 
                echo fflcommerce_price($order->order_shipping);
                ?>
</td>
                    </tr>
                    <?php 
            }
            do_action('fflcommerce_processing_fee_after_shipping');
            if ($fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'yes' && $order->order_discount > 0) {
                ?>
                    <tr>
                        <th><?php 
                _e('Discount', 'fflcommerce');
                ?>
</th>
                        <td>-<?php 
                echo fflcommerce_price($order->order_discount);
                ?>
</td>
                    </tr>
                    <?php 
            }
            if ($fflcommerce_options->get('fflcommerce_calc_taxes') == 'yes' && $order->has_compound_tax() || $fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'yes' && $order->order_discount > 0) {
                ?>
<tr>
                        <th><?php 
                _e('Subtotal', 'fflcommerce');
                ?>
</th>
                        <td><?php 
                echo fflcommerce_price($order->order_discount_subtotal);
                ?>
</td>
                    </tr>
                    <?php 
            }
            if ($fflcommerce_options->get('fflcommerce_calc_taxes') == 'yes') {
                foreach ($order->get_tax_classes() as $tax_class) {
                    if ($order->show_tax_entry($tax_class)) {
                        ?>
                            <tr>
                                <th><?php 
                        echo $order->get_tax_class_for_display($tax_class) . ' (' . (double) $order->get_tax_rate($tax_class) . '%):';
                        ?>
</th>
                                <td><?php 
                        echo $order->get_tax_amount($tax_class);
                        ?>
</td>
                            </tr>
                            <?php 
                    }
                }
            }
            if ($fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'no' && $order->order_discount > 0) {
                ?>
<tr>
                        <th><?php 
                _e('Discount', 'fflcommerce');
                ?>
</th>
                        <td>-<?php 
                echo fflcommerce_price($order->order_discount);
                ?>
</td>
                    </tr><?php 
            }
            ?>
                <tr>
                    <th><?php 
            _e('Total', 'fflcommerce');
            ?>
</th>
                    <td><?php 
            echo fflcommerce_price($order->order_total);
            ?>
</td>
                </tr>
            </table>
            <?php 
            break;
        case 'order_coupons':
            if (!empty($order->order_discount_coupons)) {
                foreach ($order->order_discount_coupons as $used_coupon) {
                    ?>
			           <p class="order_coupon"><?php 
                    echo '#' . $used_coupon['id'] . ' - ' . $used_coupon['code'];
                    ?>
</p>
				<?php 
                }
            }
            break;
    }
}
Ejemplo n.º 10
0
    /**
     *  Generate the futurepay payment iframe
     */
    protected function call_futurepay($order_id)
    {
        // Get the order
        $order = new fflcommerce_order($order_id);
        $data = array('gmid' => $this->gmid, 'reference' => $order_id . '-' . uniqid(), 'email' => $order->billing_email, 'first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'company' => $order->billing_company, 'address_line_1' => $order->billing_address_1, 'address_line_2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'country' => $order->billing_country, 'zip' => $order->billing_postcode, 'phone' => $order->billing_phone, 'shipping_address_line_1' => $order->shipping_address_1, 'shipping_address_line_2' => $order->shipping_address_2, 'shipping_city' => $order->shipping_city, 'shipping_state' => $order->shipping_state, 'shipping_country' => $order->shipping_country, 'shipping_zip' => $order->shipping_postcode, 'shipping_date' => date('Y/m/d g:i:s'));
        // for FFL Commerce 1.0, FuturePay doesn't allow negative prices (or 0.00 ) which affects discounts
        // with FuturePay doing the calcs, so we will bundle all products into ONE line item with
        // a quantity of ONE and send it that way using the final order total after shipping
        // and discounts are applied
        // all product titles will be comma delimited with their quantities
        $item_names = array();
        if (sizeof($order->items) > 0) {
            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[] = $item['qty'] . ' x ' . $title;
            }
        }
        // now add the one line item to the necessary product field arrays
        $data['sku'][] = "Products";
        $data['price'][] = $order->order_total;
        // futurepay only needs final order amount
        $data['tax_amount'][] = 0;
        $data['description'][] = sprintf(__('Order %s', 'fflcommerce'), $order->get_order_number()) . ' = ' . implode(', ', $item_names);
        $data['quantity'][] = 1;
        try {
            $response = wp_remote_post(self::$request_url . 'merchant-request-order-token', array('body' => http_build_query($data), 'sslverify' => false));
            // Convert error to exception
            if (is_wp_error($response)) {
                if (class_exists('WP_Exception') && $response instanceof WP_Exception) {
                    throw $response;
                } else {
                    fflcommerce_log($response->get_error_message());
                    throw new Exception($response->get_error_message());
                }
            }
            // Fetch the body from the result, any errors should be caught before proceeding
            $response = trim(wp_remote_retrieve_body($response));
            // we need something to validate the response.  Valid transactions begin with 'FPTK'
            if (!strstr($response, 'FPTK')) {
                $error_message = isset(self::$futurepay_errorcodes[$response]) ? self::$futurepay_errorcodes[$response] : __('An unknown error has occured with code = ', 'fflcommerce') . $response;
                $order->add_order_note(sprintf(__('FUTUREPAY: %s', 'fflcommerce'), $error_message));
                fflcommerce::add_error(sprintf(__('FUTUREPAY: %s.  Please try again or select another gateway for your Order.', 'fflcommerce'), $error_message));
                wp_safe_redirect(get_permalink(fflcommerce_get_page_id('checkout')));
                exit;
            }
            /**
             *  If we're good to go, haul in FuturePay's javascript and display the payment form
             *  so that the customer can enter his ID and password
             */
            echo '<div id="futurepay"></div>';
            echo '<script src="' . self::$request_url . 'cart-integration/' . $response . '"></script>';
            echo '<script type="text/javascript">
				/*<![CDATA[*/
				jQuery(window).load( function() {
					FP.CartIntegration();

					// Need to replace form html
					jQuery("#futurepay").html(FP.CartIntegration.getFormContent());
					FP.CartIntegration.displayFuturePay();
				});

				function FuturePayResponseHandler(response) {
					if (response.error) {
						// TODO: we need something better than this
						alert(response.code + " " + response.message);
					}
					else {
						window.location.replace("./?futurepay="+response.transaction_id);
					}

				}
				/*]]>*/
			</script>';
            echo '<input type="button" class="button alt" name="place_order" id="place_order" value="Place Order" onclick="FP.CartIntegration.placeOrder();" />';
        } catch (Exception $e) {
            echo '<div class="fflcommerce_error">' . $e->getMessage() . '</div>';
            fflcommerce_log('FUTUREPAY ERROR: ' . $e->getMessage());
        }
    }