本文整理汇总了PHP中WC_Shipping类的典型用法代码示例。如果您正苦于以下问题:PHP WC_Shipping类的具体用法?PHP WC_Shipping怎么用?PHP WC_Shipping使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WC_Shipping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkfermopoint_merchant_callback
function checkfermopoint_merchant_callback()
{
echo "<h1>Riepilogo ticket Fermo!Point</h1>";
$shippings_wc = new WC_Shipping();
$shippings = $shippings_wc->load_shipping_methods();
$fermopoint = $shippings["Fermo!Point"];
//echo json_encode($fermopoint->settings);
$fermopoint_settings = $fermopoint->settings;
$account_id = $fermopoint_settings["FERMOPOINT_ACCOUNT_ID"];
$account_secret = $fermopoint_settings["FERMOPOINT_ACCOUNT_SECRET"];
$sandbox = $fermopoint_settings["sandbox"];
$url = $sandbox == "yes" ? "http://www.sandbox.fermopoint.it/api/v1.2/merchant" : "http://api.fermopoint.it/api/v1.2/merchant";
$ts = gmdate('Y-m-d\\TH:i:s.u\\Z');
$auth_token = hash_hmac("sha256", (string) $ts, (string) $account_id . $account_secret, false);
$request_url = '{
"client_id": "' . $account_id . '",
"ts": "' . $ts . '",
"auth_token": "' . $auth_token . '",
"data":{}
}';
$request = json_encode(array("client_id" => $account_id, "auth_token" => $auth_token, "ts" => $ts, "data" => array()));
$httpHeader = array("Content-Type: application/json; charset=\"utf-8\"", "Accept: text/json");
$ch = curl_init();
$connect_timeout = 5;
//sec
$base_time_limit = (int) ini_get('max_execution_time');
if ($base_time_limit < 0) {
$base_time_limit = 0;
}
$time_limit = $base_time_limit - $connect_timeout - 2;
if ($time_limit <= 0) {
$time_limit = 20;
//default
}
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $connect_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $time_limit);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
if (!isset($info['http_code'])) {
$info['http_code'] = '';
}
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
if (curl_errno($ch)) {
$result = array('http_code' => $info['http_code'], 'status' => 'ERROR1', 'errno' => $curl_errno, 'error' => $curl_error, 'result' => NULL);
} else {
$ret = json_decode($result);
}
//var_dump($result);
//var_dump($ret);
?>
<h2>Crediti restati: <?php
echo $ret->credits;
?>
</h2>
<h2>Ordini totali: <?php
echo $ret->orders_count;
?>
</h2>
<table>
<?php
$orders = $ret->orders;
if (count($orders) > 0) {
foreach ($orders as $order) {
?>
<tr>
<?php
foreach ($order as $col) {
?>
<td><?php
echo $col;
?>
</td><?php
}
?>
</tr>
<?php
}
}
?>
</table>
<?php
curl_close($ch);
}
示例2: instance
/**
* Main WC_Shipping Instance
*
* Ensures only one instance of WC_Shipping is loaded or can be loaded.
*
* @since 2.1
* @static
* @return WC_Shipping Main instance
*/
public static function instance()
{
if (is_null(self::$_instance)) {
self::$_instance = new self();
}
return self::$_instance;
}
示例3: get_shipping_method
/**
* Get shipping zone using it's ID
* @since 2.6.0
* @param int $zone_id
* @return WC_Shipping_Meethod|bool
*/
public static function get_shipping_method($instance_id)
{
global $wpdb;
$raw_shipping_method = $wpdb->get_row($wpdb->prepare("SELECT instance_id, method_id FROM {$wpdb->prefix}woocommerce_shipping_zone_methods WHERE instance_id = %d LIMIT 1;", $instance_id));
$wc_shipping = WC_Shipping::instance();
$allowed_classes = $wc_shipping->get_shipping_method_class_names();
if (in_array($raw_shipping_method->method_id, array_keys($allowed_classes))) {
$class_name = $allowed_classes[$raw_shipping_method->method_id];
return new $class_name($raw_shipping_method->instance_id);
}
return false;
}
示例4: get_shipping_method
/**
* Get shipping zone using it's ID
* @since 2.6.0
* @return WC_Shipping_Meethod|bool
*/
public static function get_shipping_method($instance_id)
{
$data_store = WC_Data_Store::load('shipping-zone');
$raw_shipping_method = $data_store->get_method($instance_id);
$wc_shipping = WC_Shipping::instance();
$allowed_classes = $wc_shipping->get_shipping_method_class_names();
if (!empty($raw_shipping_method) && in_array($raw_shipping_method->method_id, array_keys($allowed_classes))) {
$class_name = $allowed_classes[$raw_shipping_method->method_id];
if (is_object($class_name)) {
$class_name = get_class($class_name);
}
return new $class_name($raw_shipping_method->instance_id);
}
return false;
}
示例5: dokan_create_sub_order_shipping
/**
* Create shipping for a sub-order if neccessary
*
* @param WC_Order $parent_order
* @param int $order_id
* @param array $product_ids
* @return type
*/
function dokan_create_sub_order_shipping($parent_order, $order_id, $seller_products)
{
// take only the first shipping method
$shipping_methods = $parent_order->get_shipping_methods();
$shipping_method = is_array($shipping_methods) ? reset($shipping_methods) : array();
// bail out if no shipping methods found
if (!$shipping_method) {
return;
}
$shipping_products = array();
$packages = array();
// emulate shopping cart for calculating the shipping method
foreach ($seller_products as $product_item) {
$product = get_product($product_item['product_id']);
if ($product->needs_shipping()) {
$shipping_products[] = array('product_id' => $product_item['product_id'], 'variation_id' => $product_item['variation_id'], 'variation' => '', 'quantity' => $product_item['qty'], 'data' => $product, 'line_total' => $product_item['line_total'], 'line_tax' => $product_item['line_tax'], 'line_subtotal' => $product_item['line_subtotal'], 'line_subtotal_tax' => $product_item['line_subtotal_tax']);
}
}
if ($shipping_products) {
$package = array('contents' => $shipping_products, 'contents_cost' => array_sum(wp_list_pluck($shipping_products, 'line_total')), 'applied_coupons' => array(), 'destination' => array('country' => $parent_order->shipping_country, 'state' => $parent_order->shipping_state, 'postcode' => $parent_order->shipping_postcode, 'city' => $parent_order->shipping_city, 'address' => $parent_order->shipping_address_1, 'address_2' => $parent_order->shipping_address_2));
$wc_shipping = WC_Shipping::instance();
$pack = $wc_shipping->calculate_shipping_for_package($package);
if (array_key_exists($shipping_method['method_id'], $pack['rates'])) {
$method = $pack['rates'][$shipping_method['method_id']];
$cost = wc_format_decimal($method->cost);
$item_id = wc_add_order_item($order_id, array('order_item_name' => $method->label, 'order_item_type' => 'shipping'));
if ($item_id) {
wc_add_order_item_meta($item_id, 'method_id', $method->id);
wc_add_order_item_meta($item_id, 'cost', $cost);
}
return $cost;
}
}
return 0;
}
示例6: add_shipping_method
/**
* Add a shipping method to this zone.
* @param string $type shipping method type
* @return int new instance_id, 0 on failure
*/
public function add_shipping_method($type)
{
global $wpdb;
$instance_id = 0;
$wc_shipping = WC_Shipping::instance();
$allowed_classes = $wc_shipping->get_shipping_method_class_names();
$count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->prefix}woocommerce_shipping_zone_methods WHERE zone_id = %d", $this->get_zone_id()));
if (in_array($type, array_keys($allowed_classes))) {
$wpdb->insert($wpdb->prefix . 'woocommerce_shipping_zone_methods', array('method_id' => $type, 'zone_id' => $this->get_zone_id(), 'method_order' => $count + 1), array('%s', '%d', '%d'));
$instance_id = $wpdb->insert_id;
}
return $instance_id;
}
示例7: save
/**
* Save settings.
*/
public function save()
{
global $current_section;
$wc_shipping = WC_Shipping::instance();
if (!$current_section) {
WC_Admin_Settings::save_fields($this->get_settings());
$wc_shipping->process_admin_options();
} else {
foreach ($wc_shipping->get_shipping_methods() as $method_id => $method) {
if ($current_section === sanitize_title(get_class($method))) {
do_action('woocommerce_update_options_' . $this->id . '_' . $method->id);
}
}
}
// Increments the transient version to invalidate cache
WC_Cache_Helper::get_transient_version('shipping', true);
}
示例8: sr_query_sales
function sr_query_sales($cumm_dates, $date_series, $post)
{
$params = !empty($post['params']) ? $post['params'] : array();
if (!wp_verify_nonce($params['security'], 'smart-reporter-security')) {
die('Security check');
}
global $wpdb, $sr_text_domain;
$returns = array();
// Initialize the return data
$returns['chart'] = $returns['kpi'] = array();
$returns['meta'] = array('start_date' => $cumm_dates['cp_start_date'], 'end_date' => $cumm_dates['cp_end_date'], 's_link' => admin_url() . 'edit.php?post_type=shop_order&source=sr&sdate=' . $cumm_dates['cp_start_date'] . '&edate=' . $cumm_dates['cp_end_date']);
$returns['chart']['period'] = $date_series;
$periods_count = count($returns['chart']['period']);
$p2i = array_flip($returns['chart']['period']);
$time_str = $cumm_dates['format'] == '%H' ? ':00:00' : '';
if (!empty($post['cmd']) && ($post['cmd'] == 'cumm_sales' || $post['cmd'] == 'sr_summary')) {
$date_col = $cumm_dates['format'] == '%H' ? 'created_time' : 'created_date';
$chart_keys = array('sales', 'orders', 'discount');
$payment_methods = $shipping_methods = array();
// For each payment and shipping method...
foreach ((array) WC_Payment_Gateways::instance()->get_available_payment_gateways() as $key => $value) {
$chart_keys[] = 'pm_' . $key . '_sales';
$chart_keys[] = 'pm_' . $key . '_orders';
$returns['kpi']['pm'][$key] = array('title' => __($value->get_title(), $sr_text_domain), 'sales' => 0, 'orders' => 0, 's_link' => '&s=' . $value->get_title() . '&s_col=payment_method&s_val=' . $key);
}
foreach ((array) WC_Shipping::instance()->get_shipping_methods() as $key => $value) {
$chart_keys[] = 'sm_' . $key . '_sales';
$chart_keys[] = 'sm_' . $key . '_orders';
$returns['kpi']['sm'][$key] = array('title' => __($value->get_title(), $sr_text_domain), 'sales' => 0, 'orders' => 0, 's_link' => '&s=' . $value->get_title() . '&s_col=shipping_method&s_val=' . $key);
}
// Initialize chart data to 0
foreach ($chart_keys as $value) {
$returns['chart'][$value] = array_fill(0, $periods_count, 0);
}
// KPIs are single item stats.. init for current and last period (lp_)
$kpis = array('sales', 'refunds', 'orders', 'qty', 'discount', 'tax', 'shipping', 'shipping_tax');
foreach ($kpis as $value) {
$returns['kpi'][$value] = 0;
$returns['kpi']['lp_' . $value] = 0;
}
// Bring in grouped results for sales, discounts etc - then loop and process
// LAST_PERIOD is special 'period' value for comparing current period data
// with previous period
$query = $wpdb->prepare("SELECT 'LAST_PERIOD' as period, \n\t\t\t\t\t\t\t\t\t\t\tSUM( CASE WHEN type = 'shop_order' AND status != 'wc-refunded' THEN 1 ELSE 0 END ) as orders, \n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN -1*total \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE total END), 0) AS sales,\n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN total \n\t\t\t\t\t\t\t\t\t\t\t\t\tWHEN type = 'shop_order_refund' THEN -1*total \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE 0 END), 0) AS refunds,\n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN 0 \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE qty END), 0) AS qty,\n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN 0 \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE discount+cart_discount END), 0) AS discount,\n\t\t\t\t\t\t\t\t\t\t0 AS tax,\n\t\t\t\t\t\t\t\t\t\t0 AS shipping,\n\t\t\t\t\t\t\t\t\t\t0 AS shipping_tax,\n\t\t\t\t\t\t\t\t\t '' AS payment_method, \n\t\t\t\t\t\t\t\t\t '' AS shipping_method \n\t\t\t\t\t\t\t\t\tFROM `{$wpdb->prefix}woo_sr_orders` \n\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\tcreated_date BETWEEN '%s' AND '%s'\n\t\t\t\t\t\t\t\t\t\tAND status in ('wc-completed', 'wc-processing', 'wc-on-hold', 'wc-refunded')\n\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\tSELECT concat(DATE_FORMAT(" . $date_col . ", '%s'), '" . $time_str . "') AS period,\n\t\t\t\t\t\t\t\t\t\t\tSUM( CASE WHEN type = 'shop_order' AND status != 'wc-refunded' THEN 1 ELSE 0 END ) as orders, \n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN -1*total \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE total END), 0) AS sales,\n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN total \n\t\t\t\t\t\t\t\t\t\t\t\t\tWHEN type = 'shop_order_refund' THEN -1*total \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE 0 END), 0) AS refunds,\n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN 0 \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE qty END), 0) AS qty,\n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN 0 \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE discount+cart_discount END), 0) AS discount,\n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN 0 \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE tax END), 0) AS tax,\n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN 0 \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE shipping END), 0) AS shipping,\n\t\t\t\t\t\t\t\t\t\tIFNULL(SUM( CASE WHEN status = 'wc-refunded' THEN 0 \n\t\t\t\t\t\t\t\t\t\t\t\t\tELSE shipping_tax END), 0) AS shipping_tax,\n\t\t\t\t\t\t\t\t\t payment_method, \n\t\t\t\t\t\t\t\t\t shipping_method \n\t\t\t\t\t\t\t\t\tFROM `{$wpdb->prefix}woo_sr_orders` \n\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\tcreated_date BETWEEN '%s' AND '%s'\n\t\t\t\t\t\t\t\t\tAND status in ('wc-completed', 'wc-processing', 'wc-on-hold', 'wc-refunded') \n\t\t\t\t\t\t\t\t\tGROUP BY period, payment_method, shipping_method", $cumm_dates['lp_start_date'], $cumm_dates['lp_end_date'], $cumm_dates['format'], $cumm_dates['cp_start_date'], $cumm_dates['cp_end_date']);
$results = $wpdb->get_results($query, 'ARRAY_A');
if (count($results) > 0) {
// The first row will always be last period data
$row = array_shift($results);
foreach ($kpis as $value) {
$returns['kpi']['lp_' . $value] = $row[$value];
}
// Loop and total up values now
foreach ($results as $row) {
if (!array_key_exists($row['period'], $p2i)) {
error_log('Smart Reporter: Invalid value for "period" in DB results - ' . $row['period']);
continue;
}
// Total up sales, refunds, qty etc...
foreach ($kpis as $key) {
$returns['kpi'][$key] += $row[$key];
}
// Index of this period - this will be used to position different chart data at this period's index
$i = $p2i[$row['period']];
// Set values in charts - for data other than payment / shipping methods
foreach ($chart_keys as $key) {
if (substr($key, 1, 2) != 'm_') {
// will match pm_ and sm_ both in single condition
$returns['chart'][$key][$i] += $row[$key];
}
}
// Set values for shipping and payment methods
foreach (array('pm' => $row['payment_method'], 'sm' => $row['shipping_method']) as $type => $method) {
foreach (array('sales', 'orders') as $f) {
$key = $type . '_' . $method . '_' . $f;
if (array_key_exists($key, $returns['chart'])) {
$row[$f] = $type == 'sm' && $f == 'sales' ? $row['shipping'] : $row[$f];
$returns['chart'][$key][$i] += $row[$f];
$returns['kpi'][$type][$method][$f] += $row[$f];
}
}
}
}
// sorting the pm and sm by sales
$returns['kpi']['pm'] = array_slice(sr_multidimensional_array_sort($returns['kpi']['pm'], 'sales', 'DESC'), 0, 5);
$returns['kpi']['sm'] = array_slice(sr_multidimensional_array_sort($returns['kpi']['sm'], 'sales', 'DESC'), 0, 5);
}
}
if (!empty($post['cmd']) && ($post['cmd'] == 'cumm_cust_prod' || $post['cmd'] == 'sr_summary')) {
$chart_keys = array();
$date_col = $cumm_dates['format'] == '%H' ? 'order_time' : 'order_date';
// KPIs are single item stats.. init for current and last period (lp_)
$kpis = array('car', 'carts', 'carts_prod', 'orders', 'orders_prod', 'corders', 'corders_prod', 'aipc', 'swc');
foreach ($kpis as $value) {
$returns['kpi'][$value] = 0;
if ($value == 'car' || $value == 'aipc' || $value == 'swc') {
$returns['kpi']['lp_' . $value] = 0;
}
}
// ###############################
// Top Customers
//.........这里部分代码省略.........
示例9: init
/**
* Init WooCommerce when WordPress Initialises.
*
* @access public
* @return void
*/
function init()
{
// Set up localisation
$this->load_plugin_textdomain();
// Variables
$this->template_url = apply_filters('woocommerce_template_url', 'woocommerce/');
// Load class instances
$this->payment_gateways = new WC_Payment_gateways();
// Payment gateways. Loads and stores payment methods
$this->shipping = new WC_Shipping();
// Shipping class. loads and stores shipping methods
$this->countries = new WC_Countries();
// Countries class
$this->integrations = new WC_Integrations();
// Integrations class
// Init shipping, payment gateways, and integrations
$this->shipping->init();
$this->payment_gateways->init();
$this->integrations->init();
// Classes/actions loaded for the frontend and for ajax requests
if (!is_admin() || defined('DOING_AJAX')) {
// Class instances
$this->cart = new WC_Cart();
// Cart class, stores the cart contents
$this->customer = new WC_Customer();
// Customer class, sorts out session data such as location
$this->query = new WC_Query();
// Query class, handles front-end queries and loops
// Load messages
$this->load_messages();
// Hooks
add_filter('template_include', array(&$this, 'template_loader'));
add_filter('comments_template', array(&$this, 'comments_template_loader'));
add_filter('wp_redirect', array(&$this, 'redirect'), 1, 2);
add_action('template_redirect', array(&$this, 'buffer_checkout'));
add_action('wp_enqueue_scripts', array(&$this, 'frontend_scripts'));
add_action('wp_print_scripts', array(&$this, 'check_jquery'), 25);
add_action('wp_head', array(&$this, 'generator'));
add_action('wp_head', array(&$this, 'wp_head'));
add_filter('body_class', array(&$this, 'output_body_class'));
add_action('wp_footer', array(&$this, 'output_inline_js'), 25);
}
// Actions
add_action('the_post', array(&$this, 'setup_product_data'));
add_action('admin_footer', array(&$this, 'output_inline_js'), 25);
// Email Actions
$email_actions = array('woocommerce_low_stock', 'woocommerce_no_stock', 'woocommerce_product_on_backorder', 'woocommerce_order_status_pending_to_processing', 'woocommerce_order_status_pending_to_completed', 'woocommerce_order_status_pending_to_on-hold', 'woocommerce_order_status_failed_to_processing', 'woocommerce_order_status_failed_to_completed', 'woocommerce_order_status_pending_to_processing', 'woocommerce_order_status_pending_to_on-hold', 'woocommerce_order_status_completed', 'woocommerce_new_customer_note');
foreach ($email_actions as $action) {
add_action($action, array(&$this, 'send_transactional_email'));
}
// Actions for SSL
if (!is_admin() || defined('DOING_AJAX')) {
add_action('template_redirect', array(&$this, 'ssl_redirect'));
$filters = array('post_thumbnail_html', 'widget_text', 'wp_get_attachment_url', 'wp_get_attachment_image_attributes', 'wp_get_attachment_url', 'option_siteurl', 'option_homeurl', 'option_home', 'option_url', 'option_wpurl', 'option_stylesheet_url', 'option_template_url', 'script_loader_src', 'style_loader_src', 'template_directory_uri', 'stylesheet_directory_uri', 'site_url');
foreach ($filters as $filter) {
add_filter($filter, array(&$this, 'force_ssl'));
}
}
// Register globals for WC environment
$this->register_globals();
// Init user roles
$this->init_user_roles();
// Init WooCommerce taxonomies
$this->init_taxonomy();
// Init Images sizes
$this->init_image_sizes();
// Init styles
if (!is_admin()) {
$this->init_styles();
}
// Trigger API requests
$this->api_requests();
// Init action
do_action('woocommerce_init');
}
示例10: woocommerce_load_shipping_methods
/**
* Registers shipping methods for use in things like the Add Shipping Method dialog
* on the Shipping Zones view
*
*/
public function woocommerce_load_shipping_methods()
{
$shipping_service_ids = $this->get_service_schemas_store()->get_all_service_ids_of_type('shipping');
foreach ($shipping_service_ids as $shipping_service_id) {
$shipping_method = $this->get_service_object_by_id('WC_Connect_Shipping_Method', $shipping_service_id);
WC_Shipping::instance()->register_shipping_method($shipping_method);
}
}
示例11: output_shipping_class_screen
/**
* Handles output of the shipping class settings screen.
*/
private function output_shipping_class_screen()
{
$wc_shipping = WC_Shipping::instance();
wp_localize_script('wc-shipping-classes', 'shippingClassesLocalizeScript', array('classes' => $wc_shipping->get_shipping_classes(), 'default_shipping_class' => array('term_id' => 0, 'name' => '', 'description' => ''), 'wc_shipping_classes_nonce' => wp_create_nonce('wc_shipping_classes_nonce'), 'strings' => array('unload_confirmation_msg' => __('Your changed data will be lost if you leave this page without saving.', 'woocommerce'), 'save_failed' => __('Your changes were not saved. Please retry.', 'woocommerce'))));
wp_enqueue_script('wc-shipping-classes');
include_once 'views/html-admin-page-shipping-classes.php';
}
示例12: get_shipping_methods
/**
* WooCommerce handles shipping methods on a per class/instance basis. So in order to have a
* shipping method, we must have a class file that registers itself with 'woocommerce_shipping_methods'.
*/
public function get_shipping_methods($params)
{
$klass = new WC_Shipping();
$klass->load_shipping_methods();
$methods = array();
foreach ($klass->shipping_methods as $sm) {
$methods[] = array('id' => $sm->id, 'name' => $sm->title, 'display_name' => $sm->method_title, 'enabled' => $sm->enabled, 'settings' => $sm->settings, 'plugin_id' => $sm->plugin_id);
}
$this->result->setPayload($methods);
return $this->done();
}
示例13: getfieldfermopoint
public function getfieldfermopoint()
{
//header('Content-Type: application/json');
//check_ajax_referer('creajsbarcode','security');
$shippings_wc = new WC_Shipping();
$shippings = $shippings_wc->load_shipping_methods();
$fermopoint = $shippings["Fermo!Point"];
//echo json_encode($fermopoint->settings);
$fermopoint_settings = $fermopoint->settings;
$account_id = $fermopoint_settings["FERMOPOINT_ACCOUNT_ID"];
$account_secret = $fermopoint_settings["FERMOPOINT_ACCOUNT_SECRET"];
$sandbox = $fermopoint_settings["sandbox"];
$url = $sandbox == "yes" ? "http://www.sandbox.fermopoint.it/RedirectApi" : "http://www.fermopoint.it/RedirectApi";
//echo json_encode($shippings_wc );
return array("id" => html_entity_decode($account_id), "secret" => html_entity_decode($account_secret), "url" => $url, "sandbox" => $sandbox);
}
示例14: shipping_classes_save_changes
/**
* Handle submissions from assets/js/wc-shipping-classes.js Backbone model.
*/
public static function shipping_classes_save_changes()
{
if (!isset($_POST['wc_shipping_classes_nonce'], $_POST['changes'])) {
wp_send_json_error('missing_fields');
exit;
}
if (!wp_verify_nonce($_POST['wc_shipping_classes_nonce'], 'wc_shipping_classes_nonce')) {
wp_send_json_error('bad_nonce');
exit;
}
if (!current_user_can('manage_woocommerce')) {
wp_send_json_error('missing_capabilities');
exit;
}
$changes = $_POST['changes'];
foreach ($changes as $term_id => $data) {
$term_id = absint($term_id);
if (isset($data['deleted'])) {
if (isset($data['newRow'])) {
// So the user added and deleted a new row.
// That's fine, it's not in the database anyways. NEXT!
continue;
}
wp_delete_term($term_id, 'product_shipping_class');
continue;
}
$update_args = array();
if (isset($data['name'])) {
$update_args['name'] = wc_clean($data['name']);
}
if (isset($data['slug'])) {
$update_args['slug'] = wc_clean($data['slug']);
}
if (isset($data['description'])) {
$update_args['description'] = wc_clean($data['description']);
}
if (isset($data['newRow'])) {
$update_args = array_filter($update_args);
if (empty($update_args['name'])) {
continue;
}
$term_id = wp_insert_term($update_args['name'], 'product_shipping_class', $update_args);
} else {
wp_update_term($term_id, 'product_shipping_class', $update_args);
}
do_action('woocommerce_shipping_classes_save_class', $term_id, $data);
}
$wc_shipping = WC_Shipping::instance();
wp_send_json_success(array('shipping_classes' => $wc_shipping->get_shipping_classes()));
}
示例15: register_woocommerce_fortnox_freight_settings
/**
* WooCommerce Fortnox General Settings
*
* @access public
* @param void
* @return void
*/
function register_woocommerce_fortnox_freight_settings()
{
$this->plugin_settings_tabs[$this->freight_settings_key] = 'Avancerade Fraktinställningar';
$shipping_methods = WC_Shipping::instance()->load_shipping_methods();
register_setting($this->freight_settings_key, $this->freight_settings_key);
add_settings_section('section_general', 'Avancerade Fraktinställningar', array(&$this, 'section_freight_desc'), $this->freight_settings_key);
foreach ($shipping_methods as $shipping_method) {
//add_settings_field( 'woocommerce-fortnox-api-key', 'API Nyckel', array( &$this, 'field_hidden_option_text' ), $this->general_settings_key, 'section_general', array ( 'tab_key' => $this->general_settings_key, 'key' => 'api-key', 'desc' => '') );
if ($shipping_method->enabled == 'yes') {
add_settings_field('woocommerce-fortnox-freight-method-' . $shipping_method->id, $shipping_method->title, array(&$this, 'field_option_text'), $this->freight_settings_key, 'section_general', array('tab_key' => $this->freight_settings_key, 'key' => $shipping_method->id, 'desc' => ''));
}
}
}