tab_class = 'a2wl_product_data'; $this->tab_id = 'a2wl_product_data'; $this->tab_title = 'A2WL Data'; add_action('admin_head', array(&$this, 'on_admin_head')); add_action('woocommerce_product_write_panel_tabs', array(&$this, 'product_write_panel_tabs'), 99); add_action('woocommerce_product_data_panels', array(&$this, 'product_data_panel_wrap'), 99); add_action('woocommerce_process_product_meta', array(&$this, 'process_meta_box'), 1, 2); add_action('woocommerce_variation_options_pricing', array(&$this, 'variation_options_pricing'), 20, 3); add_action('wp_ajax_a2wl_data_remove_deleted_attribute', array($this, 'ajax_remove_deleted_attribute')); add_action('wp_ajax_a2wl_data_remove_deleted_variation', array($this, 'ajax_remove_deleted_variation')); add_action('wp_ajax_a2wl_data_last_update_clean', array($this, 'ajax_last_update_clean')); } public function on_admin_head() { echo ''; } public function product_write_panel_tabs() { ?>
  • tab_title; ?>
  • '; woocommerce_wp_text_input(array( 'id' => '_a2wl_external_id', 'value' => get_post_meta($post->ID, '_a2wl_external_id', true), 'label' => __('External Id', 'ali2woo-lite'), 'desc_tip' => true, 'description' => __('External Aliexpress Product Id', 'ali2woo-lite'), )); woocommerce_wp_text_input(array( 'id' => '_a2wl_orders_count', 'value' => get_post_meta($post->ID, '_a2wl_orders_count', true), 'label' => __('Orders count', 'ali2woo-lite'), 'desc_tip' => true, 'description' => __('Aliexpress orders count', 'ali2woo-lite'), )); $disable_sync = get_post_meta($post->ID, '_a2wl_disable_sync', true); woocommerce_wp_checkbox(array( 'id' => '_a2wl_disable_sync', 'value' => $disable_sync ? 'yes' : 'no', 'label' => __('Disable synchronization?', 'ali2woo-lite'), 'description' => __('Disable global synchronization for this product', 'ali2woo-lite'), )); echo ''; woocommerce_wp_checkbox(array( 'id' => '_a2wl_disable_var_price_change', 'value' => get_post_meta($post->ID, '_a2wl_disable_var_price_change', true) ? 'yes' : 'no', 'label' => __('Disable price change?', 'ali2woo-lite'), 'description' => __('Disable variations price change', 'ali2woo-lite'), )); woocommerce_wp_checkbox(array( 'id' => '_a2wl_disable_var_quantity_change', 'value' => get_post_meta($post->ID, '_a2wl_disable_var_quantity_change', true) ? 'yes' : 'no', 'label' => __('Disable quantity change?', 'ali2woo-lite'), 'description' => __('Disable variations quantity change', 'ali2woo-lite'), )); if ($disable_sync) { echo ''; } woocommerce_wp_text_input(array( 'id' => '_a2wl_product_url', 'value' => get_post_meta($post->ID, '_a2wl_product_url', true), 'label' => __('Product url', 'ali2woo-lite'), 'desc_tip' => true, 'description' => __('Affiliate product url', 'ali2woo-lite'), )); woocommerce_wp_text_input(array( 'id' => '_a2wl_original_product_url', 'value' => get_post_meta($post->ID, '_a2wl_original_product_url', true), 'label' => __('Original product url', 'ali2woo-lite'), 'desc_tip' => true, 'description' => __('Original product url', 'ali2woo-lite'), )); echo ''; echo '
    '; $last_update = get_post_meta($post->ID, '_a2wl_last_update', true); echo '

    '.($last_update?date("F j, Y, H:m:s", $last_update).' Clean':'Not set').'

    '; echo ''; echo '
    '; echo '
    '; $deleted_variations_attributes = get_post_meta($post->ID, '_a2wl_deleted_variations_attributes', true); echo '

    '; echo ''; echo ''; if (empty($deleted_variations_attributes)) { echo '' . __('No deleted attributes of variations', 'ali2woo-lite') . ''; } else { foreach ($deleted_variations_attributes as $ka => $av) { echo '' . $av['current_name'] . ' '; } } echo ''; echo ''; echo '

    '; echo '
    '; echo '
    '; echo '

    '; echo ''; echo ''; $skip_meta = get_post_meta($post->ID, "_a2wl_skip_meta", true); if (!empty($skip_meta['skip_vars']) && is_array($skip_meta['skip_vars'])) { foreach ($skip_meta['skip_vars'] as $v) { echo '' . $v . ' '; } } else { echo '' . __('No deleted variations', 'ali2woo-lite') . ''; } echo ''; echo ''; echo '

    '; echo '
    '; } public function process_meta_box($post_id, $post) { if (isset($_POST['_a2wl_external_id'])) { update_post_meta($post_id, '_a2wl_external_id', $_POST['_a2wl_external_id']); if(!get_post_meta($post_id, '_a2wl_import_type', true)){ add_post_meta($post_id, '_a2wl_import_type', 'a2wl'); } } else { delete_post_meta($post_id, '_a2wl_external_id'); delete_post_meta($post_id, '_a2wl_import_type'); } if (isset($_POST['_a2wl_orders_count'])) { update_post_meta($post_id, '_a2wl_orders_count', $_POST['_a2wl_orders_count']); } else { delete_post_meta($post_id, '_a2wl_orders_count'); } if (isset($_POST['_a2wl_product_url'])) { update_post_meta($post_id, '_a2wl_product_url', $_POST['_a2wl_product_url']); } else { delete_post_meta($post_id, '_a2wl_product_url'); } if (isset($_POST['_a2wl_original_product_url'])) { update_post_meta($post_id, '_a2wl_original_product_url', $_POST['_a2wl_original_product_url']); } else { delete_post_meta($post_id, '_a2wl_original_product_url'); } update_post_meta($post_id, '_a2wl_disable_sync', !empty($_POST['_a2wl_disable_sync']) ? 1 : 0); update_post_meta($post_id, '_a2wl_disable_var_price_change', !empty($_POST['_a2wl_disable_var_price_change']) ? 1 : 0); update_post_meta($post_id, '_a2wl_disable_var_quantity_change', !empty($_POST['_a2wl_disable_var_quantity_change']) ? 1 : 0); if (!empty($_POST['_a2wl_last_update'])) { update_post_meta($post_id, '_a2wl_last_update', $_POST['_a2wl_last_update']); } else { delete_post_meta($post_id, '_a2wl_last_update'); } } public function variation_options_pricing($loop, $variation_data, $variation) { if (!empty($variation_data['_aliexpress_regular_price']) || !empty($variation_data['_aliexpress_price'])) { echo '

    '; if (!empty($variation_data['_aliexpress_regular_price'])) { $label = sprintf(__('Aliexpress Regular price (%s)', 'ali2woo-lite'), get_woocommerce_currency_symbol()); echo '  '; } echo ' 

    '; echo '

    '; if (!empty($variation_data['_aliexpress_price'])) { $label = sprintf(__('Aliexpress Sale price (%s)', 'ali2woo-lite'), get_woocommerce_currency_symbol()); echo '  '; } echo ' 

    '; } } public function ajax_remove_deleted_attribute() { if (!empty($_POST['post_id']) && !empty($_POST['id'])) { $deleted_variations_attributes = get_post_meta($_POST['post_id'], '_a2wl_deleted_variations_attributes', true); if ($deleted_variations_attributes) { foreach ($deleted_variations_attributes as $k => $a) { if ($k == sanitize_title($_POST['id'])) { unset($deleted_variations_attributes[$k]); } } } update_post_meta($_POST['post_id'], '_a2wl_deleted_variations_attributes', $deleted_variations_attributes); } echo json_encode(A2WL_ResultBuilder::buildOk()); wp_die(); } public function ajax_remove_deleted_variation() { if (!empty($_POST['post_id']) && !empty($_POST['id'])) { $a2wl_skip_meta = get_post_meta($_POST['post_id'], "_a2wl_skip_meta", true); $a2wl_skip_meta = $a2wl_skip_meta?$a2wl_skip_meta:array('skip_vars' => array(), 'skip_images' => array()); $a2wl_skip_meta['skip_vars'] = array_diff($a2wl_skip_meta['skip_vars'], array($_POST['id'])); update_post_meta($_POST['post_id'], "_a2wl_skip_meta", $a2wl_skip_meta); } echo json_encode(A2WL_ResultBuilder::buildOk()); wp_die(); } public function ajax_last_update_clean() { if (!empty($_POST['post_id']) && !empty($_POST['type'])) { if($_POST['type'] === 'product'){ delete_post_meta($_POST['post_id'], '_a2wl_last_update'); } } echo json_encode(A2WL_ResultBuilder::buildOk()); wp_die(); } } }