includes(); $this->api = new AfterShip_API(); $options = get_option('aftership_option_name'); if ($options) { if (isset($options['plugin'])) { $plugin = $options['plugin']; if ($plugin == 'aftership') { add_action('admin_print_scripts', array(&$this, 'library_scripts')); add_action('admin_print_styles', array(&$this, 'admin_styles')); add_action('add_meta_boxes', array(&$this, 'add_meta_box')); add_action('woocommerce_process_shop_order_meta', array(&$this, 'save_meta_box'), 0, 2); add_action('plugins_loaded', array($this, 'load_plugin_textdomain')); add_action('admin_footer', array(&$this, 'aftership_get_couriers')); add_action('wp_ajax_aftership_get_couriers_callback', array(&$this, 'aftership_get_couriers_callback')); } // View Order Page $this->plugin = $plugin; } if (isset($options['use_track_button'])) { $this->use_track_button = $options['use_track_button']; } add_action('woocommerce_view_order', array(&$this, 'display_tracking_info')); add_action('woocommerce_email_before_order_table', array(&$this, 'email_display')); } // user profile api key add_action('show_user_profile', array($this, 'add_api_key_field')); add_action('edit_user_profile', array($this, 'add_api_key_field')); add_action('personal_options_update', array($this, 'generate_api_key')); add_action('edit_user_profile_update', array($this, 'generate_api_key')); register_activation_hook(__FILE__, array($this, 'install')); } public function install() { global $wp_roles; if (class_exists('WP_Roles')) { if (!isset($wp_roles)) { $wp_roles = new WP_Roles(); } } if (is_object($wp_roles)) { $wp_roles->add_cap('administrator', 'manage_aftership'); } } private function includes() { include_once('class-aftership-api.php'); include_once('class-aftership-settings.php'); include_once('vendor/autoload.php'); } /** * Localisation */ public function load_plugin_textdomain() { load_plugin_textdomain('aftership', false, dirname(plugin_basename(__FILE__)) . '/languages/'); } public function admin_styles() { wp_enqueue_style('aftership_styles', plugins_url(basename(dirname(__FILE__))) . '/assets/css/admin.css'); } public function library_scripts() { wp_enqueue_script('aftership_script', plugins_url(basename(dirname(__FILE__))) . '/assets/js/admin.js'); } public function aftership_get_couriers() { //todo: not only check shop_order, have to check action=edit too if (get_post_type(get_the_ID()) == 'shop_order') { $js = ' jQuery(document).ready(function($) { var data = { "action": "aftership_get_couriers_callback" }; // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php $.post(ajaxurl, data, function(response) { //alert("Got this from the server: " + response); fill_meta_box(response); }); }); '; if (function_exists('wc_enqueue_js')) { wc_enqueue_js($js); } else { global $woocommerce; $woocommerce->add_inline_js($js); } } } public function aftership_get_couriers_callback() { $options = get_option('aftership_option_name'); $api_key = $options['api_key']; $code = 200; $message = ''; $response = ''; if (!$api_key) { $code = 800; // no api key $message = 'No Api Key'; } else { $courier = new AfterShip\Couriers($api_key); $response = $courier->get(); if ($response['meta']['code'] == 401) { $code = 401; $message = 'Invalid API'; } else if ($response['meta']['code'] != 200) { $code = $response['meta']['code']; $message = $response['meta']['message']; } } $result = array( 'code' => $code, 'message' => $message, 'response' => $response); echo json_encode($result); die; } /** * Add the meta box for shipment info on the order page * * @access public */ public function add_meta_box() { add_meta_box('woocommerce-aftership', __('AfterShip', 'wc_aftership'), array(&$this, 'meta_box'), 'shop_order', 'side', 'high'); } /** * Show the meta box for shipment info on the order page * * @access public */ public function meta_box() { // just draw the layout, no data global $post; $selected_provider = get_post_meta($post->ID, '_aftership_tracking_provider', true); echo '
'; echo ''; echo ''; echo ''; echo '
';
echo '
Update carrier list';
echo '';
woocommerce_wp_text_input(array(
'id' => 'aftership_tracking_provider_name',
'label' => __('', 'wc_aftership'),
'placeholder' => '',
'description' => '',
'class' => 'hidden',
'value' => get_post_meta($post->ID, '_aftership_tracking_provider_name', true),
));
woocommerce_wp_text_input(array(
'id' => 'aftership_tracking_required_fields',
'label' => __('', 'wc_aftership'),
'placeholder' => '',
'description' => '',
'class' => 'hidden',
'value' => get_post_meta($post->ID, '_aftership_tracking_required_fields', true),
));
woocommerce_wp_text_input(array(
'id' => 'aftership_tracking_number',
'label' => __('Tracking number:', 'wc_aftership'),
'placeholder' => '',
'description' => '',
'value' => get_post_meta($post->ID, '_aftership_tracking_number', true),
));
woocommerce_wp_text_input(array(
'id' => 'aftership_tracking_shipdate',
'label' => __('Date shipped:', 'wc_aftership'),
'placeholder' => 'YYYY-MM-DD',
'description' => '',
'class' => 'date-picker-field hidden-field',
'value' => ($date = get_post_meta($post->ID, '_aftership_tracking_shipdate', true)) ? date('Y-m-d', $date) : ''
));
woocommerce_wp_text_input(array(
'id' => 'aftership_tracking_postal',
'label' => __('Postal Code:', 'wc_aftership'),
'placeholder' => '',
'description' => '',
'class' => 'hidden-field',
'value' => get_post_meta($post->ID, '_aftership_tracking_postal', true),
));
woocommerce_wp_text_input(array(
'id' => 'aftership_tracking_account',
'label' => __('Account name:', 'wc_aftership'),
'placeholder' => '',
'description' => '',
'class' => 'hidden-field',
'value' => get_post_meta($post->ID, '_aftership_tracking_account', true),
));
echo '
aftership_wp_api_key)) : ?>
aftership_wp_api_key ?>
|