当前位置: 首页>>代码示例>>PHP>>正文


PHP WC_Shipping::instance方法代码示例

本文整理汇总了PHP中WC_Shipping::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Shipping::instance方法的具体用法?PHP WC_Shipping::instance怎么用?PHP WC_Shipping::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WC_Shipping的用法示例。


在下文中一共展示了WC_Shipping::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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;
 }
开发者ID:KristoferN,项目名称:woocommerce,代码行数:18,代码来源:class-wc-shipping-zones.php

示例2: 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;
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:20,代码来源:class-wc-shipping-zones.php

示例3: output_shipping_class_screen

 /**
  * Handles output of the shipping class settings screen.
  */
 protected 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');
     // Extendable columns to show on the shipping classes screen.
     $shipping_class_columns = apply_filters('woocommerce_shipping_classes_columns', array('wc-shipping-class-name' => __('Shipping Class', 'woocommerce'), 'wc-shipping-class-slug' => __('Slug', 'woocommerce'), 'wc-shipping-class-description' => __('Description', 'woocommerce'), 'wc-shipping-class-count' => __('Product Count', 'woocommerce')));
     include_once dirname(__FILE__) . '/views/html-admin-page-shipping-classes.php';
 }
开发者ID:WPprodigy,项目名称:woocommerce,代码行数:12,代码来源:class-wc-settings-shipping.php

示例4: 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);
     }
 }
开发者ID:Automattic,项目名称:woocommerce-connect-client,代码行数:13,代码来源:woocommerce-connect-client.php

示例5: 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)
 {
     if (null === $this->get_id()) {
         $this->save();
     }
     $instance_id = 0;
     $wc_shipping = WC_Shipping::instance();
     $allowed_classes = $wc_shipping->get_shipping_method_class_names();
     $count = $this->data_store->get_method_count($this->get_id());
     if (in_array($type, array_keys($allowed_classes))) {
         $instance_id = $this->data_store->add_method($this->get_id(), $type, $count + 1);
     }
     if ($instance_id) {
         do_action('woocommerce_shipping_zone_method_added', $instance_id, $type, $this->get_id());
     }
     WC_Cache_Helper::get_transient_version('shipping', true);
     return $instance_id;
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:24,代码来源:class-wc-shipping-zone.php

示例6: 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()));
 }
开发者ID:AndyA,项目名称:River,代码行数:53,代码来源:class-wc-ajax.php

示例7: 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;
}
开发者ID:amirkchetu,项目名称:dokan,代码行数:43,代码来源:wc-functions.php

示例8: 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;
 }
开发者ID:unfulvio,项目名称:woocommerce,代码行数:18,代码来源:class-wc-shipping-zone.php

示例9: register_shipping_strings

 function register_shipping_strings($fields)
 {
     $shipping = WC_Shipping::instance();
     foreach ($shipping->get_shipping_methods() as $shipping_method) {
         if (isset($_POST['woocommerce_' . $shipping_method->id . '_enabled'])) {
             $shipping_method_id = $shipping_method->id;
             break;
         }
     }
     if (isset($shipping_method_id)) {
         do_action('wpml_register_single_string', 'woocommerce', $shipping_method_id . '_shipping_method_title', $fields['title']);
     }
     return $fields;
 }
开发者ID:helgatheviking,项目名称:woocommerce-multilingual,代码行数:14,代码来源:wc-strings.class.php

示例10: get_item

 /**
  * Get a single Shipping Method.
  *
  * @param WP_REST_Request $request
  * @return WP_REST_Response|WP_Error
  */
 public function get_item($request)
 {
     $wc_shipping = WC_Shipping::instance();
     $methods = $wc_shipping->get_shipping_methods();
     if (empty($methods[$request['id']])) {
         return new WP_Error('woocommerce_rest_shipping_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
     }
     $method = $methods[$request['id']];
     $response = $this->prepare_item_for_response($method, $request);
     return rest_ensure_response($response);
 }
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:17,代码来源:class-wc-rest-shipping-methods-controller.php

示例11: 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();
     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' => 0), array('%s', '%d', '%d'));
         $instance_id = $wpdb->insert_id;
     }
     return $instance_id;
 }
开发者ID:jameztrue,项目名称:woocommerce,代码行数:17,代码来源:class-wc-shipping-zone.php

示例12: 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' => ''));
         }
     }
 }
开发者ID:NoviumDesign,项目名称:polefitness,代码行数:20,代码来源:woocommerce-fortnox3-extended.php

示例13: 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';
 }
开发者ID:KristoferN,项目名称:woocommerce,代码行数:10,代码来源:class-wc-settings-shipping.php

示例14: 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;
     if (null === $this->get_id()) {
         return 0;
     }
     $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_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_id(), 'method_order' => $count + 1), array('%s', '%d', '%d'));
         $instance_id = $wpdb->insert_id;
     }
     if ($instance_id) {
         do_action('woocommerce_shipping_zone_method_added', $instance_id, $type, $this->get_id());
     }
     WC_Cache_Helper::get_transient_version('shipping', true);
     return $instance_id;
 }
开发者ID:nishitlangaliya,项目名称:woocommerce,代码行数:25,代码来源:class-wc-shipping-zone.php

示例15: 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);
 }
开发者ID:bitoncoin,项目名称:woocommerce,代码行数:20,代码来源:class-wc-settings-shipping.php


注:本文中的WC_Shipping::instance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。