本文整理汇总了PHP中wc_format_decimal函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_format_decimal函数的具体用法?PHP wc_format_decimal怎么用?PHP wc_format_decimal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wc_format_decimal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_order_item
/**
* Add order item via ajax
* exact copy from /wp-content/plugins/woocommerce/includes/class-wc-ajax.php, with change to template selection
*/
public static function add_order_item()
{
check_ajax_referer('order-item', 'security');
$item_to_add = sanitize_text_field($_POST['item_to_add']);
$order_id = absint($_POST['order_id']);
// Find the item
if (!is_numeric($item_to_add)) {
die;
}
$post = get_post($item_to_add);
if (!$post || 'product' !== $post->post_type && 'product_variation' !== $post->post_type) {
die;
}
$_product = wc_get_product($post->ID);
$order = wc_get_order($order_id);
$order_taxes = $order->get_taxes();
$class = 'new_row';
// Set values
$item = array();
$item['product_id'] = $_product->id;
$item['variation_id'] = isset($_product->variation_id) ? $_product->variation_id : '';
$item['variation_data'] = isset($_product->variation_data) ? $_product->variation_data : '';
$item['name'] = $_product->get_title();
$item['tax_class'] = $_product->get_tax_class();
$item['qty'] = 1;
$item['line_subtotal'] = wc_format_decimal($_product->get_price_excluding_tax());
$item['line_subtotal_tax'] = '';
$item['line_total'] = wc_format_decimal($_product->get_price_excluding_tax());
$item['line_tax'] = '';
// Add line item
$item_id = wc_add_order_item($order_id, array('order_item_name' => $item['name'], 'order_item_type' => 'line_item'));
// Add line item meta
if ($item_id) {
wc_add_order_item_meta($item_id, '_qty', $item['qty']);
wc_add_order_item_meta($item_id, '_tax_class', $item['tax_class']);
wc_add_order_item_meta($item_id, '_product_id', $item['product_id']);
wc_add_order_item_meta($item_id, '_variation_id', $item['variation_id']);
wc_add_order_item_meta($item_id, '_line_subtotal', $item['line_subtotal']);
wc_add_order_item_meta($item_id, '_line_subtotal_tax', $item['line_subtotal_tax']);
wc_add_order_item_meta($item_id, '_line_total', $item['line_total']);
wc_add_order_item_meta($item_id, '_line_tax', $item['line_tax']);
// Since 2.2
wc_add_order_item_meta($item_id, '_line_tax_data', array('total' => array(), 'subtotal' => array()));
// Store variation data in meta
if ($item['variation_data'] && is_array($item['variation_data'])) {
foreach ($item['variation_data'] as $key => $value) {
wc_add_order_item_meta($item_id, str_replace('attribute_', '', $key), $value);
}
}
do_action('woocommerce_ajax_add_order_item_meta', $item_id, $item);
}
$item = apply_filters('woocommerce_ajax_order_item', $item, $item_id);
//include( 'admin/meta-boxes/views/html-order-item.php' );
//@@@@LOUSHOU - allow overtake of template
include apply_filters('qsot-woo-template', 'meta-boxes/views/html-order-item.php', 'admin');
// Quit out
die;
}
示例2: create_order
/**
* Create a order.
*
* @since 2.4
*
* @return WC_Order Order object.
*/
public static function create_order($customer_id = 1)
{
// Create product
$product = WC_Helper_Product::create_simple_product();
WC_Helper_Shipping::create_simple_flat_rate();
$order_data = array('status' => 'pending', 'customer_id' => $customer_id, 'customer_note' => '', 'total' => '');
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
// Required, else wc_create_order throws an exception
$order = wc_create_order($order_data);
// Add order products
$order->add_product($product, 4);
// Set billing address
$order->set_billing_first_name('Jeroen');
$order->set_billing_last_name('Sormani');
$order->set_billing_company('WooCompany');
$order->set_billing_address_1('WooAddress');
$order->set_billing_address_2('');
$order->set_billing_city('WooCity');
$order->set_billing_state('NY');
$order->set_billing_postcode('123456');
$order->set_billing_country('US');
$order->set_billing_email('admin@example.org');
$order->set_billing_phone('555-32123');
// Add shipping costs
$shipping_taxes = WC_Tax::calc_shipping_tax('10', WC_Tax::get_shipping_tax_rates());
$rate = new WC_Shipping_Rate('flat_rate_shipping', 'Flat rate shipping', '10', $shipping_taxes, 'flat_rate');
$item = new WC_Order_Item_Shipping();
$item->set_props(array('method_title' => $rate->label, 'method_id' => $rate->id, 'total' => wc_format_decimal($rate->cost), 'taxes' => $rate->taxes, 'meta_data' => $rate->get_meta_data()));
$order->add_item($item);
// Set payment gateway
$payment_gateways = WC()->payment_gateways->payment_gateways();
$order->set_payment_method($payment_gateways['bacs']);
// Set totals
$order->set_shipping_total(10);
$order->set_discount_total(0);
$order->set_discount_tax(0);
$order->set_cart_tax(0);
$order->set_shipping_tax(0);
$order->set_total(40);
// 4 x $10 simple helper product
$order->save();
return $order;
}
示例3: save
public static function save($post_id)
{
if (isset($_POST['_unit'])) {
update_post_meta($post_id, '_unit', sanitize_text_field($_POST['_unit']));
}
if (isset($_POST['_unit_base'])) {
update_post_meta($post_id, '_unit_base', $_POST['_unit_base'] === '' ? '' : wc_format_decimal($_POST['_unit_base']));
}
if (isset($_POST['_unit_price_regular'])) {
update_post_meta($post_id, '_unit_price_regular', $_POST['_unit_price_regular'] === '' ? '' : wc_format_decimal($_POST['_unit_price_regular']));
update_post_meta($post_id, '_unit_price', $_POST['_unit_price_regular'] === '' ? '' : wc_format_decimal($_POST['_unit_price_regular']));
}
if (isset($_POST['_unit_price_sale'])) {
update_post_meta($post_id, '_unit_price_sale', '');
// Update Sale Price only if is on sale (Cron?!)
if (get_post_meta($post_id, '_price', true) != $_POST['_regular_price'] && $_POST['_unit_price_sale'] !== '') {
update_post_meta($post_id, '_unit_price_sale', $_POST['_unit_price_sale'] === '' ? '' : wc_format_decimal($_POST['_unit_price_sale']));
update_post_meta($post_id, '_unit_price', $_POST['_unit_price_sale'] === '' ? '' : wc_format_decimal($_POST['_unit_price_sale']));
}
}
if (isset($_POST['_mini_desc'])) {
update_post_meta($post_id, '_mini_desc', esc_html($_POST['_mini_desc']));
}
if (isset($_POST['delivery_time']) && !is_numeric($_POST['delivery_time'])) {
wp_set_post_terms($post_id, sanitize_text_field($_POST['delivery_time']), 'product_delivery_time');
} else {
wp_set_object_terms($post_id, absint($_POST['delivery_time']), 'product_delivery_time');
}
}
示例4: check_get_coupon_response
/**
* Ensure valid coupon data response.
* @since 2.7.0
* @param array $response
* @param WC_Coupon $coupon
*/
protected function check_get_coupon_response($response, $coupon)
{
$this->assertEquals((int) $coupon->get_id(), $response['id']);
$this->assertEquals($coupon->get_code(), $response['code']);
$this->assertEquals($coupon->get_discount_type(), $response['type']);
$this->assertEquals($coupon->get_amount(), $response['amount']);
$this->assertEquals($coupon->get_individual_use(), $response['individual_use']);
$this->assertEquals($coupon->get_product_ids(), $response['product_ids']);
$this->assertEquals($coupon->get_excluded_product_ids(), $response['exclude_product_ids']);
$this->assertEquals((int) $coupon->get_usage_limit(), $response['usage_limit']);
$this->assertEquals((int) $coupon->get_usage_limit_per_user(), $response['usage_limit_per_user']);
$this->assertEquals((int) $coupon->get_limit_usage_to_x_items(), $response['limit_usage_to_x_items']);
$this->assertEquals((int) $coupon->get_usage_count(), $response['usage_count']);
$this->assertEquals($coupon->get_expiry_date(), $response['expiry_date']);
$this->assertEquals($coupon->get_free_shipping(), $response['enable_free_shipping']);
$this->assertEquals($coupon->get_product_categories(), $response['product_category_ids']);
$this->assertEquals($coupon->get_excluded_product_categories(), $response['exclude_product_category_ids']);
$this->assertEquals($coupon->get_exclude_sale_items(), $response['exclude_sale_items']);
$this->assertEquals(wc_format_decimal($coupon->get_minimum_amount(), 2), $response['minimum_amount']);
$this->assertEquals(wc_format_decimal($coupon->get_maximum_amount(), 2), $response['maximum_amount']);
$this->assertEquals($coupon->get_email_restrictions(), $response['customer_emails']);
$this->assertEquals($coupon->get_description(), $response['description']);
$this->assertArrayHasKey('created_at', $response);
$this->assertArrayHasKey('updated_at', $response);
}
示例5: sv_wc_csv_export_add_weight_to_line_item
/**
* Add weight to line item data
*
* @param array $line_item the original line item data
* @param array $item the item's order data
* @param object $product the \WC_Product object for the line
* @param object $order the \WC_Order object being exported
* @return array the updated line item data
*/
function sv_wc_csv_export_add_weight_to_line_item($line_item, $item, $product, $order)
{
$new_item_data = array();
foreach ($line_item as $key => $data) {
$new_item_data[$key] = $data;
if ('sku' === $key) {
$new_item_data['weight'] = wc_format_decimal($product->get_weight(), 2);
}
}
return $new_item_data;
}
示例6: get_coupon
/**
* Get the coupon for the given ID
*
* @since 2.1
* @param int $id the coupon ID
* @param string $fields fields to include in response
* @return array|WP_Error
*/
public function get_coupon($id, $fields = null)
{
$id = $this->validate_request($id, 'shop_coupon', 'read');
if (is_wp_error($id)) {
return $id;
}
$coupon = new WC_Coupon($id);
if (0 === $coupon->get_id()) {
throw new WC_API_Exception('woocommerce_api_invalid_coupon_id', __('Invalid coupon ID', 'woocommerce'), 404);
}
$coupon_data = array('id' => $coupon->get_id(), 'code' => $coupon->get_code(), 'type' => $coupon->get_discount_type(), 'created_at' => $this->server->format_datetime($coupon->get_date_created(), false, true), 'updated_at' => $this->server->format_datetime($coupon->get_date_modified(), false, true), 'amount' => wc_format_decimal($coupon->get_amount(), 2), 'individual_use' => $coupon->get_individual_use(), 'product_ids' => array_map('absint', (array) $coupon->get_product_ids()), 'exclude_product_ids' => array_map('absint', (array) $coupon->get_excluded_product_ids()), 'usage_limit' => $coupon->get_usage_limit() ? $coupon->get_usage_limit() : null, 'usage_limit_per_user' => $coupon->get_usage_limit_per_user() ? $coupon->get_usage_limit_per_user() : null, 'limit_usage_to_x_items' => (int) $coupon->get_limit_usage_to_x_items(), 'usage_count' => (int) $coupon->get_usage_count(), 'expiry_date' => $this->server->format_datetime($coupon->get_date_expires(), false, true), 'enable_free_shipping' => $coupon->get_free_shipping(), 'product_category_ids' => array_map('absint', (array) $coupon->get_product_categories()), 'exclude_product_category_ids' => array_map('absint', (array) $coupon->get_excluded_product_categories()), 'exclude_sale_items' => $coupon->get_exclude_sale_items(), 'minimum_amount' => wc_format_decimal($coupon->get_minimum_amount(), 2), 'customer_emails' => $coupon->get_email_restrictions());
return array('coupon' => apply_filters('woocommerce_api_coupon_response', $coupon_data, $coupon, $fields, $this->server));
}
示例7: test_wc_get_product_ids_on_sale
/**
* Test wc_get_product_ids_on_sale()
*
* @since 2.4
*/
public function test_wc_get_product_ids_on_sale()
{
$this->assertEquals(array(), wc_get_product_ids_on_sale());
delete_transient('wc_products_onsale');
// Create product
$product = \WC_Helper_Product::create_simple_product();
update_post_meta($product->id, '_regular_price', wc_format_decimal(10));
update_post_meta($product->id, '_price', wc_format_decimal(5));
update_post_meta($product->id, '_sale_price', wc_format_decimal(5));
$this->assertEquals(array($product->id), wc_get_product_ids_on_sale());
// Delete Product
\WC_Helper_Product::delete_product($product->id);
}
示例8: save
/**
* Save the Targets settings
*/
public function save()
{
try {
$this->verify_request(WooCommerce_Grow_Helpers::get_field('_wpnonce', $_REQUEST), 'woocommerce-grow-targets');
$is_calculate_growth = null !== WooCommerce_Grow_Helpers::get_field('calculate_growth', $_POST) ? true : false;
// Calculate and Growth settings
if ($is_calculate_growth) {
$initial_revenue_number = WooCommerce_Grow_Helpers::get_field('initial_revenue_number', $_POST);
$initial_orders_number = WooCommerce_Grow_Helpers::get_field('initial_orders_number', $_POST);
$initial_sessions_number = WooCommerce_Grow_Helpers::get_field('initial_sessions_number', $_POST);
$initial_cr_number = WooCommerce_Grow_Helpers::get_field('initial_cr_number', $_POST);
$initial_aov_number = WooCommerce_Grow_Helpers::get_field('initial_aov_number', $_POST);
// Call to GA to get sessions for the last month
$ga = WooCommerce_Grow_Google_Analytics::get_instance();
$month = date('m', strtotime('first day of previous month'));
$year = date('Y');
list($start_date, $end_date) = WooCommerce_Grow_Helpers::get_first_and_last_of_the_month($month, $year);
$initial_sessions = $ga->get_sessions_for_month($month, $year);
$filters = array('date_min' => $start_date, 'date_max' => $end_date);
$reports = WooCommerce_Grow_Helpers::setup_wc_reports($filters);
$initial_revenue = WooCommerce_Grow_Helpers::get_wc_total_sales($reports);
$initial_orders = WooCommerce_Grow_Helpers::get_wc_total_orders($reports);
WooCommerce_Grow_Helpers::add_debug_log('Revenue: ' . $initial_revenue);
WooCommerce_Grow_Helpers::add_debug_log('Orders: ' . $initial_orders);
$initial_cr = WooCommerce_Grow_Helpers::calculate_cr($initial_orders, $initial_sessions);
$initial_aov = WooCommerce_Grow_Helpers::calculate_aov($initial_revenue, $initial_orders);
$growth_rate = WooCommerce_Grow_Helpers::get_field('growth_rate', $_POST);
// Save the initial options
WooCommerce_Grow_Helpers::update_option('initial_revenue_number', $initial_revenue);
WooCommerce_Grow_Helpers::update_option('initial_orders_number', $initial_orders);
WooCommerce_Grow_Helpers::update_option('initial_sessions_number', $initial_sessions);
WooCommerce_Grow_Helpers::update_option('initial_cr_number', $initial_cr);
WooCommerce_Grow_Helpers::update_option('initial_aov_number', $initial_aov);
WooCommerce_Grow_Helpers::update_option('growth_rate', $growth_rate);
$months = WooCommerce_Grow_Helpers::get_twelve_months_ahead();
foreach ($months as $month) {
$target_sessions = WooCommerce_Grow_Helpers::calculate_growth($initial_sessions, $growth_rate);
$target_cr = WooCommerce_Grow_Helpers::calculate_growth($initial_cr, $growth_rate);
$target_aov = WooCommerce_Grow_Helpers::calculate_growth($initial_aov, $growth_rate);
$targets['sessions_percentage'][$month['year']][$month['month']] = ceil($target_sessions);
$targets['cr_percentage'][$month['year']][$month['month']] = $target_cr;
$targets['aov_percentage'][$month['year']][$month['month']] = $target_aov;
$targets['revenue_percentage'][$month['year']][$month['month']] = wc_format_decimal($target_sessions * $target_cr * $target_aov, 2);
$targets['orders_percentage'][$month['year']][$month['month']] = ceil($target_sessions * $target_cr);
}
WooCommerce_Grow_Helpers::update_option('monthly_targets', $targets);
}
} catch (Exception $e) {
WC_Admin_Settings::add_error($e->getMessage());
}
}
示例9: process_payment
public function process_payment($order_id)
{
// get order object
$order = new WC_Order($order_id);
// update pos_cash data
$tendered = isset($_POST['pos-cash-tendered']) ? wc_format_decimal($_POST['pos-cash-tendered']) : 0;
$change = isset($_POST['pos-cash-change']) ? wc_format_decimal($_POST['pos-cash-change']) : 0;
update_post_meta($order_id, '_pos_cash_amount_tendered', $tendered);
update_post_meta($order_id, '_pos_cash_change', $change);
// payment complete
$order->payment_complete();
// Return thankyou redirect
return array('result' => 'success');
}
示例10: add_rate
/**
* Add a rate.
*
* Add a shipping rate. If taxes are not set they will be calculated based on cost.
*
* @param array $args (default: array())
*/
public function add_rate($args = array())
{
$args = wp_parse_args($args, array('id' => '', 'label' => '', 'cost' => '0', 'taxes' => '', 'calc_tax' => 'per_order'));
// Id and label are required
if (!$args['id'] || !$args['label']) {
return;
}
// Total up the cost
$total_cost = wc_format_decimal(is_array($args['cost']) ? array_sum($args['cost']) : $args['cost'], wc_get_price_decimals());
$taxes = $args['taxes'];
// Taxes - if not an array and not set to false, calc tax based on cost and passed calc_tax variable
// This saves shipping methods having to do complex tax calculations
if (!is_array($taxes) && $taxes !== false && $total_cost > 0 && $this->is_taxable()) {
$taxes = array();
switch ($args['calc_tax']) {
case "per_item":
// If we have an array of costs we can look up each items tax class and add tax accordingly
if (is_array($args['cost'])) {
$cart = WC()->cart->get_cart();
foreach ($args['cost'] as $cost_key => $amount) {
if (!isset($cart[$cost_key])) {
continue;
}
$item_taxes = WC_Tax::calc_shipping_tax($amount, WC_Tax::get_shipping_tax_rates($cart[$cost_key]['data']->get_tax_class()));
// Sum the item taxes
foreach (array_keys($taxes + $item_taxes) as $key) {
$taxes[$key] = (isset($item_taxes[$key]) ? $item_taxes[$key] : 0) + (isset($taxes[$key]) ? $taxes[$key] : 0);
}
}
// Add any cost for the order - order costs are in the key 'order'
if (isset($args['cost']['order'])) {
$item_taxes = WC_Tax::calc_shipping_tax($args['cost']['order'], WC_Tax::get_shipping_tax_rates());
// Sum the item taxes
foreach (array_keys($taxes + $item_taxes) as $key) {
$taxes[$key] = (isset($item_taxes[$key]) ? $item_taxes[$key] : 0) + (isset($taxes[$key]) ? $taxes[$key] : 0);
}
}
}
break;
default:
$taxes = WC_Tax::calc_shipping_tax($total_cost, WC_Tax::get_shipping_tax_rates());
break;
}
}
$this->rates[] = new WC_Shipping_Rate($args['id'], $args['label'], $total_cost, $taxes, $this->id);
}
示例11: update_product_pricing
/**
* Get the highest hierarchy role for a user
*
* @param int $userid ID of the user to get the role for
* @return bool|string User role name or false if the user doesn't exist
*/
public static function update_product_pricing($product, $args)
{
$product = get_product($product);
if (!$product) {
return;
}
if ($product->is_type('variable', 'grouped')) {
return;
}
$args = wp_parse_args($args, array('regular_price' => $product->get_regular_price(), 'sale_price' => $product->get_sale_price(), 'sale_price_dates_from' => $product->sale_price_dates_from, 'sale_price_dates_to' => $product->sale_price_dates_to));
$regular_price = $args['regular_price'] === '' ? '' : wc_format_decimal($args['regular_price']);
$sale_price = $args['sale_price'] === '' ? '' : wc_format_decimal($args['sale_price']);
update_post_meta($product->id, '_regular_price', $regular_price);
update_post_meta($product->id, '_sale_price', $sale_price);
$date_from = $args['sale_price_dates_from'] ? $args['sale_price_dates_from'] : '';
$date_to = $args['sale_price_dates_to'] ? $args['sale_price_dates_to'] : '';
// Dates
if ($date_from) {
update_post_meta($product->id, '_sale_price_dates_from', strtotime($date_from));
} else {
update_post_meta($product->id, '_sale_price_dates_from', '');
}
if ($date_to) {
update_post_meta($product->id, '_sale_price_dates_to', strtotime($date_to));
} else {
update_post_meta($product->id, '_sale_price_dates_to', '');
}
if ($date_to && !$date_from) {
update_post_meta($product->id, '_sale_price_dates_from', strtotime('NOW', current_time('timestamp')));
}
// Update price if on sale
if ($sale_price !== '' && $date_to == '' && $date_from == '') {
update_post_meta($product->id, '_price', wc_format_decimal($sale_price));
} else {
update_post_meta($product->id, '_price', $regular_price === '' ? '' : wc_format_decimal($regular_price));
}
if ($sale_price !== '' && $date_from && strtotime($date_from) < strtotime('NOW', current_time('timestamp'))) {
update_post_meta($product->id, '_price', wc_format_decimal($sale_price));
}
if ($date_to && strtotime($date_to) < strtotime('NOW', current_time('timestamp'))) {
update_post_meta($product->id, '_price', $regular_price === '' ? '' : wc_format_decimal($regular_price));
update_post_meta($product->id, '_sale_price_dates_from', '');
update_post_meta($product->id, '_sale_price_dates_to', '');
}
}
示例12: process_payment
public function process_payment($order_id)
{
// get order object
$order = new WC_Order($order_id);
$tendered = isset($_REQUEST['pos-cash-tendered']) ? wc_format_decimal($_REQUEST['pos-cash-tendered']) : 0;
$tendered = abs((double) $tendered);
$total = isset($_REQUEST['total']) ? $_REQUEST['total'] : 0;
$total = abs((double) $total);
if ($tendered !== 0) {
// calculate change
$change = $tendered - $total;
// add order meta
update_post_meta($order_id, '_pos_cash_amount_tendered', $tendered);
update_post_meta($order_id, '_pos_cash_change', $change);
}
// payment complete
$order->payment_complete();
// Return thankyou redirect
return array('result' => 'success');
}
示例13: wccg_generate_coupons
/**
* Generate coupons.
*
* Generate the coupons based on the $args arguments.
*
* @since 1.0.0
* TODO
*/
function wccg_generate_coupons($number, $args = array())
{
// Verify required values
if (!isset($args['number_of_coupons'])) {
return;
}
// TODO default args
global $wpdb;
$insert_coupon_ids = array();
$wpdb->query('START TRANSACTION');
// Query coupons
$number_of_coupons = absint($number);
for ($i = 0; $i < $number_of_coupons; $i++) {
$coupon_code = wccg_get_random_coupon();
// Insert coupon post
$wpdb->query($wpdb->prepare("INSERT INTO {$wpdb->posts} SET\n\t\t\tpost_author=%d,\n\t\t\tpost_date=%s,\n\t\t\tpost_date_gmt=%s,\n\t\t\tpost_title=%s,\n\t\t\tpost_status='publish',\n\t\t\tcomment_status='closed',\n\t\t\tping_status='closed',\n\t\t\tpost_name=%s,\n\t\t\tpost_modified=%s,\n\t\t\tpost_modified_gmt=%s,\n\t\t\tpost_type='shop_coupon'\n\t\t\t", get_current_user_id(), current_time('mysql'), current_time('mysql', 1), sanitize_title($coupon_code), $coupon_code, current_time('mysql'), current_time('mysql', 1)));
$insert_coupon_ids[] = $wpdb->insert_id;
$coupon_id = $wpdb->insert_id;
// Set GUID
// $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET guid=%s WHERE ID=%d", get_permalink( $coupon_id ), $coupon_id ) ); // Slow
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET guid=%s WHERE ID=%d", esc_url_raw(add_query_arg(array('post_type' => 'shop_coupon', 'p' => $coupon_id), home_url())), $coupon_id));
// 10% faster -1 query per coupon
}
// Add/Replace data to array
$meta_array = apply_filters('woocommerce_coupon_generator_coupon_meta_data', array('discount_type' => empty($args['discount_type']) ? 'fixed_cart' : wc_clean($args['discount_type']), 'coupon_amount' => wc_format_decimal($args['coupon_amount']), 'individual_use' => isset($args['individual_use']) ? 'yes' : 'no', 'product_ids' => implode(',', array_filter(array_map('intval', explode(',', $args['product_ids'])))), 'exclude_product_ids' => implode(',', array_filter(array_map('intval', explode(',', $args['exclude_product_ids'])))), 'usage_limit' => empty($args['usage_limit']) ? '' : absint($args['usage_limit']), 'usage_limit_per_user' => empty($args['usage_limit_per_user']) ? '' : absint($args['usage_limit_per_user']), 'limit_usage_to_x_items' => empty($args['limit_usage_to_x_items']) ? '' : absint($args['limit_usage_to_x_items']), 'expiry_date' => wc_clean($args['expiry_date']), 'free_shipping' => isset($args['free_shipping']) ? 'yes' : 'no', 'exclude_sale_items' => isset($args['exclude_sale_items']) ? 'yes' : 'no', 'product_categories' => isset($args['product_categories']) ? array_map('intval', $args['product_categories']) : array(), 'exclude_product_categories' => isset($args['exclude_product_categories']) ? array_map('intval', $args['exclude_product_categories']) : array(), 'minimum_amount' => wc_format_decimal($args['minimum_amount']), 'maximum_amount' => wc_format_decimal($args['maximum_amount']), 'customer_email' => array_filter(array_map('trim', explode(',', wc_clean($args['customer_email']))))), $coupon_id);
$insert_meta_values = '';
// Insert all coupons meta
foreach ($meta_array as $key => $value) {
foreach ($insert_coupon_ids as $coupon_id) {
$insert_meta_values .= $wpdb->prepare('(%d, %s, %s)', $coupon_id, sanitize_title(wp_unslash($key)), maybe_serialize(wp_unslash($value)));
$meta_array_keys = array_keys($meta_array);
if ($key == end($meta_array_keys) && $coupon_id == end($insert_coupon_ids)) {
$insert_meta_values .= ';';
} else {
$insert_meta_values .= ', ';
}
}
}
$wpdb->query("INSERT INTO {$wpdb->postmeta} (post_id, meta_key, meta_value) VALUES {$insert_meta_values}");
$wpdb->query('COMMIT');
}
示例14: get_orders
static function get_orders($untyped_array_of_orders)
{
$typed_array_of_products = array();
foreach ($untyped_array_of_orders as $untyped_order) {
$wc_order = wc_get_order($untyped_order->ID);
$typed_order = new Matrix42_Order();
$typed_order->id = $wc_order->id;
$typed_order->created_at = $wc_order->order_date;
$typed_order->updated_at = $wc_order->modified_date;
$typed_order->completed_at = $wc_order->completed_date;
$typed_order->status = $wc_order->get_status();
$customer = get_user_by('id', $wc_order->customer_user);
$typed_order->customer = array('id' => $customer->ID, 'email' => $customer->user_email, 'first_name' => $customer->user_firstname, 'last_name' => $customer->user_lastname, 'login_name' => $customer->user_login);
$typed_order->order_url = $wc_order->get_view_order_url();
foreach ($wc_order->get_items() as $item_id => $item) {
$product = $wc_order->get_product_from_item($item);
$typed_order->order_items[] = array('id' => $item_id, 'price' => wc_format_decimal($wc_order->get_item_total($item), 2), 'quantity' => (int) $item['qty'], 'name' => $item['name'], 'product_id' => isset($product->variation_id) ? $product->variation_id : $product->id, 'sku' => is_object($product) ? $product->get_sku() : null);
}
array_push($typed_array_of_products, $typed_order);
}
return $typed_array_of_products;
}
示例15: add_checkout_add_ons_to_csv_export_column_data
/**
* Adds support for Customer/Order CSV Export by adding data for each
* checkout add-on column header
*
* @since 1.1.0
* @param array $order_data generated order data matching the column keys in the header
* @param WC_Order $order order being exported
* @param \WC_Customer_Order_CSV_Export_Generator $csv_generator instance
* @return array
*/
public function add_checkout_add_ons_to_csv_export_column_data($order_data, $order, $csv_generator)
{
$order_add_ons = wc_checkout_add_ons()->get_order_add_ons($order->id);
$new_order_data = $add_on_data = array();
foreach (wc_checkout_add_ons()->get_add_ons() as $add_on) {
$value = '';
$total = '';
if (isset($order_add_ons[$add_on->id])) {
$value = 'file' == $add_on->type ? wp_get_attachment_url($order_add_ons[$add_on->id]['value']) : $add_on->normalize_value($order_add_ons[$add_on->id]['normalized_value'], true);
$total = wc_format_decimal($order_add_ons[$add_on->id]['total'], 2);
}
$add_on_data['checkout_add_on_' . $add_on->id] = $value;
$add_on_data['checkout_add_on_total_' . $add_on->id] = $total;
}
if (isset($csv_generator->order_format) && ('default_one_row_per_item' == $csv_generator->order_format || 'legacy_one_row_per_item' == $csv_generator->order_format)) {
foreach ($order_data as $data) {
$new_order_data[] = array_merge((array) $data, $add_on_data);
}
} else {
$new_order_data = array_merge($order_data, $add_on_data);
}
return $new_order_data;
}