/**
  * Get the legend for the main chart sidebar
  * @return array
  */
 public function get_chart_legend()
 {
     $legend = array();
     $order_totals = $this->get_order_report_data(array('data' => array('_order_total' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_sales'), '_order_shipping' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_shipping'), 'ID' => array('type' => 'post_data', 'function' => 'COUNT', 'name' => 'total_orders')), 'filter_range' => true));
     $total_sales = $order_totals->total_sales;
     $total_shipping = $order_totals->total_shipping;
     $total_orders = absint($order_totals->total_orders);
     $total_items = absint($this->get_order_report_data(array('data' => array('_qty' => array('type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'order_item_qty')), 'query_type' => 'get_var', 'filter_range' => true)));
     // Get discount amounts in range
     $total_coupons = $this->get_order_report_data(array('data' => array('discount_amount' => array('type' => 'order_item_meta', 'order_item_type' => 'coupon', 'function' => 'SUM', 'name' => 'discount_amount')), 'where' => array(array('key' => 'order_item_type', 'value' => 'coupon', 'operator' => '=')), 'query_type' => 'get_var', 'filter_range' => true));
     $this->average_sales = $total_sales / ($this->chart_interval + 1);
     switch ($this->chart_groupby) {
         case 'day':
             $average_sales_title = sprintf(__('%s average daily sales', 'woocommerce'), '<strong>' . wc_price($this->average_sales) . '</strong>');
             break;
         case 'month':
             $average_sales_title = sprintf(__('%s average monthly sales', 'woocommerce'), '<strong>' . wc_price($this->average_sales) . '</strong>');
             break;
     }
     $legend[] = array('title' => sprintf(__('%s sales in this period', 'woocommerce'), '<strong>' . wc_price($total_sales) . '</strong>'), 'color' => $this->chart_colours['sales_amount'], 'highlight_series' => 5);
     $legend[] = array('title' => $average_sales_title, 'color' => $this->chart_colours['average'], 'highlight_series' => 2);
     $legend[] = array('title' => sprintf(__('%s orders placed', 'woocommerce'), '<strong>' . $total_orders . '</strong>'), 'color' => $this->chart_colours['order_count'], 'highlight_series' => 1);
     $legend[] = array('title' => sprintf(__('%s items purchased', 'woocommerce'), '<strong>' . $total_items . '</strong>'), 'color' => $this->chart_colours['item_count'], 'highlight_series' => 0);
     $legend[] = array('title' => sprintf(__('%s charged for shipping', 'woocommerce'), '<strong>' . wc_price($total_shipping) . '</strong>'), 'color' => $this->chart_colours['shipping_amount'], 'highlight_series' => 4);
     $legend[] = array('title' => sprintf(__('%s worth of coupons used', 'woocommerce'), '<strong>' . wc_price($total_coupons) . '</strong>'), 'color' => $this->chart_colours['coupon_amount'], 'highlight_series' => 3);
     return $legend;
 }
Ejemplo n.º 2
0
 /**
  * Test wc_cart_totals_subtotal_html()
  *
  * @todo  test with taxes incl./excl.
  * @since 2.4
  */
 public function test_wc_cart_totals_subtotal_html()
 {
     $product = \WC_Helper_Product::create_simple_product();
     WC()->cart->add_to_cart($product->id, 1);
     $this->expectOutputString(wc_price($product->price), wc_cart_totals_subtotal_html());
     \WC_Helper_Product::delete_product($product->id);
 }
 /**
  * Get the legend for the main chart sidebar
  * @return array
  */
 public function get_chart_legend()
 {
     if (!$this->show_categories) {
         return array();
     }
     $legend = array();
     $index = 0;
     foreach ($this->show_categories as $category) {
         $category = get_term($category, 'product_cat');
         $term_ids = get_term_children($category->term_id, 'product_cat');
         $term_ids[] = $category->term_id;
         $total = 0;
         $product_ids = array_unique(get_objects_in_term($term_ids, 'product_cat'));
         foreach ($product_ids as $id) {
             if (isset($this->item_sales[$id])) {
                 $total += $this->item_sales[$id];
             }
         }
         //if ( ! $total )
         //	continue;
         $legend[] = array('title' => sprintf(__('%s sales in %s', 'woocommerce'), '<strong>' . wc_price($total) . '</strong>', $category->name), 'color' => isset($this->chart_colours[$index]) ? $this->chart_colours[$index] : $this->chart_colours[0], 'highlight_series' => $index);
         $index++;
     }
     return $legend;
 }
 function column_default($item, $column_name)
 {
     global $CPT_Product, $post, $the_product;
     if (is_null($post) || (int) $item->ID != (int) $post->ID) {
         $post = get_post($item->ID);
         if (is_null($post)) {
             return;
         }
     }
     switch ($column_name) {
         case 'thumb':
         case 'name':
         case 'sku':
         case 'is_in_stock':
         case 'price':
         case 'product_cat':
         case 'product_type':
         case 'date':
         case 'crm_actions':
             return $CPT_Product->render_product_columns($column_name);
         case 'number_purchased':
             return $item->items_count;
             break;
         case 'value_purchases':
             return wc_price($item->line_total);
         default:
             return print_r($item, true);
             //Show the whole array for troubleshooting purposes
     }
 }
 public static function woocommerce_grouped_price_html($price, $product)
 {
     $tax_display_mode = get_option('woocommerce_tax_display_shop');
     $child_prices = array();
     foreach ($product->get_children() as $child_id) {
         //$child_prices[] = get_post_meta( $child_id, '_price', true );
         $child = get_product($child_id);
         $child_prices[] = $child->get_price();
     }
     $child_prices = array_unique($child_prices);
     $get_price_method = 'get_price_' . $tax_display_mode . 'uding_tax';
     if (!empty($child_prices)) {
         $min_price = min($child_prices);
         $max_price = max($child_prices);
     } else {
         $min_price = '';
         $max_price = '';
     }
     if ($min_price) {
         if ($min_price == $max_price) {
             $display_price = wc_price($product->{$get_price_method}(1, $min_price));
         } else {
             $from = wc_price($product->{$get_price_method}(1, $min_price));
             $to = wc_price($product->{$get_price_method}(1, $max_price));
             $display_price = sprintf(_x('%1$s&ndash;%2$s', 'Price range: from-to', 'woocommerce'), $from, $to);
         }
         $price = $display_price . $product->get_price_suffix();
     }
     return $price;
 }
 /**
  * Get the legend for the main chart sidebar
  * @return array
  */
 public function get_chart_legend()
 {
     $legend = array();
     $total_orders = $this->get_order_report_data(array('data' => array('ID' => array('type' => 'post_data', 'function' => 'COUNT', 'name' => 'total_orders')), 'query_type' => 'get_var', 'filter_range' => true));
     $total_sales = $this->get_order_report_data(array('data' => array('_line_subtotal' => array('type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'total_item_sales')), 'query_type' => 'get_var', 'filter_range' => true));
     $total_items = absint($this->get_order_report_data(array('data' => array('_qty' => array('type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'order_item_qty')), 'query_type' => 'get_var', 'filter_range' => true)));
     $total_cog = $this->get_order_report_data(array('data' => array('_line_funkwoocost_order' => array('type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'total_cog')), 'query_type' => 'get_var', 'filter_range' => true));
     $total_profit = $total_sales - $total_cog;
     $total_profit < 0 ? $total_profit = 0 : 0;
     $this->average_sales = $total_sales / ($this->chart_interval + 1);
     switch ($this->chart_groupby) {
         case 'day':
             $average_sales_title = sprintf(__('%s average daily sales', 'woocommerce'), '<strong>' . wc_price($this->average_sales) . '</strong>');
             break;
         case 'month':
             $average_sales_title = sprintf(__('%s average monthly sales', 'woocommerce'), '<strong>' . wc_price($this->average_sales) . '</strong>');
             break;
     }
     $legend[] = array('title' => sprintf(__('%s item sales in this period', 'funkwoocost'), '<strong>' . wc_price($total_sales) . '</strong>'), 'placeholder' => __('This is the sum of the order totals after any refunds and excluding shipping and taxes.', 'funkwoocost'), 'color' => $this->chart_colours['sales_amount'], 'highlight_series' => 4);
     $legend[] = array('title' => sprintf(__('%s item profits in this period', 'funkwoocost'), '<strong>' . wc_price($total_profit) . '</strong>'), 'placeholder' => __('This is the sum of the order totals after deducting by cost of goods, any refunds and excluding shipping and taxes.', 'funkwoocost'), 'color' => $this->chart_colours['profit_amount'], 'highlight_series' => 3);
     $legend[] = array('title' => $average_sales_title, 'color' => $this->chart_colours['average'], 'highlight_series' => 2);
     $legend[] = array('title' => sprintf(__('%s orders placed', 'woocommerce'), '<strong>' . $total_orders . '</strong>'), 'color' => $this->chart_colours['order_count'], 'highlight_series' => 1);
     $legend[] = array('title' => sprintf(__('%s items purchased', 'woocommerce'), '<strong>' . $total_items . '</strong>'), 'color' => $this->chart_colours['item_count'], 'highlight_series' => 0);
     return $legend;
 }
 /**
  * return user balance formated as dollars
  * @return [type] [description]
  */
 function get_user_balance()
 {
     $current_user_balance = get_user_meta($_POST['user_id'], '_uw_balance', true);
     $return = array('status' => true, 'balance' => wc_price($current_user_balance));
     print json_encode($return);
     exit;
 }
 /**
  * Gets order total - formatted for display.
  *
  * @return string
  */
 public function get_formatted_order_total($tax_display = '', $display_refunded = true)
 {
     $formatted_total = wc_price($this->get_total(), array('currency' => $this->get_order_currency()));
     $order_total = $this->get_total();
     $total_refunded = $this->get_total_refunded();
     $tax_string = '';
     // Tax for inclusive prices
     if (wc_tax_enabled() && 'incl' == $tax_display) {
         $tax_string_array = array();
         if ('itemized' == get_option('woocommerce_tax_total_display')) {
             foreach ($this->get_tax_totals() as $code => $tax) {
                 $tax_amount = $total_refunded && $display_refunded ? wc_price(WC_Tax::round($tax->amount - $this->get_total_tax_refunded_by_rate_id($tax->rate_id)), array('currency' => $this->get_order_currency())) : $tax->formatted_amount;
                 $tax_string_array[] = sprintf('%s %s', $tax_amount, $tax->label);
             }
         } else {
             $tax_amount = $total_refunded && $display_refunded ? $this->get_total_tax() - $this->get_total_tax_refunded() : $this->get_total_tax();
             $tax_string_array[] = sprintf('%s %s', wc_price($tax_amount, array('currency' => $this->get_order_currency())), WC()->countries->tax_or_vat());
         }
         if (!empty($tax_string_array)) {
             $tax_string = ' ' . sprintf(__('(Includes %s)', 'woocommerce'), implode(', ', $tax_string_array));
         }
     }
     if ($total_refunded && $display_refunded) {
         $formatted_total = '<del>' . strip_tags($formatted_total) . '</del> <ins>' . wc_price($order_total - $total_refunded, array('currency' => $this->get_order_currency())) . $tax_string . '</ins>';
     } else {
         $formatted_total .= $tax_string;
     }
     return apply_filters('woocommerce_get_formatted_order_total', $formatted_total, $this);
 }
Ejemplo n.º 9
0
function wc_minimum_order_amount()
{
    global $woocommerce;
    $postcode = get_user_meta(get_current_user_id(), 'shipping_postcode', true);
    if (strstr(' 90024 90027 90028 90029 90034 90036 90038 90039 90046 90048 90064 90066 90067 90068 90069 90095 90230 90291 90401 90402 90403 90404 90405 91505 91506 91602 91604 91607 91608 90010 90012 90019 90020 90025 90232 91601 91606 90073 90031 90090 90005 90004 90026 90035 90056 90211 90212 ', $postcode)) {
        $minimum = 60;
    } else {
        if (strstr(' 90045 90049 90016 90292 91423 90008 90018 90045 90049 90210 90245 90272 90293 90077 90094 91403 91436 90079 90210 90007 90015 90017 90057 90071 90089 90266 90013 90014 ', $postcode)) {
            $minimum = 100;
        } else {
            $minimum = false;
        }
    }
    if ($minimum == false) {
        wc_print_notice(sprintf('We are unable to service your area at this time. Please give us a call at (323) 450-7708 to discuss arrangements for your delivery.', wc_price($minimum), wc_price(WC()->cart->subtotal)), 'error');
        echo "<script>\n\t\t\t\tjQuery(document).ready(function(\$) {\n\t\t\t\t\t\$('.checkout-button').addClass('disabled');\n\t\t\t\t\t\$('.checkout-button').click(function(e) { e.preventDefault(); });\n\t\t\t\t});\n\t\t\t</script>";
    } elseif (WC()->cart->subtotal < $minimum) {
        if (is_cart()) {
            wc_print_notice(sprintf('Based on your zip code ' . $postcode . ', you must have an order with a minimum of %s to checkout. Your current order total is %s.', wc_price($minimum), wc_price(WC()->cart->subtotal)), 'error');
            echo "\n\t\t\t\t<script>\n\t\t\t\t\tjQuery(document).ready(function(\$) {\n\t\t\t\t\t\t\$('.checkout-button').addClass('disabled');\n\t\t\t\t\t\t\$('.checkout-button').click(function(e) { e.preventDefault(); });\n\t\t\t\t\t});\n\t\t\t\t</script>";
        } else {
            wc_add_notice(sprintf('Based on your zip code ' . $postcode . ', you must have an order with a minimum of %s to checkout. Your current order total is %s.', wc_price($minimum), wc_price(WC()->cart->subtotal)), 'error');
        }
    }
}
function francotecnologia_wc_parcpagseg_get_parceled_table($price = null)
{
    $price = francotecnologia_wc_parcpagseg_get_price($price);
    if ($price > 0) {
        $installments = francotecnologia_wc_parcpagseg_get_installments($price);
        $table = '<table class="francotecnologia_wc_parcpagseg_table">';
        $table .= '<tr>';
        $table .= str_repeat('<th>Parcelas</th><th>Valor</th>', $installments > 1 ? 2 : 1);
        $table .= '</tr>';
        foreach (range(1, $installments) as $parcel) {
            $calc = francotecnologia_wc_parcpagseg_calculate_installment($price, $parcel);
            if ($parcel % 2 == 1) {
                $table .= '<tr>';
            }
            $table .= '<th>' . $parcel . '</th><td>' . wc_price($calc->price) . '</td>';
            if ($parcel % 2 == 0) {
                $table .= '</tr>';
            }
        }
        if (substr($table, -5) != '</tr>') {
            $table .= '</tr>';
        }
        $table .= '</table>';
        return $table;
    } else {
        return '';
    }
}
 /**
  * Get the legend for the main chart sidebar
  * @return array
  */
 public function get_chart_legend()
 {
     $legend = array();
     $total_orders = absint($this->get_order_report_data(array('data' => array('ID' => array('type' => 'post_data', 'function' => 'COUNT', 'name' => 'total_orders')), 'query_type' => 'get_var', 'filter_range' => true, 'order_types' => wc_get_order_types('order-count'), 'order_status' => array('completed', 'processing', 'on-hold', 'refunded'))));
     $total_items = absint($this->get_order_report_data(array('data' => array('_qty' => array('type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'order_item_qty')), 'query_type' => 'get_var', 'order_types' => wc_get_order_types('order-count'), 'order_status' => array('completed', 'processing', 'on-hold', 'refunded'), 'filter_range' => true)));
     $total_coupons = $this->get_order_report_data(array('data' => array('discount_amount' => array('type' => 'order_item_meta', 'order_item_type' => 'coupon', 'function' => 'SUM', 'name' => 'discount_amount')), 'where' => array(array('key' => 'order_items.order_item_type', 'value' => 'coupon', 'operator' => '=')), 'query_type' => 'get_var', 'order_types' => wc_get_order_types('order-count'), 'order_status' => array('completed', 'processing', 'on-hold', 'refunded'), 'filter_range' => true));
     $order_totals = $this->get_order_report_data(array('data' => array('_order_total' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_sales'), '_order_shipping' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_shipping'), '_order_tax' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_tax'), '_order_shipping_tax' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_shipping_tax')), 'order_types' => wc_get_order_types('sales-reports'), 'order_status' => array('completed', 'processing', 'on-hold', 'refunded'), 'filter_range' => true));
     $partial_refunds = $this->get_order_report_data(array('data' => array('_refund_amount' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_refund')), 'query_type' => 'get_var', 'order_types' => array('shop_order_refund'), 'filter_range' => true, 'order_status' => false, 'parent_order_status' => array('completed', 'processing', 'on-hold')));
     $full_refunds = $this->get_order_report_data(array('data' => array('_order_total' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_sales')), 'query_type' => 'get_var', 'order_types' => wc_get_order_types('sales-reports'), 'order_status' => array('refunded'), 'filter_range' => true));
     $total_sales = $order_totals->total_sales;
     $total_shipping = $order_totals->total_shipping;
     $total_tax = $order_totals->total_tax;
     $total_shipping_tax = $order_totals->total_shipping_tax;
     $net_sales = $order_totals->total_sales - $total_shipping - $total_tax - $total_shipping_tax;
     $total_refunds = $partial_refunds + $full_refunds;
     $this->average_sales = $total_sales / ($this->chart_interval + 1);
     switch ($this->chart_groupby) {
         case 'day':
             $average_sales_title = sprintf(__('%s average daily sales', 'woocommerce'), '<strong>' . wc_price($this->average_sales) . '</strong>');
             break;
         case 'month':
         default:
             $average_sales_title = sprintf(__('%s average monthly sales', 'woocommerce'), '<strong>' . wc_price($this->average_sales) . '</strong>');
             break;
     }
     $legend[] = array('title' => sprintf(__('%s gross sales in this period', 'woocommerce'), '<strong>' . wc_price($total_sales) . '</strong>'), 'placeholder' => __('This is the sum of the order totals, including shipping and taxes. This does not include refunds.', 'woocommerce'), 'color' => $this->chart_colours['sales_amount'], 'highlight_series' => 6);
     $legend[] = array('title' => sprintf(__('%s net sales in this period', 'woocommerce'), '<strong>' . wc_price($net_sales) . '</strong>'), 'placeholder' => __('This is the net sales figure excluding shipping and taxes. This does not include refunds.', 'woocommerce'), 'color' => $this->chart_colours['net_sales_amount'], 'highlight_series' => 7);
     $legend[] = array('title' => $average_sales_title, 'color' => $this->chart_colours['average'], 'highlight_series' => 2);
     $legend[] = array('title' => sprintf(__('%s orders placed', 'woocommerce'), '<strong>' . $total_orders . '</strong>'), 'color' => $this->chart_colours['order_count'], 'highlight_series' => 1);
     $legend[] = array('title' => sprintf(__('%s items purchased', 'woocommerce'), '<strong>' . $total_items . '</strong>'), 'color' => $this->chart_colours['item_count'], 'highlight_series' => 0);
     $legend[] = array('title' => sprintf(__('%s charged for shipping', 'woocommerce'), '<strong>' . wc_price($total_shipping) . '</strong>'), 'color' => $this->chart_colours['shipping_amount'], 'highlight_series' => 5);
     $legend[] = array('title' => sprintf(__('%s in refunds', 'woocommerce'), '<strong>' . wc_price($total_refunds) . '</strong>'), 'color' => $this->chart_colours['refund_amount'], 'highlight_series' => 4);
     $legend[] = array('title' => sprintf(__('%s worth of coupons used', 'woocommerce'), '<strong>' . wc_price($total_coupons) . '</strong>'), 'color' => $this->chart_colours['coupon_amount'], 'highlight_series' => 3);
     return $legend;
 }
 /**
  * Get the legend for the main chart sidebar
  * @return array
  */
 public function get_chart_legend()
 {
     $legend = array();
     $total_sales = $this->get_order_report_data(array('data' => array('et_order_total' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_sales')), 'query_type' => 'get_var', 'order_types' => array('order'), 'order_status' => array('publish'), 'filter_range' => true));
     $total_pending = $this->get_order_report_data(array('data' => array('et_order_total' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_sales'), 'ID' => array('type' => 'post_data', 'function' => 'COUNT', 'name' => 'total_orders')), 'query_type' => 'get_row', 'order_types' => array('order'), 'order_status' => array('pending'), 'filter_range' => true));
     $total_draft = $this->get_order_report_data(array('data' => array('et_order_total' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_sales'), 'ID' => array('type' => 'post_data', 'function' => 'COUNT', 'name' => 'total_orders')), 'query_type' => 'get_row', 'order_types' => array('order'), 'order_status' => array('draft'), 'filter_range' => true));
     $total_paid = absint($this->get_order_report_data(array('data' => array('ID' => array('type' => 'post_data', 'function' => 'COUNT', 'name' => 'total_orders')), 'query_type' => 'get_var', 'filter_range' => true, 'order_types' => array('order'), 'order_status' => array('publish'))));
     $this->average_sales = $total_sales / ($this->chart_interval + 1);
     switch ($this->chart_groupby) {
         case 'day':
             $average_sales_title = sprintf(__('%s average daily sales', 'woocommerce'), '<strong>' . wc_price($this->average_sales) . '</strong>');
             break;
         case 'month':
             $average_sales_title = sprintf(__('%s average monthly sales', 'woocommerce'), '<strong>' . wc_price($this->average_sales) . '</strong>');
             break;
     }
     $legend[] = array('title' => sprintf(__('%s sales in this period', 'woocommerce'), '<strong>' . wc_price($total_sales) . '</strong>'), 'color' => $this->chart_colours['sales_amount'], 'highlight_series' => 4);
     $legend[] = array('title' => sprintf(__('%s Pending sales', 'woocommerce'), '<strong>' . wc_price($total_pending->total_sales) . '</strong>'), 'color' => $this->chart_colours['sales_pending'], 'highlight_series' => 6);
     $legend[] = array('title' => sprintf(__('%s draft sales', 'woocommerce'), '<strong>' . wc_price($total_draft->total_sales) . '</strong>'), 'color' => $this->chart_colours['sales_draft'], 'highlight_series' => 5);
     $legend[] = array('title' => $average_sales_title, 'color' => $this->chart_colours['average'], 'highlight_series' => 3);
     $legend[] = array('title' => sprintf(__('%s paid orders', 'woocommerce'), '<strong>' . $total_paid . '</strong>'), 'color' => $this->chart_colours['order_count'], 'highlight_series' => 0);
     $legend[] = array('title' => sprintf(__('%s pending orders', 'woocommerce'), '<strong>' . $total_pending->total_orders . '</strong>'), 'color' => $this->chart_colours['order_pending'], 'highlight_series' => 2);
     $legend[] = array('title' => sprintf(__('%s draft orders', 'woocommerce'), '<strong>' . $total_draft->total_orders . '</strong>'), 'color' => $this->chart_colours['order_draft'], 'highlight_series' => 1);
     return $legend;
 }
function wc_autoship_upsell_cart_item_name($name, $item, $item_key)
{
    if (!is_cart()) {
        return $name;
    }
    $product_id = $item['product_id'];
    $autoship_enabled = get_post_meta($product_id, '_wc_autoship_enable_autoship', true);
    if ($autoship_enabled != 'yes') {
        // No autoship
        return $name;
    }
    $var_product_id = !empty($item['variation_id']) ? $item['variation_id'] : $item['product_id'];
    $product = wc_get_product($var_product_id);
    $price = $product->get_price();
    $autoship_price = (double) apply_filters('wc_autoship_price', get_post_meta($var_product_id, '_wc_autoship_price', true), $var_product_id, 0, get_current_user_id(), 0);
    $diff = $product->get_price() - $autoship_price;
    $upsell_title = '';
    $upsell_class = '';
    if (isset($item['wc_autoship_frequency'])) {
        $upsell_title = __('<span class="wc-autoship-upsell-icon">&#9998;</span> Change Auto-Ship', 'wc-autoship-upsell');
        $upsell_class = 'wc-autoship-upsell-change-autoship';
    } elseif ($autoship_price > 0 && $diff > 0) {
        $upsell_title = __('<span class="wc-autoship-upsell-icon">&plus;</span>Save ' . wc_price($diff) . ' with Auto-Ship', 'wc-autoship-upsell');
        $upsell_class = 'wc-autoship-upsell-add-autoship-savings';
    } else {
        $upsell_title = __('<span class="wc-autoship-upsell-icon">&plus;</span>Add to Auto-Ship', 'wc-autoship-upsell');
        $upsell_class = 'wc-autoship-upsell-add-autoship';
    }
    $upsell_title = apply_filters('wc-autoship-upsell-title', $upsell_title, $item, $item_key);
    ob_start();
    ?>
			<div class="wc-autoship-upsell-container <?php 
    echo $upsell_class;
    ?>
">
				<button type="button" class="wc-autoship-upsell-cart-toggle"
					data-cart-item-key="<?php 
    echo esc_attr($item_key);
    ?>
"
					data-product-id="<?php 
    echo esc_attr($product->id);
    ?>
"
					data-remove-from-cart-url="<?php 
    echo esc_attr(WC()->cart->get_remove_url($item_key));
    ?>
"
					data-add-to-cart-url="<?php 
    echo esc_attr($product->add_to_cart_url());
    ?>
"><?php 
    echo $upsell_title;
    ?>
</button>
			</div>
		<?php 
    $upsell_content = ob_get_clean();
    return $name . $upsell_content;
}
 public static function wc_price($price)
 {
     if (self::is_wc_version_gte_2_1()) {
         return wc_price($price);
     } else {
         return woocommerce_price($price);
     }
 }
Ejemplo n.º 15
0
 function wcml_convert_price($formatted, $unformatted)
 {
     if (!is_admin()) {
         $currency = apply_filters('wcml_price_currency', get_woocommerce_currency());
         $formatted = strip_tags(wc_price(apply_filters('wcml_raw_price_amount', $unformatted), array('currency' => $currency)));
     }
     return $formatted;
 }
 public static function format_price($price)
 {
     if (function_exists('woocommerce_price')) {
         return woocommerce_price($price);
     } else {
         return wc_price($price);
     }
 }
Ejemplo n.º 17
0
/**
 * Get woocommerce data for product
 *
 * @param $value
 * @param $data
 *
 * @return string
 */
function vc_gitem_template_attribute_woocommerce_product($value, $data)
{
    $label = '';
    /**
     * @var null|Wp_Post $post ;
     * @var string $data ;
     */
    extract(array_merge(array('post' => null, 'data' => ''), $data));
    require_once WC()->plugin_path() . '/includes/abstracts/abstract-wc-product.php';
    $product = new WC_Product($post);
    if (preg_match('/_labeled$/', $data)) {
        $data = preg_replace('/_labeled$/', '', $data);
        $label = apply_filters('vc_gitem_template_attribute_woocommerce_product_' . $data . '_label', Vc_Vendor_Woocommerce::getProductFieldLabel($data) . ': ');
    }
    switch ($data) {
        case 'id':
            $value = (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id;
            break;
        case 'sku':
            $value = $product->get_sku();
            break;
        case 'price':
            $value = wc_price($product->get_price());
            break;
        case 'regular_price':
            $value = wc_price($product->get_regular_price());
            break;
        case 'sale_price':
            $value = wc_price($product->get_sale_price());
            break;
        case 'price_html':
            $value = $product->get_price_html();
            break;
        case 'reviews_count':
            $value = count(get_comments(array('post_id' => $post->ID, 'approve' => 'approve')));
            break;
        case 'short_description':
            $value = apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt);
            break;
        case 'dimensions':
            $units = get_option('woocommerce_dimension_unit');
            $value = $product->length . $units . 'x' . $product->width . $units . 'x' . $product->height . $units;
            break;
        case 'rating_count':
            $value = $product->get_rating_count();
            break;
        case 'weight':
            $value = $product->get_weight() ? wc_format_decimal($product->get_weight(), 2) : '';
            break;
        case 'on_sale':
            $value = $product->is_on_sale() ? 'yes' : 'no';
            // TODO: change
            break;
        default:
            $value = $product->{$data};
    }
    return strlen($value) > 0 ? $label . apply_filters('vc_gitem_template_attribute_woocommerce_product_' . $data . '_value', $value) : '';
}
function wc_gzd_cart_forwarding_fee_notice_filter($total_rows, $order)
{
    $gateways = WC()->payment_gateways()->get_available_payment_gateways();
    $gateway = isset($gateways[$order->payment_method]) ? $gateways[$order->payment_method] : null;
    if ($gateway && $gateway->get_option('forwarding_fee')) {
        $total_rows['order_total_forwarding_fee'] = array('label' => '', 'value' => sprintf(__('Plus %s forwarding fee (charged by the transport agent)', 'woocommerce-germanized'), wc_price($gateway->get_option('forwarding_fee'))));
    }
    return $total_rows;
}
 /**
  * Get the total amount with or without refunds
  * @return string
  */
 public function get_total()
 {
     if ($this->order->get_total_refunded() > 0) {
         $total_after_refund = $this->order->get_total() - $this->order->get_total_refunded();
         return $total = '<del class="total-without-refund">' . wc_price($this->order->get_total(), array('currency' => $this->order->get_order_currency())) . '</del> <ins>' . wc_price($total_after_refund, array('currency' => $this->order->get_order_currency())) . '</ins>';
     } else {
         return $total = $this->order->get_formatted_order_total();
     }
 }
Ejemplo n.º 20
0
function wc_wc20_variation_price_format($price, $product) {
    $min_price = $product->get_variation_price('min', true);
    $max_price = $product->get_variation_price('max', true);
    if ($min_price != $max_price) {
        $price = sprintf(__('A partir de %1$s', 'woocommerce'), wc_price($min_price));
        return $price;
    } else {
        $price = sprintf(__('%1$s', 'woocommerce'), wc_price($min_price));
        return $price;
    }
}
Ejemplo n.º 21
0
function wc_wc20_variation_price_format($price, $product)
{
    // Main Price
    $prices = array($product->get_variation_price('min', true), $product->get_variation_price('max', true));
    $price = $prices[0] !== $prices[1] ? sprintf(__('%1$s', 'woocommerce'), wc_price($prices[0])) : wc_price($prices[0]);
    // Sale Price
    $prices = array($product->get_variation_regular_price('min', true), $product->get_variation_regular_price('max', true));
    sort($prices);
    $saleprice = $prices[0] !== $prices[1] ? sprintf(__('%1$s', 'woocommerce'), wc_price($prices[0])) : wc_price($prices[0]);
    if ($price !== $saleprice) {
        $price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>';
    }
    return $price;
}
    public function get_content_html()
    {
        $mailer = WC()->mailer();
        ob_start();
        do_action('woocommerce_email_header', $this->heading, $mailer);
        $email = htmlspecialchars(trim(get_post_meta($this->request_id, '_email', true)));
        $source = htmlspecialchars(trim(get_post_meta($this->request_id, '_source', true)));
        if (substr($source, 0, 4) == 'http') {
            $source = '<a href="' . $source . '" target="_blank">' . $source . '</a>';
        }
        $product_id = get_post_meta($this->request_id, '_product_id', true);
        echo '
			<p>A price match request has been received.</p>
			
			<table>
				<tbody>
					<tr>
						<th><strong>Customer Email:</strong></th>
						<td><a href="mailto:' . $email . '">' . $email . '</a></td>
					</tr>
					<tr>
						<th><strong>Product:</strong></th>
						<td>';
        edit_post_link(get_the_title($product_id), '', '', $product_id);
        echo '</td>
					</tr>
					<tr>
						<th><strong>List Price:</strong></th>
						<td>' . wc_price(get_post_meta($product_id, '_price', true)) . '</td>
					</tr>
						<th><strong>Requested Price:</strong></th>
						<td>' . get_post_meta($this->request_id, '_price', true) . '</td>
					</tr>
					<tr>
						<th><strong>Source:</strong></th>
						<td>' . $source . '</td>
					</tr>
				</tbody>
			</table>
			
			<p>
				<a href="' . admin_url('post.php') . '?id=' . $this->request_id . '&amp;action=hmwcpm_approve&amp;return=edit.php%3Fpost_type%3Dprice_match_request">Approve Request</a> |
				<a href="' . admin_url('post.php') . '?id=' . $this->request_id . '&amp;action=hmwcpm_deny&amp;return=edit.php%3Fpost_type%3Dprice_match_request">Deny Request</a>
			</p>
		';
        do_action('woocommerce_email_footer', $mailer);
        $message = ob_get_contents();
        ob_end_clean();
        return $message;
    }
 /**
  * Manipualte payment gateway title
  *  
  * @param string $title 
  * @param string $id    gateway id
  */
 public function set_title($title, $id)
 {
     $gateways = WC()->payment_gateways->get_available_payment_gateways();
     foreach ($gateways as $gateway) {
         if ($gateway->id != $id) {
             continue;
         }
         $title = $gateway->title;
         if ($gateway->get_option('fee') && (is_checkout() || defined('DOING_AJAX') && isset($_POST['action']) && $_POST['action'] == 'woocommerce_update_order_review')) {
             $title = $title . ' <span class="small">(' . sprintf(__('plus %s payment charge', 'woocommerce-germanized'), wc_price($gateway->get_option('fee'))) . ')</span>';
         }
         return $title;
     }
 }
Ejemplo n.º 24
0
 public function calculate_change($order_id)
 {
     $message = '';
     $tendered = get_post_meta($order_id, '_pos_cash_amount_tendered', true);
     $change = get_post_meta($order_id, '_pos_cash_change', true);
     // construct message
     if ($tendered && $change) {
         $message = __('Amount Tendered', 'woocommerce-pos') . ': ';
         $message .= wc_price($tendered) . '<br>';
         $message .= _x('Change', 'Money returned from cash sale', 'woocommerce-pos') . ': ';
         $message .= wc_price($change);
     }
     echo $message;
 }
 /**
  * Output widget.
  *
  * @see WP_Widget
  *
  * @param array $args
  * @param array $instance
  */
 public function widget($args, $instance)
 {
     global $_chosen_attributes;
     if (!is_post_type_archive('product') && !is_tax(get_object_taxonomies('product'))) {
         return;
     }
     // Price
     $min_price = isset($_GET['min_price']) ? wc_clean($_GET['min_price']) : 0;
     $max_price = isset($_GET['max_price']) ? wc_clean($_GET['max_price']) : 0;
     // Rating
     $min_rating = isset($_GET['min_rating']) ? wc_clean($_GET['min_rating']) : 0;
     if (0 < count($_chosen_attributes) || 0 < $min_price || 0 < $max_price || 0 < $min_rating) {
         $this->widget_start($args, $instance);
         echo '<ul>';
         // Attributes
         if (!is_null($_chosen_attributes)) {
             foreach ($_chosen_attributes as $taxonomy => $data) {
                 foreach ($data['terms'] as $term_slug) {
                     if (!($term = get_term_by('slug', $term_slug, $taxonomy))) {
                         continue;
                     }
                     $filter_name = 'filter_' . sanitize_title(str_replace('pa_', '', $taxonomy));
                     $current_filter = isset($_GET[$filter_name]) ? explode(',', wc_clean($_GET[$filter_name])) : array();
                     $current_filter = array_map('sanitize_title', $current_filter);
                     $new_filter = array_diff($current_filter, array($term_slug));
                     $link = remove_query_arg(array('add-to-cart', $filter_name));
                     if (sizeof($new_filter) > 0) {
                         $link = add_query_arg($filter_name, implode(',', $new_filter), $link);
                     }
                     echo '<li class="chosen"><a title="' . esc_attr__('Remove filter', 'woocommerce') . '" href="' . esc_url($link) . '">' . esc_html($term->name) . '</a></li>';
                 }
             }
         }
         if ($min_price) {
             $link = remove_query_arg('min_price');
             echo '<li class="chosen"><a title="' . esc_attr__('Remove filter', 'woocommerce') . '" href="' . esc_url($link) . '">' . __('Min', 'woocommerce') . ' ' . wc_price($min_price) . '</a></li>';
         }
         if ($max_price) {
             $link = remove_query_arg('max_price');
             echo '<li class="chosen"><a title="' . esc_attr__('Remove filter', 'woocommerce') . '" href="' . esc_url($link) . '">' . __('Max', 'woocommerce') . ' ' . wc_price($max_price) . '</a></li>';
         }
         if ($min_rating) {
             $link = remove_query_arg('min_rating');
             echo '<li class="chosen"><a title="' . esc_attr__('Remove filter', 'woocommerce') . '" href="' . esc_url($link) . '">' . sprintf(__('Rated %s and above', 'woocommerce'), $min_rating) . '</a></li>';
         }
         echo '</ul>';
         $this->widget_end($args);
     }
 }
 /**
  * widget function.
  *
  * @see WP_Widget
  * @access public
  * @param array $args
  * @param array $instance
  * @return void
  */
 public function widget($args, $instance)
 {
     global $_chosen_attributes;
     extract($args);
     if (!is_post_type_archive('product') && !is_tax(get_object_taxonomies('product'))) {
         return;
     }
     $current_term = is_tax() ? get_queried_object()->term_id : '';
     $current_tax = is_tax() ? get_queried_object()->taxonomy : '';
     $title = isset($instance['title']) ? $instance['title'] : '';
     $title = apply_filters('widget_title', $title, $instance, $this->id_base);
     // Price
     $min_price = isset($_GET['min_price']) ? esc_attr($_GET['min_price']) : 0;
     $max_price = isset($_GET['max_price']) ? esc_attr($_GET['max_price']) : 0;
     if (count($_chosen_attributes) > 0 || $min_price > 0 || $max_price > 0) {
         echo $before_widget;
         if ($title) {
             echo $before_title . $title . $after_title;
         }
         echo "<ul>";
         // Attributes
         if (!is_null($_chosen_attributes)) {
             foreach ($_chosen_attributes as $taxonomy => $data) {
                 foreach ($data['terms'] as $term_id) {
                     $term = get_term($term_id, $taxonomy);
                     $taxonomy_filter = str_replace('pa_', '', $taxonomy);
                     $current_filter = !empty($_GET['filter_' . $taxonomy_filter]) ? $_GET['filter_' . $taxonomy_filter] : '';
                     $new_filter = array_map('absint', explode(',', $current_filter));
                     $new_filter = array_diff($new_filter, array($term_id));
                     $link = remove_query_arg('filter_' . $taxonomy_filter);
                     if (sizeof($new_filter) > 0) {
                         $link = add_query_arg('filter_' . $taxonomy_filter, implode(',', $new_filter), $link);
                     }
                     echo '<li class="chosen"><a title="' . __('Remove filter', 'woocommerce') . '" href="' . esc_url($link) . '">' . $term->name . '</a></li>';
                 }
             }
         }
         if ($min_price) {
             $link = remove_query_arg('min_price');
             echo '<li class="chosen"><a title="' . __('Remove filter', 'woocommerce') . '" href="' . esc_url($link) . '">' . __('Min', 'woocommerce') . ' ' . wc_price($min_price) . '</a></li>';
         }
         if ($max_price) {
             $link = remove_query_arg('max_price');
             echo '<li class="chosen"><a title="' . __('Remove filter', 'woocommerce') . '" href="' . esc_url($link) . '">' . __('Max', 'woocommerce') . ' ' . wc_price($max_price) . '</a></li>';
         }
         echo "</ul>";
         echo $after_widget;
     }
 }
 /**
  * Get the legend for the main chart sidebar
  * @return array
  */
 public function get_chart_legend()
 {
     $legend = array();
     $data = $this->get_report_data();
     $count = !empty($data->commissions_all_count) ? count($data->commissions_all_count) : 0;
     $legend[] = array('title' => sprintf(__('%s commission amount', 'yith_wc_product_vendors'), '<strong>' . wc_price($data->commissions_all_amount) . '</strong>'), 'placeholder' => __('This is the sum of commission totals.', 'yith_wc_product_vendors'), 'color' => $this->chart_colours['commissions_amount'], 'highlight_series' => 1);
     $legend[] = array('title' => sprintf(__('%s paid commissions', 'yith_wc_product_vendors'), '<strong>' . wc_price($data->commissions_paid_amount) . '</strong>'), 'placeholder' => __('This is the sum of paid commission totals.', 'yith_wc_product_vendors'), 'color' => $this->chart_colours['commissions_paid'], 'highlight_series' => 2);
     $legend[] = array('title' => sprintf(__('%s unpaid commissions', 'yith_wc_product_vendors'), '<strong>' . wc_price($data->commissions_unpaid_amount) . '</strong>'), 'placeholder' => __('This is the sum of unpaid commission totals.', 'yith_wc_product_vendors'), 'color' => $this->chart_colours['commissions_unpaid'], 'highlight_series' => 3);
     $legend[] = array('title' => sprintf(__('%s processing commissions', 'yith_wc_product_vendors'), '<strong>' . wc_price($data->commissions_processing_amount) . '</strong>'), 'placeholder' => __('This is the sum of processing commission totals.', 'yith_wc_product_vendors'), 'color' => $this->chart_colours['commissions_processing'], 'highlight_series' => 4);
     $legend[] = array('title' => sprintf(__('%s pending commissions', 'yith_wc_product_vendors'), '<strong>' . wc_price($data->commissions_pending_amount) . '</strong>'), 'placeholder' => __('This is the sum of pending commission totals.', 'yith_wc_product_vendors'), 'color' => $this->chart_colours['commissions_pending'], 'highlight_series' => 5);
     $legend[] = array('title' => sprintf(__('%s commissions', 'yith_wc_product_vendors'), '<strong>' . $count . '</strong>'), 'placeholder' => __('This is the sum of the commissions in this period.', 'yith_wc_product_vendors'), 'color' => $this->chart_colours['commissions_count'], 'highlight_series' => 0);
     $legend[] = array('title' => sprintf(__('%s refunded commissions', 'yith_wc_product_vendors'), '<strong>' . wc_price($data->commissions_refunded_amount) . '</strong>'), 'placeholder' => __('This is the sum of refunded commission totals.', 'yith_wc_product_vendors'), 'color' => $this->chart_colours['commissions_refunded'], 'highlight_series' => 6);
     $legend[] = array('title' => sprintf(__('%s cancelled commissions', 'yith_wc_product_vendors'), '<strong>' . wc_price($data->commissions_cancelled_amount) . '</strong>'), 'placeholder' => __('This is the sum of cancelled commission totals.', 'yith_wc_product_vendors'), 'color' => $this->chart_colours['commissions_cancelled'], 'highlight_series' => 7);
     return $legend;
 }
 /**
  * Display the discount in payment method title.
  *
  * @param  string $title Gateway title.
  * @param  string $id    Gateway ID.
  *
  * @return string
  */
 public function payment_method_title($title, $id)
 {
     if (!is_checkout() && !(defined('DOING_AJAX') && DOING_AJAX)) {
         return $title;
     }
     $settings = get_option('woocommerce_payment_discounts');
     if (isset($settings[$id]) && 0 < $settings[$id]) {
         $discount = $settings[$id];
         if (strstr($discount, '%')) {
             $value = $discount;
         } else {
             $value = wc_price($discount);
         }
         $title .= ' <small>(' . sprintf(__('%s off', 'woocommerce-payment-discounts'), $value) . ')</small>';
     }
     return $title;
 }
    public function get_content_html()
    {
        $mailer = WC()->mailer();
        ob_start();
        do_action('woocommerce_email_header', $this->heading, $mailer);
        $product_id = get_post_meta($this->request_id, '_product_id', true);
        $link = get_permalink($product_id);
        echo '
			<p>Your price match request for <strong>' . get_the_title($product_id) . '</strong>
			at <strong>' . wc_price(get_post_meta($this->request_id, '_price', true)) . '</strong> was denied.</p>
			<p>To purchase the product at the regular price, <a href="' . htmlspecialchars($link) . '">click here</a>.</p>
		';
        do_action('woocommerce_email_footer', $mailer);
        $message = ob_get_contents();
        ob_end_clean();
        return $message;
    }
 /**
  * @param   string $price The sale price html
  * @param   string $from String or float to wrap with 'from' text
  * @param   mixed $to String or float to wrap with 'to' text
  * @param   WC_Product $product
  *
  * @return  string
  */
 public function sale_price_from_to($price, $from, $to, $product)
 {
     if ($unit = get_post_meta($product->id, 'unit', true)) {
         $price = '<del>' . (is_numeric($from) ? wc_price($from) : $from) . '/' . $unit . '</del> <ins>' . (is_numeric($to) ? wc_price($to) : $to) . '/' . $unit . '</ins>';
     }
     return $price;
 }