function woocommerce_osc_run_cats($parent = 0, $parent_term_id = 0) { global $wpdb, $oscdb, $import_cat_counter; $categories = $oscdb->get_results("SELECT c.*, cd.* FROM categories c, categories_description cd WHERE c.categories_id=cd.categories_id AND cd.language_id=1 AND c.parent_id='" . (int) $parent . "'", ARRAY_A); if (!empty($categories)) { foreach ($categories as $category) { if (!is_wp_error($category)) { $term = term_exists($category['categories_name'], 'product_cat', (int) $parent_term_id); // array is returned if taxonomy is given if ((int) $term['term_id'] == 0) { $term = wp_insert_term($category['categories_name'], 'product_cat', array('parent' => $parent_term_id)); delete_option('product_cat_children'); // clear the cache $attach_id = 0; if ($category['categories_image'] != '') { $url = rtrim($_POST['store_url'], '/') . '/images/' . urlencode($category['categories_image']); $attach_id = woocommerce_osc_import_image($url); } add_woocommerce_term_meta($term['term_id'], 'order', $category['sort_order']); add_woocommerce_term_meta($term['term_id'], 'display_type', ''); add_woocommerce_term_meta($term['term_id'], 'thumbnail_id', (int) $attach_id); add_woocommerce_term_meta($term['term_id'], 'osc_id', $category['categories_id']); woocommerce_osc_run_cats($category['categories_id'], $term['term_id']); $import_cat_counter++; } else { woocommerce_osc_run_cats($category['categories_id'], $term['term_id']); } } } } }
function category_field_save($term_id, $tt_id, $taxonomy) { $restrictions_enabled = isset($_POST['_wc_restrictions']) ? $_POST['_wc_restrictions'] : false; if (empty($restrictions_enabled) || $restrictions_enabled == 'no-restriction-setting') { delete_woocommerce_term_meta($term_id, '_wc_restrictions'); delete_woocommerce_term_meta($term_id, '_wc_restrictions_allowed'); } else { update_woocommerce_term_meta($term_id, '_wc_restrictions', $restrictions_enabled); delete_woocommerce_term_meta($term_id, '_wc_restrictions_allowed'); if ($restrictions_enabled == 'restricted') { $restrictions = isset($_POST['wc_restrictions_allowed']) ? $_POST['wc_restrictions_allowed'] : array(''); foreach ($restrictions as $role) { add_woocommerce_term_meta($term_id, '_wc_restrictions_allowed', $role); } } } $restrictions_location_enabled = isset($_POST['_wc_restrictions_location']) ? $_POST['_wc_restrictions_location'] : false; if (empty($restrictions_location_enabled) || $restrictions_location_enabled == 'no-restriction-setting') { delete_woocommerce_term_meta($term_id, '_wc_restrictions_location'); delete_woocommerce_term_meta($term_id, '_wc_restrictions_locations'); } else { update_woocommerce_term_meta($term_id, '_wc_restrictions_location', $restrictions_location_enabled); delete_woocommerce_term_meta($term_id, '_wc_restrictions_locations'); if ($restrictions_location_enabled == 'restricted') { $restrictions = isset($_POST['wc_restrictions_locations']) ? $_POST['wc_restrictions_locations'] : array(''); foreach ($restrictions as $location) { add_woocommerce_term_meta($term_id, '_wc_restrictions_locations', $location); } } } }
/** * HTML setup for the Orders Page */ public static function shipping_page() { global $WCMp, $post; $vendor_user_id = get_current_user_id(); $vendor_data = get_wcmp_vendor($vendor_user_id); if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['vendor_shipping_data'])) { $fee = 0; $vendor_shipping_data = get_user_meta($vendor_user_id, 'vendor_shipping_data', true); $cost = isset($_POST['vendor_shipping_data']['shipping_amount']) ? stripslashes($_POST['vendor_shipping_data']['shipping_amount']) : 0; $international_cost = isset($_POST['vendor_shipping_data']['international_shipping_amount']) ? stripslashes($_POST['vendor_shipping_data']['international_shipping_amount']) : 0; $fee = isset($_POST['vendor_shipping_data']['handling_amount']) ? $_POST['vendor_shipping_data']['handling_amount'] : 0; if (!empty($cost)) { $shipping_updt = true; $dc_flat_rates = array(); if (!term_exists($vendor_data->user_data->user_login, 'product_shipping_class')) { $shipping_term = wp_insert_term($vendor_data->user_data->user_login, 'product_shipping_class'); $shipping_term_id = $shipping_term['term_id']; if (!is_wp_error($shipping_term)) { update_user_meta($vendor_user_id, 'shipping_class_id', $shipping_term['term_id']); add_woocommerce_term_meta($shipping_term['term_id'], 'vendor_id', $vendor_user_id); add_woocommerce_term_meta($shipping_term['term_id'], 'vendor_shipping_origin', $_POST['vendor_shipping_data']['ship_from']); } else { $shipping_updt = false; } } else { $shipping_class_id = get_user_meta($vendor_user_id, 'shipping_class_id', true); update_woocommerce_term_meta($shipping_class_id, 'vendor_shipping_origin', $_POST['vendor_shipping_data']['ship_from']); $shipping_term_id = $shipping_class_id; } if (version_compare(WC_VERSION, '2.5.0', '>=')) { $woocommerce_flat_rate_settings = get_option('woocommerce_flat_rate_settings'); $woocommerce_flat_rate_settings['class_cost_' . $shipping_term_id] = stripslashes($cost); update_option('woocommerce_flat_rate_settings', $woocommerce_flat_rate_settings); $woocommerce_international_delivery_settings = get_option('woocommerce_international_delivery_settings'); $woocommerce_international_delivery_settings['class_cost_' . $shipping_term_id] = stripslashes($international_cost); update_option('woocommerce_international_delivery_settings', $woocommerce_international_delivery_settings); } else { if (version_compare(WC_VERSION, '2.4.0', '>')) { $woocommerce_flat_rate_settings = get_option('woocommerce_flat_rate_settings'); $woocommerce_flat_rate_settings['class_cost_' . sanitize_title($vendor_data->user_data->user_login)] = $cost; update_option('woocommerce_flat_rate_settings', $woocommerce_flat_rate_settings); $woocommerce_international_delivery_settings = get_option('woocommerce_international_delivery_settings'); $woocommerce_international_delivery_settings['class_cost_' . sanitize_title($vendor_data->user_data->user_login)] = $international_cost; update_option('woocommerce_international_delivery_settings', $woocommerce_international_delivery_settings); } else { $woocommerce_flat_rates = get_option('woocommerce_flat_rates'); $woocommerce_flat_rates[sanitize_title($vendor_data->user_data->user_login)] = array('cost' => $cost, 'fee' => $fee); update_option('woocommerce_flat_rates', $woocommerce_flat_rates); } } update_user_meta($vendor_user_id, 'vendor_shipping_data', $_POST['vendor_shipping_data']); if ($shipping_updt) { echo '<div class="updated">' . __("Shipping Data Updated.", $WCMp->text_domain) . '</div>'; } else { echo '<div class="error">' . __("Shipping Data Not Updated.", $WCMp->text_domain) . '</div>'; delete_user_meta($vendor_user_id, 'vendor_shipping_data'); } } else { echo '<div class="error">' . __("Specify Shipping Amount.", $WCMp->text_domain) . '</div>'; } } } $vendor_shipping_data = get_user_meta($vendor_user_id, 'vendor_shipping_data', true); ?> <div class="wrap"> <div id="icon-woocommerce" class="icon32 icon32-woocommerce-reports"><br/></div> <h2><?php _e('Shipping', $WCMp->text_domain); ?> </h2> <form name="vendor_shipping_form" method="post"> <table> <tbody> <?php if (version_compare(WC_VERSION, '2.4.0', '>')) { ?> <tr> <td><label><?php _e('Enter Shipping Amount for "Flat Rate" :', $WCMp->text_domain); ?> </label></td> <td><input name="vendor_shipping_data[shipping_amount]" type="text" step="0.01" value='<?php echo isset($vendor_shipping_data['shipping_amount']) ? $vendor_shipping_data['shipping_amount'] : ''; ?> ' /></td> </tr> <tr><td></td><td><?php _e('Enter a cost (excl. tax) or sum, e.g. <code>10.00 * [qty]</code>. Supports the following placeholders: <code>[qty]</code> = number of items, <code>[cost]</code> = cost of items,<br><code>[fee percent="10" min_fee="20"]</code> = Percentage based fee.', $WCMp->text_domain); ?> <br><br></td></tr> <tr> <td><label><?php _e('Enter Shipping Amount for "International Flat Rate" :', $WCMp->text_domain); ?> </label></td> <td><input name="vendor_shipping_data[international_shipping_amount]" type="text" step="0.01" value='<?php echo isset($vendor_shipping_data['international_shipping_amount']) ? $vendor_shipping_data['international_shipping_amount'] : ''; ?> ' /></td> </tr> <tr><td></td><td><?php _e('Enter a cost (excl. tax) or sum, e.g. <code>10.00 * [qty]</code>. Supports the following placeholders: <code>[qty]</code> = number of items, <code>[cost]</code> = cost of items,<br><code>[fee percent="10" min_fee="20"]</code> = Percentage based fee.', $WCMp->text_domain); ?> <br><br></td></tr> <?php } else { ?> <tr> <td><label><?php _e('Enter Shipping Amount :', $WCMp->text_domain); ?> </label></td> <td><input name="vendor_shipping_data[shipping_amount]" type="text" step="0.01" value='<?php echo isset($vendor_shipping_data['shipping_amount']) ? $vendor_shipping_data['shipping_amount'] : ''; ?> ' /></td> </tr> <tr> <td><label><?php _e('Enter Handling Fee :', $WCMp->text_domain); ?> </label></td> <td><input name="vendor_shipping_data[handling_amount]" type="number" step="0.01" value='<?php echo isset($vendor_shipping_data['handling_amount']) ? $vendor_shipping_data['handling_amount'] : ''; ?> ' /></td> </tr> <?php } ?> <tr> <td><label><?php _e('Ship from :', $WCMp->text_domain); ?> </label></td> <td><input name="vendor_shipping_data[ship_from]" type="text" value="<?php echo isset($vendor_shipping_data['ship_from']) ? $vendor_shipping_data['ship_from'] : ''; ?> " /></td> </tr> </tbody> </table> <?php submit_button(); ?> </form> <br class="clear"/> </div> <?php }
function category_field_save($term_id, $tt_id, $taxonomy) { $restrictions_enabled = filter_input(INPUT_POST, '_wc_restrictions', FILTER_SANITIZE_STRIPPED); if ($restrictions_enabled == 'no-restriction-setting') { delete_woocommerce_term_meta($term_id, '_wc_restrictions'); delete_woocommerce_term_meta($term_id, '_wc_restrictions_allowed'); } else { update_woocommerce_term_meta($term_id, '_wc_restrictions', $restrictions_enabled); delete_woocommerce_term_meta($term_id, '_wc_restrictions_allowed'); if ($restrictions_enabled == 'restricted') { $restrictions = isset($_POST['wc_restrictions_allowed']) ? $_POST['wc_restrictions_allowed'] : array(''); foreach ($restrictions as $role) { add_woocommerce_term_meta($term_id, '_wc_restrictions_allowed', $role); } } } $restrictions_location_enabled = filter_input(INPUT_POST, '_wc_restrictions_location', FILTER_SANITIZE_STRIPPED); if ($restrictions_location_enabled == 'no-restriction-setting') { delete_woocommerce_term_meta($term_id, '_wc_restrictions_location'); delete_woocommerce_term_meta($term_id, '_wc_restrictions_locations'); } else { update_woocommerce_term_meta($term_id, '_wc_restrictions_location', $restrictions_location_enabled); delete_woocommerce_term_meta($term_id, '_wc_restrictions_locations'); if ($restrictions_location_enabled == 'restricted') { $restrictions = isset($_POST['wc_restrictions_locations']) ? $_POST['wc_restrictions_locations'] : array(''); foreach ($restrictions as $location) { add_woocommerce_term_meta($term_id, '_wc_restrictions_locations', $location); } } } }
$international_cost = $_POST['vendor_shipping_data']['international_shipping_amount']; $fee = isset($_POST['vendor_shipping_data']['handling_amount']) ? $_POST['vendor_shipping_data']['handling_amount'] : ''; if (isset($_POST['vendor_shipping_data']['shipping_amount'])) { $shipping_updt = true; $dc_flat_rates = array(); $shipping_class_id = get_user_meta($vendor_user_id, 'shipping_class_id', true); if (!empty($shipping_class_id)) { $term_shipping_obj = get_term_by('id', $shipping_class_id, 'product_shipping_class'); } if (!(isset($term_shipping_obj) && isset($term_shipping_obj->term_id) && !empty($term_shipping_obj))) { $shipping_term = wp_insert_term($vendor_data->user_data->user_login . '-' . $vendor_user_id, 'product_shipping_class'); if (!is_wp_error($shipping_term)) { $shipping_term_id = $shipping_term['term_id']; update_user_meta($vendor_user_id, 'shipping_class_id', $shipping_term['term_id']); add_woocommerce_term_meta($shipping_term['term_id'], 'vendor_id', $vendor_user_id); add_woocommerce_term_meta($shipping_term['term_id'], 'vendor_shipping_origin', $_POST['vendor_shipping_data']['ship_from']); } else { $shipping_updt = false; } } else { $shipping_class_id = get_user_meta($vendor_user_id, 'shipping_class_id', true); if (empty($shipping_class_id)) { $sterm = get_term_by('slug', $vendor_data->user_data->user_login . '-' . $vendor_user_id, 'shipping_class_id'); if (isset($sterm->term_id) && !empty($sterm->term_id)) { $shipping_class_id = $sterm->term_id; update_user_meta($vendor_user_id, 'shipping_class_id', $shipping_class_id); } } $shipping_term_id = $shipping_class_id; update_woocommerce_term_meta($shipping_class_id, 'vendor_shipping_origin', $_POST['vendor_shipping_data']['ship_from']); }
/** * Add Product Cat * * @since 1.0 * * @param $term_id * @param $name * @param $slug * @param $taxonomy * @param $parent * @param $description * @param $thumbnail */ function kt_add_product_cat($term_id, $name, $slug, $taxonomy, $parent, $description, $thumbnail = 0) { global $categories_id; $new_cat_id = kt_get_cate_id($term_id); if (!$new_cat_id) { //all categories $ids = $categories_id; if (!taxonomy_exists($taxonomy)) { register_taxonomy('product_cat', apply_filters('woocommerce_taxonomy_objects_product_cat', array('product')), apply_filters('woocommerce_taxonomy_args_product_cat', array('hierarchical' => true, 'update_count_callback' => '_wc_term_recount', 'label' => __('Product Categories', 'woocommerce'), 'labels' => array('name' => __('Product Categories', 'woocommerce'), 'singular_name' => __('Product Category', 'woocommerce'), 'menu_name' => _x('Categories', 'Admin menu name', 'woocommerce'), 'search_items' => __('Search Product Categories', 'woocommerce'), 'all_items' => __('All Product Categories', 'woocommerce'), 'parent_item' => __('Parent Product Category', 'woocommerce'), 'parent_item_colon' => __('Parent Product Category:', 'woocommerce'), 'edit_item' => __('Edit Product Category', 'woocommerce'), 'update_item' => __('Update Product Category', 'woocommerce'), 'add_new_item' => __('Add New Product Category', 'woocommerce'), 'new_item_name' => __('New Product Category Name', 'woocommerce')), 'show_ui' => true, 'query_var' => true, 'capabilities' => array('manage_terms' => 'manage_product_terms', 'edit_terms' => 'edit_product_terms', 'delete_terms' => 'delete_product_terms', 'assign_terms' => 'assign_product_terms'), 'rewrite' => array('slug' => empty($permalinks['category_base']) ? _x('product-category', 'slug', 'woocommerce') : $permalinks['category_base'], 'with_front' => false, 'hierarchical' => true)))); } if (!$parent) { $new_cat_id = wp_insert_term($name, $taxonomy, array('description' => $description, 'slug' => $slug, 'parent' => $ids[$parent])); } else { if ($ids[$parent]) { $new_cat_id = wp_insert_term($name, $taxonomy, array('description' => $description, 'slug' => $slug, 'parent' => $ids[$parent])); } else { //The categoy have been waiting $cate_add_after = get_option('kt_demo_categories_add_before'); if ($cate_add_after && count($cate_add_after)) { foreach ($cate_add_after as $after) { kt_add_category($after); } } $cate_add_after[] = $cat; update_option('kt_demo_categories_add_before', $cate_add_after); } } if (!is_wp_error($new_cat_id)) { if (is_array($new_cat_id) && isset($new_cat_id['term_id'])) { $ids[$term_id] = array('id' => $new_cat_id['term_id'], 'tax' => $taxonomy); } else { $ids[$term_id] = array('id' => $new_cat_id, 'tax' => $taxonomy); } $categories_id = $ids; update_option('kt_demo_categories', $categories_id); //Update thumbnail if ($thumbnail) { $thumnail_id = kt_get_post_id($thumbnail, 'attachment', 'kt_demo_attachment'); if (function_exists('add_woocommerce_term_meta')) { return add_woocommerce_term_meta($new_cat_id['term_id'], 'thumbnail_id', $thumnail_id, false); } else { return add_metadata('woocommerce_term', $new_cat_id['term_id'], 'thumbnail_id', $thumnail_id, false); } } } else { return; } } return $new_cat_id; }
function update_post_id() { global $wpdb; $sql_str = "UPDATE {$wpdb->term_taxonomy} tt SET count = (SELECT count(p.ID) FROM {$wpdb->term_relationships} tr LEFT JOIN wp_posts p ON (p.ID = tr.object_id AND p.post_status = 'publish') WHERE tr.term_taxonomy_id = tt.term_taxonomy_id)"; $wpdb->query($sql_str); require_once ABSPATH . 'wp-admin/includes/file.php'; WP_Filesystem(); global $wp_filesystem; $datas_file = (array) json_decode($wp_filesystem->get_contents(CHANGE_DATA_FILE), true); // change ID of Primary, One-page Menu $data = get_option('theme_mods_' . get_option("stylesheet")); if (isset($data['nav_menu_locations'])) { foreach ($data['nav_menu_locations'] as $key => $value) { $slug_obj = $this->get_slug_by_id($datas_file, 'nav_menu', $value); $term = get_term_by('slug', $slug_obj, 'nav_menu'); if ($term) { $data['nav_menu_locations'][$key] = $term->term_id; } } } update_option('theme_mods_' . get_option("stylesheet"), $data); unset($data); // Change nav_menu ID in widget $rows = $wpdb->get_results($wpdb->prepare("SELECT option_name FROM {$wpdb->options} WHERE option_name like %s", 'widget_%')); foreach ($rows as $row) { if ($row->option_name == 'widget_nav_menu') { $data = get_option($row->option_name); if (isset($data) && is_array($data)) { foreach ($data as $key => $value) { if (is_array($value) && isset($value['nav_menu'])) { $slug_obj = $this->get_slug_by_id($datas_file, 'nav_menu', $value['nav_menu']); $term = get_term_by('slug', $slug_obj, 'nav_menu'); if ($term) { $data[$key]['nav_menu'] = $term->term_id; } } } } update_option($row->option_name, $data); } } // Update PageId foreach ($datas_file['page'] as $key => $value) { if ($value) { $slug_obj = $this->get_slug_by_id($datas_file, 'page-slug', $value); $page_new_obj = get_page_by_path($slug_obj); if ($page_new_obj) { update_option($key, $page_new_obj->ID); } } } // Update ACF for category & product_cat $process_term_ids = array(); foreach ($datas_file['product_cat'] as $key => $value) { $term = get_term_by('slug', $key, 'product_cat'); if ($term) { $process_term_ids[$value] = $term->term_id; } } foreach ($datas_file['category'] as $key => $value) { $term = get_term_by('slug', $key, 'category'); if ($term) { $process_term_ids[$value] = $term->term_id; } } $arr_cate = array('category_', '_category_', 'product_cat_', '_product_cat_'); foreach ($datas_file['acf'] as $key => $value) { foreach ($arr_cate as $cate_prefix) { if (strrpos($key, $cate_prefix) === 0) { $key = preg_replace_callback('|' . $cate_prefix . '([0-9]+)_((.)+)|', function ($aMatches) use($cate_prefix, $process_term_ids) { $new_term_id = isset($process_term_ids[$aMatches[1] + 0]) ? $process_term_ids[$aMatches[1] + 0] : $aMatches[1]; return $cate_prefix . $new_term_id . '_' . $aMatches[2]; }, $key); update_option($key, $value); break; } } } // Update Woocommer Meta Term foreach ($datas_file['woocommerce_termmeta'] as $key => $value) { $new_term_id = isset($process_term_ids[$key]) ? $process_term_ids[$key] : $key; $meta_value = $value; if ($value) { $slug_obj = $this->get_slug_by_id($datas_file, 'page-slug', $value); $page_new_obj = get_page_by_path($slug_obj, OBJECT, 'attachment'); if ($page_new_obj) { $meta_value = $page_new_obj->ID; } } add_woocommerce_term_meta($new_term_id, 'thumbnail_id', $meta_value); } }