2016-06-16 15:27:32 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* REST API Shipping Zone Methods controller
|
|
|
|
*
|
|
|
|
* Handles requests to the /shipping/zones/<id>/methods endpoint.
|
|
|
|
*
|
|
|
|
* @author WooThemes
|
|
|
|
* @category API
|
|
|
|
* @package WooCommerce/API
|
2017-03-15 16:36:53 +00:00
|
|
|
* @since 3.0.0
|
2016-06-16 15:27:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* REST API Shipping Zone Methods class.
|
|
|
|
*
|
|
|
|
* @package WooCommerce/API
|
|
|
|
* @extends WC_REST_Shipping_Zones_Controller_Base
|
|
|
|
*/
|
|
|
|
class WC_REST_Shipping_Zone_Methods_Controller extends WC_REST_Shipping_Zones_Controller_Base {
|
2016-06-16 22:34:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register the routes for Shipping Zone Methods.
|
|
|
|
*/
|
|
|
|
public function register_routes() {
|
2017-04-28 14:49:51 +00:00
|
|
|
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<zone_id>[\d]+)/methods', array(
|
2017-01-26 20:06:18 +00:00
|
|
|
'args' => array(
|
|
|
|
'zone_id' => array(
|
|
|
|
'description' => __( 'Unique ID for the zone.', 'woocommerce' ),
|
|
|
|
'type' => 'integer',
|
|
|
|
),
|
|
|
|
),
|
2016-06-16 22:34:40 +00:00
|
|
|
array(
|
|
|
|
'methods' => WP_REST_Server::READABLE,
|
|
|
|
'callback' => array( $this, 'get_items' ),
|
2016-06-17 21:14:39 +00:00
|
|
|
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
2016-06-16 22:34:40 +00:00
|
|
|
),
|
2016-08-26 03:34:26 +00:00
|
|
|
array(
|
|
|
|
'methods' => WP_REST_Server::CREATABLE,
|
|
|
|
'callback' => array( $this, 'create_item' ),
|
|
|
|
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
2017-03-24 01:19:16 +00:00
|
|
|
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
|
|
|
|
'method_id' => array(
|
|
|
|
'required' => true,
|
|
|
|
'readonly' => false,
|
|
|
|
'description' => __( 'Shipping method ID.', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
) ),
|
2016-08-26 03:34:26 +00:00
|
|
|
),
|
2016-06-16 22:34:40 +00:00
|
|
|
'schema' => array( $this, 'get_public_item_schema' ),
|
|
|
|
) );
|
2016-06-17 21:31:40 +00:00
|
|
|
|
2017-05-02 23:37:03 +00:00
|
|
|
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<zone_id>[\d]+)/methods/(?P<instance_id>[\d]+)', array(
|
2017-01-26 20:06:18 +00:00
|
|
|
'args' => array(
|
|
|
|
'zone_id' => array(
|
|
|
|
'description' => __( 'Unique ID for the zone.', 'woocommerce' ),
|
|
|
|
'type' => 'integer',
|
|
|
|
),
|
|
|
|
'instance_id' => array(
|
|
|
|
'description' => __( 'Unique ID for the instance.', 'woocommerce' ),
|
|
|
|
'type' => 'integer',
|
|
|
|
),
|
|
|
|
),
|
2016-06-17 21:31:40 +00:00
|
|
|
array(
|
|
|
|
'methods' => WP_REST_Server::READABLE,
|
|
|
|
'callback' => array( $this, 'get_item' ),
|
|
|
|
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
|
|
|
),
|
2016-08-26 03:34:26 +00:00
|
|
|
array(
|
|
|
|
'methods' => WP_REST_Server::EDITABLE,
|
|
|
|
'callback' => array( $this, 'update_item' ),
|
|
|
|
'permission_callback' => array( $this, 'update_items_permissions_check' ),
|
|
|
|
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'methods' => WP_REST_Server::DELETABLE,
|
|
|
|
'callback' => array( $this, 'delete_item' ),
|
2016-08-29 17:19:28 +00:00
|
|
|
'permission_callback' => array( $this, 'delete_items_permissions_check' ),
|
2016-08-26 03:34:26 +00:00
|
|
|
'args' => array(
|
|
|
|
'force' => array(
|
|
|
|
'default' => false,
|
2017-01-26 20:06:18 +00:00
|
|
|
'type' => 'boolean',
|
2016-08-26 03:34:26 +00:00
|
|
|
'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2016-06-17 21:31:40 +00:00
|
|
|
'schema' => array( $this, 'get_public_item_schema' ),
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a single Shipping Zone Method.
|
|
|
|
*
|
|
|
|
* @param WP_REST_Request $request
|
|
|
|
* @return WP_REST_Response|WP_Error
|
|
|
|
*/
|
|
|
|
public function get_item( $request ) {
|
|
|
|
$zone = $this->get_zone( $request['zone_id'] );
|
|
|
|
|
|
|
|
if ( is_wp_error( $zone ) ) {
|
|
|
|
return $zone;
|
|
|
|
}
|
|
|
|
|
|
|
|
$instance_id = (int) $request['instance_id'];
|
|
|
|
$methods = $zone->get_shipping_methods();
|
|
|
|
$method = false;
|
|
|
|
|
|
|
|
foreach ( $methods as $method_obj ) {
|
|
|
|
if ( $instance_id === $method_obj->instance_id ) {
|
|
|
|
$method = $method_obj;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( false === $method ) {
|
2016-09-06 20:57:30 +00:00
|
|
|
return new WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
|
2016-06-17 21:31:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$data = $this->prepare_item_for_response( $method, $request );
|
|
|
|
|
|
|
|
return rest_ensure_response( $data );
|
2016-06-16 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all Shipping Zone Methods.
|
|
|
|
*
|
|
|
|
* @param WP_REST_Request $request
|
|
|
|
* @return WP_REST_Response|WP_Error
|
|
|
|
*/
|
|
|
|
public function get_items( $request ) {
|
|
|
|
$zone = $this->get_zone( $request['zone_id'] );
|
|
|
|
|
|
|
|
if ( is_wp_error( $zone ) ) {
|
|
|
|
return $zone;
|
|
|
|
}
|
|
|
|
|
|
|
|
$methods = $zone->get_shipping_methods();
|
|
|
|
$data = array();
|
|
|
|
|
|
|
|
foreach ( $methods as $method_obj ) {
|
|
|
|
$method = $this->prepare_item_for_response( $method_obj, $request );
|
|
|
|
$data[] = $method;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rest_ensure_response( $data );
|
|
|
|
}
|
|
|
|
|
2016-08-26 03:34:26 +00:00
|
|
|
/**
|
|
|
|
* Create a new shipping zone method instance.
|
|
|
|
*
|
|
|
|
* @param WP_REST_Request $request Full details about the request.
|
|
|
|
* @return WP_REST_Request|WP_Error
|
|
|
|
*/
|
|
|
|
public function create_item( $request ) {
|
|
|
|
$method_id = $request['method_id'];
|
|
|
|
$zone = $this->get_zone( $request['zone_id'] );
|
|
|
|
if ( is_wp_error( $zone ) ) {
|
|
|
|
return $zone;
|
|
|
|
}
|
|
|
|
|
2016-09-02 02:00:46 +00:00
|
|
|
$instance_id = $zone->add_shipping_method( $method_id );
|
2016-08-26 03:34:26 +00:00
|
|
|
$methods = $zone->get_shipping_methods();
|
|
|
|
$method = false;
|
|
|
|
foreach ( $methods as $method_obj ) {
|
|
|
|
if ( $instance_id === $method_obj->instance_id ) {
|
|
|
|
$method = $method_obj;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( false === $method ) {
|
2016-08-26 11:57:30 +00:00
|
|
|
return new WP_Error( 'woocommerce_rest_shipping_zone_not_created', __( 'Resource cannot be created.', 'woocommerce' ), array( 'status' => 500 ) );
|
2016-08-26 03:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$method = $this->update_fields( $instance_id, $method, $request );
|
2016-09-08 22:14:40 +00:00
|
|
|
if ( is_wp_error( $method ) ) {
|
|
|
|
return $method;
|
|
|
|
}
|
2016-08-26 03:34:26 +00:00
|
|
|
|
|
|
|
$data = $this->prepare_item_for_response( $method, $request );
|
|
|
|
return rest_ensure_response( $data );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a shipping method instance.
|
|
|
|
*
|
|
|
|
* @param WP_REST_Request $request Full details about the request
|
|
|
|
* @return WP_Error|boolean
|
|
|
|
*/
|
|
|
|
public function delete_item( $request ) {
|
|
|
|
$zone = $this->get_zone( $request['zone_id'] );
|
|
|
|
if ( is_wp_error( $zone ) ) {
|
|
|
|
return $zone;
|
|
|
|
}
|
|
|
|
|
|
|
|
$instance_id = (int) $request['instance_id'];
|
|
|
|
$force = $request['force'];
|
2016-08-26 11:57:30 +00:00
|
|
|
|
2016-08-26 03:34:26 +00:00
|
|
|
$methods = $zone->get_shipping_methods();
|
|
|
|
$method = false;
|
|
|
|
|
|
|
|
foreach ( $methods as $method_obj ) {
|
|
|
|
if ( $instance_id === $method_obj->instance_id ) {
|
|
|
|
$method = $method_obj;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( false === $method ) {
|
2016-09-06 20:57:30 +00:00
|
|
|
return new WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
|
2016-08-26 03:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$method = $this->update_fields( $instance_id, $method, $request );
|
2016-09-08 22:14:40 +00:00
|
|
|
if ( is_wp_error( $method ) ) {
|
|
|
|
return $method;
|
|
|
|
}
|
|
|
|
|
2016-08-26 03:34:26 +00:00
|
|
|
$request->set_param( 'context', 'view' );
|
|
|
|
$response = $this->prepare_item_for_response( $method, $request );
|
|
|
|
|
2016-08-26 11:57:30 +00:00
|
|
|
// Actually delete
|
2016-08-26 03:34:26 +00:00
|
|
|
if ( $force ) {
|
2016-09-02 02:00:46 +00:00
|
|
|
$zone->delete_shipping_method( $instance_id );
|
2016-08-26 03:34:26 +00:00
|
|
|
} else {
|
2016-10-12 10:05:37 +00:00
|
|
|
return new WP_Error( 'rest_trash_not_supported', __( 'Shipping methods do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
|
2016-08-26 03:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fires after a product review is deleted via the REST API.
|
|
|
|
*
|
|
|
|
* @param object $method
|
|
|
|
* @param WP_REST_Response $response The response data.
|
|
|
|
* @param WP_REST_Request $request The request sent to the API.
|
|
|
|
*/
|
|
|
|
do_action( 'rest_delete_product_review', $method, $response, $request );
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update A Single Shipping Zone Method.
|
|
|
|
*
|
|
|
|
* @param WP_REST_Request $request
|
|
|
|
* @return WP_REST_Response|WP_Error
|
|
|
|
*/
|
|
|
|
public function update_item( $request ) {
|
|
|
|
$zone = $this->get_zone( $request['zone_id'] );
|
|
|
|
if ( is_wp_error( $zone ) ) {
|
|
|
|
return $zone;
|
|
|
|
}
|
|
|
|
|
|
|
|
$instance_id = (int) $request['instance_id'];
|
|
|
|
$methods = $zone->get_shipping_methods();
|
|
|
|
$method = false;
|
|
|
|
|
|
|
|
foreach ( $methods as $method_obj ) {
|
|
|
|
if ( $instance_id === $method_obj->instance_id ) {
|
|
|
|
$method = $method_obj;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( false === $method ) {
|
2016-09-06 20:57:30 +00:00
|
|
|
return new WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
|
2016-08-26 03:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$method = $this->update_fields( $instance_id, $method, $request );
|
2016-09-08 22:14:40 +00:00
|
|
|
if ( is_wp_error( $method ) ) {
|
|
|
|
return $method;
|
|
|
|
}
|
2016-08-26 03:34:26 +00:00
|
|
|
|
|
|
|
$data = $this->prepare_item_for_response( $method, $request );
|
|
|
|
return rest_ensure_response( $data );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates settings, order, and enabled status on create.
|
|
|
|
*
|
|
|
|
* @param $instance_id integer
|
|
|
|
* @param $method
|
|
|
|
* @param WP_REST_Request $request
|
|
|
|
* @return $method
|
|
|
|
*/
|
|
|
|
public function update_fields( $instance_id, $method, $request ) {
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
// Update settings if present
|
|
|
|
if ( isset( $request['settings'] ) ) {
|
|
|
|
$method->init_instance_settings();
|
|
|
|
$instance_settings = $method->instance_settings;
|
2016-09-08 22:14:40 +00:00
|
|
|
$errors_found = false;
|
2016-08-26 03:34:26 +00:00
|
|
|
foreach ( $method->get_instance_form_fields() as $key => $field ) {
|
|
|
|
if ( isset( $request['settings'][ $key ] ) ) {
|
2016-09-08 22:14:40 +00:00
|
|
|
if ( is_callable( array( $this, 'validate_setting_' . $field['type'] . '_field' ) ) ) {
|
|
|
|
$value = $this->{'validate_setting_' . $field['type'] . '_field'}( $request['settings'][ $key ], $field );
|
|
|
|
} else {
|
|
|
|
$value = $this->validate_setting_text_field( $request['settings'][ $key ], $field );
|
|
|
|
}
|
|
|
|
if ( is_wp_error( $value ) ) {
|
|
|
|
$errors_found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$instance_settings[ $key ] = $value;
|
2016-08-26 03:34:26 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-08 22:14:40 +00:00
|
|
|
|
|
|
|
if ( $errors_found ) {
|
|
|
|
return new WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) );
|
|
|
|
}
|
|
|
|
|
2016-08-26 03:34:26 +00:00
|
|
|
update_option( $method->get_instance_option_key(), apply_filters( 'woocommerce_shipping_' . $method->id . '_instance_settings_values', $instance_settings, $method ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update order
|
|
|
|
if ( isset( $request['order'] ) ) {
|
|
|
|
$wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'method_order' => absint( $request['order'] ) ), array( 'instance_id' => absint( $instance_id ) ) );
|
|
|
|
$method->method_order = absint( $request['order'] );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update if this method is enabled or not.
|
|
|
|
if ( isset( $request['enabled'] ) ) {
|
|
|
|
if ( $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'is_enabled' => $request['enabled'] ), array( 'instance_id' => absint( $instance_id ) ) ) ) {
|
|
|
|
do_action( 'woocommerce_shipping_zone_method_status_toggled', $instance_id, $method->id, $request['zone_id'], $request['enabled'] );
|
|
|
|
$method->enabled = ( true === $request['enabled'] ? 'yes' : 'no' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $method;
|
|
|
|
}
|
|
|
|
|
2016-06-16 22:34:40 +00:00
|
|
|
/**
|
|
|
|
* Prepare the Shipping Zone Method for the REST response.
|
|
|
|
*
|
|
|
|
* @param array $item Shipping Zone Method.
|
|
|
|
* @param WP_REST_Request $request Request object.
|
|
|
|
* @return WP_REST_Response $response
|
|
|
|
*/
|
|
|
|
public function prepare_item_for_response( $item, $request ) {
|
|
|
|
$method = array(
|
2017-05-02 23:37:03 +00:00
|
|
|
'id' => $item->instance_id,
|
2016-06-16 22:34:40 +00:00
|
|
|
'instance_id' => $item->instance_id,
|
|
|
|
'title' => $item->instance_settings['title'],
|
|
|
|
'order' => $item->method_order,
|
|
|
|
'enabled' => ( 'yes' === $item->enabled ),
|
|
|
|
'method_id' => $item->id,
|
|
|
|
'method_title' => $item->method_title,
|
|
|
|
'method_description' => $item->method_description,
|
2016-08-26 03:34:26 +00:00
|
|
|
'settings' => $this->get_settings( $item ),
|
2016-06-16 22:34:40 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$context = empty( $request['context'] ) ? 'view' : $request['context'];
|
|
|
|
$data = $this->add_additional_fields_to_object( $method, $request );
|
|
|
|
$data = $this->filter_response_by_context( $data, $context );
|
|
|
|
|
|
|
|
// Wrap the data in a response object.
|
|
|
|
$response = rest_ensure_response( $data );
|
|
|
|
|
2016-06-16 22:53:33 +00:00
|
|
|
$response->add_links( $this->prepare_links( $request['zone_id'], $item->instance_id ) );
|
|
|
|
|
2016-06-17 23:40:58 +00:00
|
|
|
$response = $this->prepare_response_for_collection( $response );
|
|
|
|
|
2016-06-16 22:34:40 +00:00
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
2016-08-26 03:34:26 +00:00
|
|
|
/**
|
|
|
|
* Return settings associated with this shipping zone method instance.
|
|
|
|
*/
|
|
|
|
public function get_settings( $item ) {
|
|
|
|
$item->init_instance_settings();
|
|
|
|
$settings = array();
|
|
|
|
foreach ( $item->get_instance_form_fields() as $id => $field ) {
|
|
|
|
$data = array(
|
|
|
|
'id' => $id,
|
|
|
|
'label' => $field['title'],
|
2016-08-26 11:57:30 +00:00
|
|
|
'description' => empty( $field['description'] ) ? '' : $field['description'],
|
2016-08-26 03:34:26 +00:00
|
|
|
'type' => $field['type'],
|
|
|
|
'value' => $item->instance_settings[ $id ],
|
2016-08-26 11:57:30 +00:00
|
|
|
'default' => empty( $field['default'] ) ? '' : $field['default'],
|
|
|
|
'tip' => empty( $field['description'] ) ? '' : $field['description'],
|
|
|
|
'placeholder' => empty( $field['placeholder'] ) ? '' : $field['placeholder'],
|
2016-08-26 03:34:26 +00:00
|
|
|
);
|
|
|
|
if ( ! empty( $field['options'] ) ) {
|
|
|
|
$data['options'] = $field['options'];
|
|
|
|
}
|
|
|
|
$settings[ $id ] = $data;
|
|
|
|
}
|
|
|
|
return $settings;
|
|
|
|
}
|
|
|
|
|
2016-06-16 22:53:33 +00:00
|
|
|
/**
|
|
|
|
* Prepare links for the request.
|
|
|
|
*
|
|
|
|
* @param int $zone_id Given Shipping Zone ID.
|
|
|
|
* @param int $instance_id Given Shipping Zone Method Instance ID.
|
|
|
|
* @return array Links for the given Shipping Zone Method.
|
|
|
|
*/
|
|
|
|
protected function prepare_links( $zone_id, $instance_id ) {
|
|
|
|
$base = '/' . $this->namespace . '/' . $this->rest_base . '/' . $zone_id;
|
|
|
|
$links = array(
|
2016-06-17 21:31:40 +00:00
|
|
|
'self' => array(
|
|
|
|
'href' => rest_url( $base . '/methods/' . $instance_id ),
|
|
|
|
),
|
2016-06-16 22:53:33 +00:00
|
|
|
'collection' => array(
|
|
|
|
'href' => rest_url( $base . '/methods' ),
|
|
|
|
),
|
|
|
|
'describes' => array(
|
|
|
|
'href' => rest_url( $base ),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
return $links;
|
|
|
|
}
|
|
|
|
|
2016-06-16 15:27:32 +00:00
|
|
|
/**
|
|
|
|
* Get the Shipping Zone Methods schema, conforming to JSON Schema
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_item_schema() {
|
2016-06-17 20:59:36 +00:00
|
|
|
$schema = array(
|
|
|
|
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
|
|
|
'title' => 'shipping_zone_method',
|
2016-06-16 15:27:32 +00:00
|
|
|
'type' => 'object',
|
|
|
|
'properties' => array(
|
2017-05-02 23:37:03 +00:00
|
|
|
'id' => array(
|
|
|
|
'description' => __( 'Shipping method instance ID.', 'woocommerce' ),
|
|
|
|
'type' => 'integer',
|
|
|
|
'context' => array( 'view', 'edit' ),
|
|
|
|
'readonly' => true,
|
|
|
|
),
|
2016-06-16 15:27:32 +00:00
|
|
|
'instance_id' => array(
|
|
|
|
'description' => __( 'Shipping method instance ID.', 'woocommerce' ),
|
|
|
|
'type' => 'integer',
|
2016-08-31 21:16:52 +00:00
|
|
|
'context' => array( 'view', 'edit' ),
|
|
|
|
'readonly' => true,
|
2016-06-16 15:27:32 +00:00
|
|
|
),
|
|
|
|
'title' => array(
|
|
|
|
'description' => __( 'Shipping method customer facing title.', 'woocommerce' ),
|
|
|
|
'type' => 'string',
|
2016-08-31 21:16:52 +00:00
|
|
|
'context' => array( 'view', 'edit' ),
|
|
|
|
'readonly' => true,
|
2016-06-16 15:27:32 +00:00
|
|
|
),
|
|
|
|
'order' => array(
|
|
|
|
'description' => __( 'Shipping method sort order.', 'woocommerce' ),
|
|
|
|
'type' => 'integer',
|
|
|
|
'context' => array( 'view', 'edit' ),
|
|
|
|
),
|
|
|
|
'enabled' => array(
|
|
|
|
'description' => __( 'Shipping method enabled status.', 'woocommerce' ),
|
|
|
|
'type' => 'boolean',
|
|
|
|
'context' => array( 'view', 'edit' ),
|
|
|
|
),
|
|
|
|
'method_id' => array(
|
2017-03-24 01:19:16 +00:00
|
|
|
'description' => __( 'Shipping method ID.', 'woocommerce' ),
|
2016-06-16 15:27:32 +00:00
|
|
|
'type' => 'string',
|
2016-08-31 21:16:52 +00:00
|
|
|
'context' => array( 'view', 'edit' ),
|
2017-03-24 01:19:16 +00:00
|
|
|
'readonly' => true,
|
2016-06-16 15:27:32 +00:00
|
|
|
),
|
|
|
|
'method_title' => array(
|
|
|
|
'description' => __( 'Shipping method title.', 'woocommerce' ),
|
|
|
|
'type' => 'string',
|
2016-08-31 21:16:52 +00:00
|
|
|
'context' => array( 'view', 'edit' ),
|
|
|
|
'readonly' => true,
|
2016-06-16 15:27:32 +00:00
|
|
|
),
|
|
|
|
'method_description' => array(
|
|
|
|
'description' => __( 'Shipping method description.', 'woocommerce' ),
|
|
|
|
'type' => 'string',
|
2016-08-31 21:16:52 +00:00
|
|
|
'context' => array( 'view', 'edit' ),
|
|
|
|
'readonly' => true,
|
2016-06-16 15:27:32 +00:00
|
|
|
),
|
2016-08-26 03:34:26 +00:00
|
|
|
'settings' => array(
|
|
|
|
'description' => __( 'Shipping method settings.', 'woocommerce' ),
|
2016-12-07 20:23:23 +00:00
|
|
|
'type' => 'object',
|
2016-08-26 03:34:26 +00:00
|
|
|
'context' => array( 'view', 'edit' ),
|
2017-03-21 20:47:28 +00:00
|
|
|
'properties' => array(
|
|
|
|
'id' => array(
|
|
|
|
'description' => __( 'A unique identifier for the setting.', 'woocommerce' ),
|
|
|
|
'type' => 'string',
|
|
|
|
'context' => array( 'view', 'edit' ),
|
|
|
|
'readonly' => true,
|
|
|
|
),
|
|
|
|
'label' => array(
|
2017-03-22 13:51:52 +00:00
|
|
|
'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ),
|
2017-03-21 20:47:28 +00:00
|
|
|
'type' => 'string',
|
|
|
|
'context' => array( 'view', 'edit' ),
|
|
|
|
'readonly' => true,
|
|
|
|
),
|
|
|
|
'description' => array(
|
2017-03-22 13:51:52 +00:00
|
|
|
'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ),
|
2017-03-21 20:47:28 +00:00
|
|
|
'type' => 'string',
|
|
|
|
'context' => array( 'view', 'edit' ),
|
|
|
|
'readonly' => true,
|
|
|
|
),
|
|
|
|
'type' => array(
|
|
|
|
'description' => __( 'Type of setting.', 'woocommerce' ),
|
|
|
|
'type' => 'string',
|
|
|
|
'context' => array( 'view', 'edit' ),
|
|
|
|
'enum' => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox' ),
|
|
|
|
'readonly' => true,
|
|
|
|
),
|
|
|
|
'value' => array(
|
|
|
|
'description' => __( 'Setting value.', 'woocommerce' ),
|
|
|
|
'type' => 'string',
|
|
|
|
'context' => array( 'view', 'edit' ),
|
|
|
|
),
|
|
|
|
'default' => array(
|
|
|
|
'description' => __( 'Default value for the setting.', 'woocommerce' ),
|
|
|
|
'type' => 'string',
|
|
|
|
'context' => array( 'view', 'edit' ),
|
|
|
|
'readonly' => true,
|
|
|
|
),
|
|
|
|
'tip' => array(
|
2017-03-22 13:51:52 +00:00
|
|
|
'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ),
|
2017-03-21 20:47:28 +00:00
|
|
|
'type' => 'string',
|
|
|
|
'context' => array( 'view', 'edit' ),
|
|
|
|
'readonly' => true,
|
|
|
|
),
|
|
|
|
'placeholder' => array(
|
|
|
|
'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ),
|
|
|
|
'type' => 'string',
|
|
|
|
'context' => array( 'view', 'edit' ),
|
|
|
|
'readonly' => true,
|
|
|
|
),
|
|
|
|
),
|
2016-08-26 03:34:26 +00:00
|
|
|
),
|
2016-06-16 15:27:32 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2016-06-17 20:59:36 +00:00
|
|
|
return $this->add_additional_fields_schema( $schema );
|
2016-06-16 15:27:32 +00:00
|
|
|
}
|
2016-07-26 18:42:57 +00:00
|
|
|
}
|