get_var("SELECT count(*) FROM $wpdb->postmeta WHERE meta_key='aeidn_import'"); } public function init() { if (get_option('aeidn_price_auto_update', false)) { $this->bulkActions[] = 'aeidn_product_update_manual'; $update_price = get_option('aeidn_regular_price_auto_update', false); $text = 'Update stock'; if ($update_price) { $text = "Update price & stock"; } $this->bulkActionsText['aeidn_product_update_manual'] = $text; } list($this->bulkActions, $this->bulkActionsText) = apply_filters('aeidn_wcpl_bulk_actions_init', array($this->bulkActions, $this->bulkActionsText)); } public function rowActions($actions, $post) { if ('product' === $post->post_type) { $external_id = get_post_meta($post->ID, "external_id", true); if ($external_id) { $actions = array_merge($actions, array( 'aeidn_product_info' => sprintf('%2$s', $post->ID, 'AliExpressImporter Info' ) )); return $actions; } else { return $actions; } } return []; } public function assets() { $plugin_data = get_plugin_data(AEIDN_FILE_FULLNAME); wp_enqueue_style('aeidn-wc-pl-style', plugins_url('assets/css/wc_pl_style.css', AEIDN_FILE_FULLNAME), array(), $plugin_data['Version']); wp_enqueue_script('jquery-ui-dialog'); wp_enqueue_script('aeidn-wc-pl-script', plugins_url('assets/js/wc_pl_script.js', AEIDN_FILE_FULLNAME), array(), $plugin_data['Version']); } public function scripts() { global $post_type; if ($post_type === 'product') { foreach ($this->bulkActions as $action) { $text = $this->bulkActionsText[$action]; ?> current_action(); $allowed_actions = $this->bulkActions; if (!in_array($action, $allowed_actions, false)) { return; } check_admin_referer('bulk-posts'); // make sure ids are submitted. depending on the resource type, this may be 'media' or 'ids' if (isset($_REQUEST['post'])) { $post_ids = array_map('intval', $_REQUEST['post']); } if (empty($post_ids)) { return; } $sendback = remove_query_arg(array_merge($allowed_actions, array('untrashed', 'deleted', 'ids')), wp_get_referer()); if (!$sendback) { $sendback = admin_url("edit.php?post_type=$post_type"); } $pagenum = $wp_list_table->get_pagenum(); $sendback = add_query_arg('paged', $pagenum, $sendback); if ($action === 'aeidn_product_update_manual') { $updated = 0; $skiped = 0; foreach ($post_ids as $post_id) { $result = $this->performUpdate($post_id); if ($result === -1) { $skiped++; } else if (!$result) { wp_die(__('Error updating product.')); } else { $updated++; } } $sendback = add_query_arg(array('aeidn_updated' => $updated, 'aeidn_skiped' => $skiped, 'ids' => implode(',', $post_ids)), $sendback); } $sendback = apply_filters('aeidn_wcpl_bulk_actions_perform', $sendback, $action, $post_ids); $sendback = remove_query_arg(array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'), $sendback); wp_redirect($sendback); exit(); } } public function adminNotices() { global $post_type, $pagenow; if ($pagenow === 'edit.php' && $post_type === 'product' && isset($_REQUEST['aeidn_updated']) && (int)$_REQUEST['aeidn_updated']) { $message = sprintf(_n('Product updated.', '%s products updated.', $_REQUEST['aeidn_updated']), number_format_i18n($_REQUEST['aeidn_updated'])); if (isset($_REQUEST['aeidn_skiped']) && (int)$_REQUEST['aeidn_skiped']) { $message .= ' And ' . sprintf(_n('one product skiped.', '%s products skiped.', $_REQUEST['aeidn_skiped']), number_format_i18n($_REQUEST['aeidn_skiped'])); } echo "

{$message}

"; } } public function performUpdate($post_id) { $external_id = get_post_meta($post_id, "external_id", true); if ($external_id) { aeidn_update_price_proc($post_id, false); return true; } return -1; } } } new AEIDN_WooCommerce_ProductList();