Пример #1
0
 /**
  * Implements WC_Pricefile_Generator->print_product()= and echoes a formatted product
  * 
  * @param     array  An opaque object used by property getters.
  * @since    0.1.12
  */
 protected function print_product($product)
 {
     if (WC_Pricefiles()->get_options()['prisjakt_referrals']) {
         $url = add_query_arg('ref', 'prisjakt', $product->get_url());
     } else {
         $url = $product->get_url();
     }
     echo $this::format_value($product->get_title());
     echo $this::format_value($product->get_sku());
     echo $this::format_value($product->get_ean());
     echo $this::format_value($product->get_manufacturer());
     echo $this::format_value($product->get_manufacturer_sku());
     echo $this::format_value($product->get_categories());
     echo $this::format_value($product->get_price());
     echo $this::format_value($product->get_shipping_cost());
     echo $this::format_value($url);
     echo $this::format_value($product->get_image_url());
     echo $this::format_value($product->get_stock_status());
     echo $this::format_value($product->get_prisjakt_status());
     echo "\n";
 }
Пример #2
0
 * Author URI:  http://elmered.com
 * Text Domain: woocommerce-pricefiles
 * Domain Path: /languages
 * License:     GPL-2.0+
 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
 */
/*
//For debuging
error_reporting(E_ALL);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
*/
// If this file is called directly, abort.
if (!defined('WPINC')) {
    die;
}
require 'define.php';
define('WP_PRICEFILES_PLUGIN_NAME', untrailingslashit(plugin_basename(__FILE__)));
if (!class_exists('WC_Pricefiles')) {
    require_once WP_PRICEFILES_PLUGIN_PATH . 'includes/pricefiles.php';
}
add_action('plugins_loaded', 'WC_Pricefiles');
// Register hooks that are fired when the plugin is activated, deactivated, and uninstalled, respectively.
register_activation_hook(__FILE__, array(WC_Pricefiles(), 'activate'));
//Deletes all data if plugin deactivated
register_deactivation_hook(__FILE__, array(WC_Pricefiles(), 'deactivate'));
function WC_Pricefiles()
{
    require_once WP_PRICEFILES_PLUGIN_PATH . 'includes/pricefiles.php';
    return WC_Pricefiles::get_instance();
}
Пример #3
0
 /**
  * This function is a hack to calculate the shipping cost for a single product. To do this we must first build a cart object and after that a package object that is needed to calculate the price. 
  * TODO: This need to be revisited. Has been improved, but not perfect
  * 
  * @global  object  $woocommerce
  * @param   object  $product Product object
  * @return  float   Lowest shipping price
  */
 public function get_shipping_cost()
 {
     // Packages array for storing package/cart object
     $packages = array();
     $product = $this->product;
     $price = $product->get_price_excluding_tax(1);
     $price_tax = $product->get_price_including_tax(1) - $price;
     // Build up a fake package object
     $cart = array('product_id' => $product->id, 'variation_id' => '', 'variation' => '', 'quantity' => 1, 'data' => $product, 'line_total' => $price, 'line_tax' => $price_tax, 'line_subtotal' => $price, 'line_subtotal_tax' => $price_tax);
     // Items in the package
     $packages[0]['contents'][md5('wc_pricefiles_' . $product->id . $price)] = $cart;
     // Cost of items in the package, set below
     $packages[0]['contents_cost'] = $price;
     // Applied coupons - some, like free shipping, affect costs
     $packages[0]['applied_coupons'] = '';
     // Fake destination address. Needed for calculation the shipping
     $packages[0]['destination'] = WC_Pricefiles()->get_shipping_destination();
     // Apply filters to mimic normal behaviour
     $packages = apply_filters('woocommerce_cart_shipping_packages', $packages);
     $package = $packages[0];
     // Calculate the shipping using our fake package object
     $shipping_method_rates = WC()->shipping->calculate_shipping_for_package($package);
     $shipping_methods = WC_Pricefiles()->get_shipping_methods();
     $lowest_shipping_cost = 0;
     if (!empty($shipping_methods)) {
         //$shipping_methods = array_intersect_key($shipping_method_rates['rates'], $this->shipping_methods);
         foreach ($shipping_method_rates['rates'] as $rate) {
             if (in_array($rate->method_id, $shipping_methods)) {
                 $total_tax = 0;
                 if (WC_Pricefiles()->get_price_type() == 'incl') {
                     //Sum the taxes
                     foreach ($rate->taxes as $tax) {
                         $total_tax += $tax;
                     }
                     //Calc shipping cost including tax
                     $total_cost = $rate->cost + $total_tax;
                 } else {
                     $total_cost = $rate->cost;
                 }
                 if (empty($lowest_shipping_cost) || $total_cost < $lowest_shipping_cost) {
                     $lowest_shipping_cost = $total_cost;
                 }
             }
         }
     }
     return $lowest_shipping_cost;
 }
Пример #4
0
 function shipping_destination_callback($args)
 {
     echo '<p>' . $args['description'] . '</p>';
     echo '<div id="shipping-destination">';
     $shipping_destination_values = $this->plugin_options['shipping_destination'];
     if (!$shipping_destination_values) {
         global $wc_pricefiles_globals;
         $shipping_destination_values = $wc_pricefiles_globals['default_shipping_destination'];
     }
     $shipping_fields = WC_Pricefiles()->get_shipping_destination_fields();
     foreach ($shipping_fields as $key => $field) {
         $field['required'] = 0;
         woocommerce_form_field($this->plugin_slug . '_options[shipping_destination][' . $key . ']', $field, $shipping_destination_values[$key]);
     }
     echo '</div>';
 }
Пример #5
0
 /**
  * Get price tax display option. I.e. whether we should out put prices including or excluding tax  
  *
  * @return  string  'incl' or 'excl'
  * @since   0.1.10
  */
 public function get_price_type()
 {
     if (!empty($this->cache_data['price_type'])) {
         return $this->cache_data['price_type'];
     }
     $options = WC_Pricefiles()->get_options();
     if ($options['output_prices'] == 'shop') {
         $wc_option = get_option('woocommerce_tax_display_cart');
         if (!empty($wc_option)) {
             $this->cache_data['price_type'] = $wc_option;
             return $this->cache_data['price_type'];
         }
     }
     if (!empty($options['output_prices'])) {
         $this->cache_data['price_type'] = $options['output_prices'];
         return $this->cache_data['price_type'];
     } else {
         $this->cache_data['price_type'] = 'incl';
         return $this->cache_data['price_type'];
     }
 }