Ejemplo n.º 1
0
 function woo_st_clear_dataset($export_type = '', $data = false)
 {
     global $wpdb;
     if (empty($export_type)) {
         return false;
     }
     // Commence the drop
     woo_st_update_option('in_progress', $export_type);
     switch ($export_type) {
         // WooCommerce
         case 'product':
             $post_type = array('product', 'product_variation');
             $args = array('post_type' => $post_type, 'fields' => 'ids', 'post_status' => woo_st_post_statuses(), 'numberposts' => 100);
             // Loop through every 100 records until 0 is returned, might take awhile
             while (woo_st_return_count('product')) {
                 $products = get_posts($args);
                 if (!empty($products)) {
                     foreach ($products as $product) {
                         wp_delete_post($product, true);
                         // Product Category
                         if (taxonomy_exists('product_cat')) {
                             wp_set_object_terms($product, null, 'product_cat');
                         }
                         // Product Tag
                         if (taxonomy_exists('product_tag')) {
                             wp_set_object_terms($product, null, 'product_tag');
                         }
                         // Product Brand
                         if (taxonomy_exists('product_brand')) {
                             wp_set_object_terms($product, null, 'product_brand');
                         }
                         // Product Vendor
                         if (taxonomy_exists('shop_vendor')) {
                             wp_set_object_terms($product, null, 'shop_vendor');
                         }
                         // Attributes
                         $attributes_sql = "SELECT `attribute_id` as ID, `attribute_name` as name, `attribute_label` as label, `attribute_type` as type FROM `" . $wpdb->prefix . "woocommerce_attribute_taxonomies`";
                         $attributes = $wpdb->get_results($attributes_sql);
                         if (!empty($attributes)) {
                             foreach ($attributes as $attribute) {
                                 if (taxonomy_exists('pa_' . $attribute->name)) {
                                     wp_set_object_terms($product, null, 'pa_' . $attribute->name);
                                 }
                             }
                         }
                     }
                     unset($products, $product, $attributes, $attribute);
                 }
             }
             break;
         case 'product_category':
             $term_taxonomy = 'product_cat';
             if (!empty($data)) {
                 foreach ($data as $single_category) {
                     $post_type = 'product';
                     $args = array('post_type' => $post_type, 'fields' => 'ids', 'tax_query' => array(array('taxonomy' => $term_taxonomy, 'field' => 'id', 'terms' => $single_category)), 'numberposts' => -1);
                     $products = get_posts($args);
                     if ($products) {
                         foreach ($products as $product) {
                             wp_delete_post($product, true);
                         }
                         unset($products, $product);
                     }
                 }
                 unset($data, $single_category);
             } else {
                 $args = array('hide_empty' => false, 'number' => 100);
                 // Loop through every 100 records until 0 is returned, might take awhile
                 while (woo_st_return_count('product_category')) {
                     $categories = get_terms($term_taxonomy, $args);
                     if (!empty($categories)) {
                         foreach ($categories as $category) {
                             wp_delete_term($category->term_id, $term_taxonomy);
                             $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->terms . "` WHERE `term_id` = %d", $category->term_id));
                             $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->term_relationships . "` WHERE `term_taxonomy_id` = %d", $category->term_taxonomy_id));
                             $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->prefix . "woocommerce_termmeta` WHERE `woocommerce_term_id` = %d", $category->term_id));
                             if (function_exists('delete_woocommerce_term_meta')) {
                                 delete_woocommerce_term_meta($category->term_id, 'thumbnail_id');
                             }
                         }
                         unset($categories, $category);
                     }
                 }
                 $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->term_taxonomy . "` WHERE `taxonomy` = '%s'", $term_taxonomy));
             }
             break;
         case 'product_tag':
             $term_taxonomy = 'product_tag';
             $args = array('fields' => 'ids', 'hide_empty' => false, 'number' => 100);
             // Loop through every 100 records until 0 is returned, might take awhile
             while (woo_st_return_count('product_tag')) {
                 $tags = get_terms($term_taxonomy, $args);
                 if (!empty($tags)) {
                     foreach ($tags as $tag) {
                         wp_delete_term($tag, $term_taxonomy);
                         $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->terms . "` WHERE `term_id` = %d", $tag));
                     }
                 }
             }
             break;
         case 'product_brand':
             $term_taxonomy = 'product_brand';
             $args = array('fields' => 'ids', 'hide_empty' => false, 'number' => 100);
             // Loop through every 100 records until 0 is returned, might take awhile
             while (woo_st_return_count('product_brand')) {
                 $tags = get_terms($term_taxonomy, $args);
                 if ($tags) {
                     foreach ($tags as $tag) {
                         wp_delete_term($tag, $term_taxonomy);
                         $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->terms . "` WHERE `term_id` = %d", $tag));
                     }
                 }
             }
             break;
         case 'product_vendor':
             $term_taxonomy = 'shop_vendor';
             $args = array('fields' => 'ids', 'hide_empty' => false);
             // Loop through every 100 records until 0 is returned, might take awhile
             while (woo_st_return_count('product_vendor')) {
                 $tags = get_terms($term_taxonomy, $args);
                 if ($tags) {
                     foreach ($tags as $tag) {
                         wp_delete_term($tag, $term_taxonomy);
                         $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->terms . "` WHERE `term_id` = %d", $tag));
                     }
                 }
             }
             break;
         case 'product_image':
             $post_type = array('product', 'product_variation');
             $args = array('post_type' => $post_type, 'fields' => 'ids', 'post_status' => 'any', 'numberposts' => 100);
             // Loop through every 100 records until 0 is returned, might take awhile
             while (woo_st_return_count('product_image')) {
                 $products = get_posts($args);
                 // Check each Product for images
                 if (!empty($products)) {
                     $upload_dir = wp_upload_dir();
                     foreach ($products as $product) {
                         $args = array('post_type' => 'attachment', 'post_parent' => $product, 'post_status' => 'inherit', 'post_mime_type' => 'image', 'numberposts' => -1);
                         $images = get_children($args);
                         if (!empty($images)) {
                             foreach ($images as $image) {
                                 wp_delete_attachment($image->ID, true);
                             }
                             unset($images, $image);
                         }
                     }
                 } else {
                     // Check for WooCommerce-related images
                     $images_sql = "SELECT `post_id` AS `ID` FROM `" . $wpdb->postmeta . "` WHERE `meta_key` = '_woocommerce_exclude_image' AND `meta_value` = 0";
                     $images = $wpdb->get_col($images_sql);
                     if (!empty($images)) {
                         foreach ($images as $image) {
                             wp_delete_attachment($image, true);
                         }
                         unset($images, $image);
                     }
                 }
             }
             break;
         case 'order':
             $post_type = 'shop_order';
             $term_taxonomy = 'shop_order_status';
             $woocommerce_version = woo_get_woo_version();
             if (!empty($data)) {
                 foreach ($data as $single_order) {
                     $args = array('post_type' => $post_type, 'fields' => 'ids', 'numberposts' => -1);
                     // Check if this is a pre-WooCommerce 2.2 instance
                     if (version_compare($woocommerce_version, '2.2', '<')) {
                         $args['tax_query'] = array(array('taxonomy' => $term_taxonomy, 'field' => 'id', 'terms' => $single_order));
                     } else {
                         $args['status'] = 'any';
                     }
                     $orders = get_posts($args);
                     if (!empty($orders)) {
                         foreach ($orders as $order) {
                             wp_delete_post($order, true);
                             $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->term_relationships . "` WHERE `order_id` = %d", $order));
                         }
                         unset($orders, $order);
                     }
                 }
                 unset($data, $single_order);
             } else {
                 $args = array('post_type' => $post_type, 'fields' => 'ids', 'post_status' => 'any', 'numberposts' => 100);
                 // Loop through every 100 records until 0 is returned, might take awhile
                 while (woo_st_return_count('order')) {
                     $orders = get_posts($args);
                     if (!empty($orders)) {
                         foreach ($orders as $order) {
                             wp_delete_post($order, true);
                             $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->term_relationships . "` WHERE `order_id` = %d", $order));
                         }
                         unset($orders, $order);
                     }
                 }
                 $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "woocommerce_order_items`");
                 $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "woocommerce_order_itemmeta`");
             }
             break;
         case 'tax_rate':
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "woocommerce_tax_rates`");
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "woocommerce_tax_rate_locations`");
             break;
         case 'download_permission':
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "woocommerce_downloadable_product_permissions`");
             break;
         case 'coupon':
             $post_type = 'shop_coupon';
             $args = array('post_type' => $post_type, 'fields' => 'ids', 'post_status' => woo_st_post_statuses(), 'numberposts' => 100);
             // Loop through every 100 records until 0 is returned, might take awhile
             while (woo_st_return_count('coupon')) {
                 $coupons = get_posts($args);
                 if (!empty($coupons)) {
                     foreach ($coupons as $coupon) {
                         wp_delete_post($coupon, true);
                     }
                     unset($coupons, $coupon);
                 }
             }
             break;
         case 'attribute':
             if (isset($_POST['woo_st_attributes'])) {
                 $attributes_sql = "SELECT `attribute_id` as ID, `attribute_name` as name, `attribute_label` as label, `attribute_type` as type FROM `" . $wpdb->prefix . "woocommerce_attribute_taxonomies`";
                 $attributes = $wpdb->get_results($attributes_sql);
                 if ($attributes) {
                     foreach ($attributes as $attribute) {
                         $terms_sql = $wpdb->prepare("SELECT `term_id` FROM `" . $wpdb->prefix . "term_taxonomy` WHERE `taxonomy` = %s", 'pa_' . $attribute->name);
                         $terms = $wpdb->get_results($terms_sql);
                         if ($terms) {
                             foreach ($terms as $term) {
                                 wp_delete_term($term->term_id, 'pa_' . $attribute->name);
                             }
                         }
                         $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->prefix . "woocommerce_termmeta` WHERE `meta_key` = 'order_pa_%s'", $attribute->name));
                         $wpdb->query($wpdb->prepare("DELETE FROM `" . $wpdb->term_relationships . "` WHERE `term_taxonomy_id` = %d", $attribute->ID));
                     }
                 }
                 $wpdb->query("DELETE FROM `" . $wpdb->prefix . "woocommerce_attribute_taxonomies`");
             }
             break;
             // 3rd Party
         // 3rd Party
         case 'credit_card':
             $post_type = 'offline_payment';
             $args = array('post_type' => $post_type, 'fields' => 'ids', 'post_status' => woo_st_post_statuses(), 'numberposts' => 100);
             // Loop through every 100 records until 0 is returned, might take awhile
             while (woo_st_return_count('credit_card')) {
                 $credit_cards = get_posts($args);
                 if (!empty($credit_cards)) {
                     foreach ($credit_cards as $credit_card) {
                         wp_delete_post($credit_card, true);
                     }
                     unset($credit_cards, $credit_card);
                 }
             }
             break;
             // WordPress
         // WordPress
         case 'post':
             $post_type = 'post';
             $args = array('post_type' => $post_type, 'fields' => 'ids', 'post_status' => woo_st_post_statuses(), 'numberposts' => 100);
             // Loop through every 100 records until 0 is returned, might take awhile
             while (woo_st_return_count('post')) {
                 $posts = get_posts($args);
                 if ($posts) {
                     foreach ($posts as $post) {
                         wp_delete_post($post, true);
                     }
                     unset($posts, $post);
                 }
             }
             break;
         case 'post_category':
             $term_taxonomy = 'category';
             $args = array('hide_empty' => false, 'number' => 100);
             // Loop through every 100 records until 0 is returned, might take awhile
             while (woo_st_return_count('post_category')) {
                 $post_categories = get_terms($term_taxonomy, $args);
                 if ($post_categories) {
                     foreach ($post_categories as $post_category) {
                         wp_delete_term($post_category->term_id, $term_taxonomy);
                         $wpdb->query("DELETE FROM `" . $wpdb->terms . "` WHERE `term_id` = " . $post_category->term_id);
                         $wpdb->query("DELETE FROM `" . $wpdb->term_relationships . "` WHERE `term_taxonomy_id` = " . $post_category->term_taxonomy_id);
                     }
                 }
             }
             $wpdb->query("DELETE FROM `" . $wpdb->term_taxonomy . "` WHERE `taxonomy` = '" . $term_taxonomy . "'");
             break;
         case 'post_tag':
             $term_taxonomy = 'post_tag';
             $args = array('hide_empty' => false, 'number' => 100);
             // Loop through every 100 records until 0 is returned, might take awhile
             while (woo_st_return_count('post_tag')) {
                 $post_tags = get_terms($term_taxonomy, $args);
                 if ($post_tags) {
                     foreach ($post_tags as $post_tag) {
                         wp_delete_term($post_tag->term_id, $term_taxonomy);
                         $wpdb->query("DELETE FROM `" . $wpdb->terms . "` WHERE `term_id` = " . $post_tag->term_id);
                         $wpdb->query("DELETE FROM `" . $wpdb->term_relationships . "` WHERE `term_taxonomy_id` = " . $post_tag->term_taxonomy_id);
                     }
                 }
             }
             $wpdb->query("DELETE FROM `" . $wpdb->term_taxonomy . "` WHERE `taxonomy` = '" . $term_taxonomy . "'");
             break;
         case 'link':
             $wpdb->query("TRUNCATE TABLE `" . $wpdb->prefix . "links`");
             break;
         case 'comment':
             $args = array('number' => 100);
             // Loop through every 100 records until 0 is returned, might take awhile
             while (woo_st_return_count('comment')) {
                 $comments = get_comments($args);
                 if (!empty($comments)) {
                     foreach ($comments as $comment) {
                         wp_delete_comment($comment->comment_ID, true);
                     }
                     unset($comments, $comment);
                 }
             }
             break;
         case 'media_image':
             $post_type = 'attachment';
             $post_mime_types = array('image/jpg', 'image/jpeg', 'image/jpe', 'image/gif', 'image/png');
             $args = array('post_type' => $post_type, 'fields' => 'ids', 'post_mime_type' => $post_mime_types, 'post_status' => woo_st_post_statuses(), 'numberposts' => 100);
             // Loop through every 100 records until 0 is returned, might take awhile
             while (woo_st_return_count('media_image')) {
                 $images = get_posts($args);
                 if (!empty($images)) {
                     foreach ($images as $image) {
                         wp_delete_attachment($image, true);
                     }
                     unset($images, $image);
                 }
             }
             break;
     }
     // Mission accomplished
     woo_st_update_option('in_progress', '');
 }
Ejemplo n.º 2
0
	function woo_ce_return_count( $export_type = '', $args = array() ) {

		global $wpdb;

		$count_sql = null;
		$woocommerce_version = woo_get_woo_version();

		switch( $export_type ) {

			case 'product':
				$post_type = array( 'product', 'product_variation' );
				$args = array(
					'post_type' => $post_type,
					'posts_per_page' => 1,
					'fields' => 'ids',
					'suppress_filters' => 1
				);
				$count_query = new WP_Query( $args );
				$count = $count_query->found_posts;
				break;

			case 'category':
				$term_taxonomy = 'product_cat';
				if( taxonomy_exists( $term_taxonomy ) )
					$count = wp_count_terms( $term_taxonomy );
				break;

			case 'tag':
				$term_taxonomy = 'product_tag';
				if( taxonomy_exists( $term_taxonomy ) )
					$count = wp_count_terms( $term_taxonomy );
				break;

			case 'brand':
				$term_taxonomy = apply_filters( 'woo_ce_brand_term_taxonomy', 'product_brand' );
				if( taxonomy_exists( $term_taxonomy ) )
					$count = wp_count_terms( $term_taxonomy );
				break;

			case 'order':
				$post_type = 'shop_order';
				// Check if this is a WooCommerce 2.2+ instance (new Post Status)
				if( version_compare( $woocommerce_version, '2.2' ) >= 0 )
					$post_status = ( function_exists( 'wc_get_order_statuses' ) ? apply_filters( 'woo_ce_order_post_status', array_keys( wc_get_order_statuses() ) ) : 'any' );
				else
					$post_status = apply_filters( 'woo_ce_order_post_status', woo_ce_post_statuses() );
				$args = array(
					'post_type' => $post_type,
					'posts_per_page' => 1,
					'post_status' => $post_status,
					'fields' => 'ids'
				);
				$count_query = new WP_Query( $args );
				$count = $count_query->found_posts;
				break;

			case 'customer':
				if( $users = woo_ce_return_count( 'user' ) > 1000 ) {
					$count = sprintf( '~%s+', 1000 );
				} else {
					$post_type = 'shop_order';
					$args = array(
						'post_type' => $post_type,
						'posts_per_page' => -1,
						'fields' => 'ids'
					);
					// Check if this is a WooCommerce 2.2+ instance (new Post Status)
					if( version_compare( $woocommerce_version, '2.2' ) >= 0 ) {
						$args['post_status'] = apply_filters( 'woo_ce_customer_post_status', array( 'wc-pending', 'wc-on-hold', 'wc-processing', 'wc-completed' ) );
					} else {
						$args['post_status'] = apply_filters( 'woo_ce_customer_post_status', woo_ce_post_statuses() );
						$args['tax_query'] = array(
							array(
								'taxonomy' => 'shop_order_status',
								'field' => 'slug',
								'terms' => array( 'pending', 'on-hold', 'processing', 'completed' )
							),
						);
					}
					$order_ids = new WP_Query( $args );
					$count = $order_ids->found_posts;
					if( $count > 100 ) {
						$count = sprintf( '~%s', $count );
					} else {
						$customers = array();
						if( $order_ids->posts ) {
							foreach( $order_ids->posts as $order_id ) {
								$email = get_post_meta( $order_id, '_billing_email', true );
								if( !in_array( $email, $customers ) )
									$customers[$order_id] = $email;
								unset( $email );
							}
							$count = count( $customers );
						}
					}
				}
/*
				if( false ) {
					$orders = get_posts( $args );
					if( $orders ) {
						$customers = array();
						foreach( $orders as $order ) {
							$order->email = get_post_meta( $order->ID, '_billing_email', true );
							if( empty( $order->email ) ) {
								if( $order->user_id = get_post_meta( $order->ID, '_customer_user', true ) ) {
									$user = get_userdata( $order->user_id );
									if( $user )
										$order->email = $user->user_email;
									unset( $user );
								} else {
									$order->email = '-';
								}
							}
							if( !in_array( $order->email, $customers ) ) {
								$customers[$order->ID] = $order->email;
								$count++;
							}
						}
						unset( $orders, $order );
					}
				}
*/
				break;

			case 'user':
				if( $users = count_users() )
					$count = $users['total_users'];
				break;

			case 'coupon':
				$post_type = 'shop_coupon';
				if( post_type_exists( $post_type ) )
					$count = wp_count_posts( $post_type );
				break;

			case 'subscription':
				$count = 0;
				// Check that WooCommerce Subscriptions exists
				if( class_exists( 'WC_Subscriptions' ) ) {
					if( method_exists( 'WC_Subscriptions', 'is_large_site' ) ) {
						// Does this store have roughly more than 3000 Subscriptions
						if( false === WC_Subscriptions::is_large_site() ) {
							if( class_exists( 'WC_Subscriptions_Manager' ) ) {
								// Check that the get_all_users_subscriptions() function exists
								if( method_exists( 'WC_Subscriptions_Manager', 'get_all_users_subscriptions' ) ) {
									if( $subscriptions = WC_Subscriptions_Manager::get_all_users_subscriptions() ) {
										foreach( $subscriptions as $key => $user_subscription ) {
											if( !empty( $user_subscription ) ) {
												foreach( $user_subscription as $subscription )
													$count++;
											}
										}
										unset( $subscriptions, $subscription, $user_subscription );
									}
								}
							}
						} else {
							if( method_exists( 'WC_Subscriptions', 'get_total_subscription_count' ) )
								$count = WC_Subscriptions::get_total_subscription_count();
							else
								$count = "~2500";
						}
					}
				}
				break;

			case 'product_vendor':
				$term_taxonomy = 'shop_vendor';
				if( taxonomy_exists( $term_taxonomy ) )
					$count = wp_count_terms( $term_taxonomy );
				break;

			case 'commission':
				$post_type = 'shop_commission';
				if( post_type_exists( $post_type ) )
					$count = wp_count_posts( $post_type );
				break;

			case 'shipping_class':
				$term_taxonomy = 'product_shipping_class';
				if( taxonomy_exists( $term_taxonomy ) )
					$count = wp_count_terms( $term_taxonomy );
				break;

			case 'attribute':
				$attributes = ( function_exists( 'wc_get_attribute_taxonomies' ) ? wc_get_attribute_taxonomies() : array() );
				$count = count( $attributes );
				break;

		}
		if( isset( $count ) || $count_sql ) {
			if( isset( $count ) ) {
				if( is_object( $count ) ) {
					$count = (array)$count;
					$count = (int)array_sum( $count );
				}
				return $count;
			} else {
				if( $count_sql )
					$count = $wpdb->get_var( $count_sql );
				else
					$count = 0;
			}
			return $count;
		} else {
			return 0;
		}

	}
Ejemplo n.º 3
0
function woo_ce_get_order_statuses()
{
    $terms = false;
    // Check if this is a WooCommerce 2.2+ instance (new Post Status)
    $woocommerce_version = woo_get_woo_version();
    if (version_compare($woocommerce_version, '2.2') >= 0) {
        // Convert Order Status array into our magic sauce
        $order_statuses = function_exists('wc_get_order_statuses') ? wc_get_order_statuses() : false;
        if (!empty($order_statuses)) {
            $terms = array();
            $post_type = 'shop_order';
            $posts_count = wp_count_posts($post_type);
            foreach ($order_statuses as $key => $order_status) {
                $terms[] = (object) array('name' => $order_status, 'slug' => $key, 'count' => isset($posts_count->{$key}) ? $posts_count->{$key} : 0);
            }
        }
    } else {
        $args = array('hide_empty' => false);
        $terms = get_terms('shop_order_status', $args);
        if (empty($terms) || is_wp_error($terms) == true) {
            $terms = false;
        }
    }
    return $terms;
}
Ejemplo n.º 4
0
function woo_st_tab_template($tab = '')
{
    if (!$tab) {
        $tab = 'overview';
    }
    switch ($tab) {
        case 'nuke':
            // Check if a previous nuke failed mid-drop
            $in_progress = woo_st_get_option('in_progress', '');
            if (!empty($in_progress)) {
                $message = sprintf(__('It looks like a previous nuke failed to clear that dataset, this is common in large catalogues and is likely due to WordPress hitting a memory limit or server timeout. Don\'t stress, <a href="%s">retry %s nuke?</a>', 'woo_st'), add_query_arg(array('action' => 'nuke', 'dataset' => $in_progress)), ucfirst($in_progress));
                woo_st_admin_notice_html($message, 'error');
                woo_st_update_option('in_progress', '');
            }
            $products = woo_st_return_count('product');
            $images = woo_st_return_count('product_image');
            $tags = woo_st_return_count('product_tag');
            $categories = woo_st_return_count('product_category');
            if ($categories) {
                $term_taxonomy = 'product_cat';
                $args = array('hide_empty' => 0);
                $categories_data = get_terms($term_taxonomy, $args);
            }
            $orders = woo_st_return_count('order');
            if ($orders) {
                // Check if this is a WooCommerce 2.2+ instance
                $woocommerce_version = woo_get_woo_version();
                $orders_data = false;
                if (version_compare($woocommerce_version, '2.2', '<')) {
                    $term_taxonomy = 'shop_order_status';
                    $args = array('hide_empty' => 0);
                    $orders_data = get_terms($term_taxonomy, $args);
                }
            }
            $tax_rates = woo_st_return_count('tax_rate');
            $download_permissions = woo_st_return_count('download_permission');
            $coupons = woo_st_return_count('coupon');
            $attributes = woo_st_return_count('attribute');
            $brands = woo_st_return_count('product_brand');
            $vendors = woo_st_return_count('product_vendor');
            $credit_cards = woo_st_return_count('credit_card');
            $posts = woo_st_return_count('post');
            $post_categories = woo_st_return_count('post_category');
            $post_tags = woo_st_return_count('post_tag');
            $links = woo_st_return_count('link');
            $comments = woo_st_return_count('comment');
            $media_images = woo_st_return_count('media_image');
            $show_table = false;
            if ($products || $images || $tags || $categories || $orders || $credit_cards || $attributes) {
                $show_table = true;
            }
            break;
    }
    if ($tab) {
        if (file_exists(WOO_ST_PATH . 'templates/admin/tabs-' . $tab . '.php')) {
            include_once WOO_ST_PATH . 'templates/admin/tabs-' . $tab . '.php';
        } else {
            $message = sprintf(__('We couldn\'t load the export template file <code>%s</code> within <code>%s</code>, this file should be present.', 'woo_st'), 'tabs-' . $tab . '.php', WOO_CD_PATH . 'templates/admin/...');
            woo_st_admin_notice_html($message, 'error');
            ob_start();
            ?>
<p><?php 
            _e('You can see this error for one of a few common reasons', 'woo_st');
            ?>
:</p>
<ul class="ul-disc">
	<li><?php 
            _e('WordPress was unable to create this file when the Plugin was installed or updated', 'woo_st');
            ?>
</li>
	<li><?php 
            _e('The Plugin files have been recently changed and there has been a file conflict', 'woo_st');
            ?>
</li>
	<li><?php 
            _e('The Plugin file has been locked and cannot be opened by WordPress', 'woo_st');
            ?>
</li>
</ul>
<p><?php 
            _e('Jump onto our website and download a fresh copy of this Plugin as it might be enough to fix this issue. If this persists get in touch with us.', 'woo_st');
            ?>
</p>
<?php 
            ob_end_flush();
        }
    }
}
Ejemplo n.º 5
0
function woo_ce_get_order_status( $order_id = 0 ) {

	global $export;

	$output = '';
	// Check if this is a WooCommerce 2.2+ instance (new Post Status)
	$woocommerce_version = woo_get_woo_version();
	if( version_compare( $woocommerce_version, '2.2' ) >= 0 ) {
		$output = get_post_status( $order_id );
		$terms = ( function_exists( 'wc_get_order_statuses' ) ? wc_get_order_statuses() : array() );
		if( isset( $terms[$output] ) )
			$output = $terms[$output];
	} else {
		$term_taxonomy = 'shop_order_status';
		$status = wp_get_object_terms( $order_id, $term_taxonomy );
		if( !empty( $status ) && is_wp_error( $status ) == false ) {
			$size = count( $status );
			for( $i = 0; $i < $size; $i++ ) {
				if( $term = get_term( $status[$i]->term_id, $term_taxonomy ) ) {
					$output .= $term->name . $export->category_separator;
					unset( $term );
				}
			}
			$output = substr( $output, 0, -1 );
		}
	}
	return $output;

}
Ejemplo n.º 6
0
function woo_ce_get_subscription_fields( $format = 'full' ) {

	$export_type = 'subscription';

	$fields = array();
	$fields[] = array(
		'name' => 'key',
		'label' => __( 'Subscription Key', 'woo_ce' )
	);
	$fields[] = array(
		'name' => 'status',
		'label' => __( 'Subscription Status', 'woo_ce' )
	);
	$fields[] = array(
		'name' => 'name',
		'label' => __( 'Subscription Name', 'woo_ce' )
	);
	$fields[] = array(
		'name' => 'user',
		'label' => __( 'User', 'woo_ce' )
	);
	$fields[] = array(
		'name' => 'user_id',
		'label' => __( 'User ID', 'woo_ce' )
	);
	$fields[] = array(
		'name' => 'email',
		'label' => __( 'E-mail Address', 'woo_ce' )
	);
	$fields[] = array(
		'name' => 'order_id',
		'label' => __( 'Order ID', 'woo_ce' )
	);
	$fields[] = array(
		'name' => 'order_status',
		'label' => __( 'Order Status', 'woo_ce' )
	);
	// Check if this is a pre-WooCommerce 2.2 instance
	$woocommerce_version = woo_get_woo_version();
	if( version_compare( $woocommerce_version, '2.2', '<' ) ) {
		$fields[] = array(
			'name' => 'post_status',
			'label' => __( 'Post Status', 'woo_ce' )
		);
	}
	$fields[] = array(
		'name' => 'start_date',
		'label' => __( 'Start Date', 'woo_ce' )
	);
	$fields[] = array(
		'name' => 'expiration',
		'label' => __( 'Expiration', 'woo_ce' )
	);
	$fields[] = array(
		'name' => 'end_date',
		'label' => __( 'End Date', 'woo_ce' )
	);
	$fields[] = array(
		'name' => 'trial_end_date',
		'label' => __( 'Trial End Date', 'woo_ce' )
	);
	$fields[] = array(
		'name' => 'last_payment',
		'label' => __( 'Last Payment', 'woo_ce' )
	);
	$fields[] = array(
		'name' => 'next_payment',
		'label' => __( 'Next Payment', 'woo_ce' )
	);
	$fields[] = array(
		'name' => 'renewals',
		'label' => __( 'Renewals', 'woo_ce' )
	);
	$fields[] = array(
		'name' => 'product_id',
		'label' => __( 'Product ID', 'woo_ce' )
	);
	$fields[] = array(
		'name' => 'product_sku',
		'label' => __( 'Product SKU', 'woo_ce' )
	);
	$fields[] = array(
		'name' => 'variation_id',
		'label' => __( 'Variation ID', 'woo_ce' )
	);
	$fields[] = array(
		'name' => 'coupon',
		'label' => __( 'Coupon Code', 'woo_ce' )
	);
/*
	$fields[] = array(
		'name' => '',
		'label' => __( '', 'woo_ce' )
	);
*/

	// Drop in our content filters here
	add_filter( 'sanitize_key', 'woo_ce_sanitize_key' );

	// Allow Plugin/Theme authors to add support for additional columns
	$fields = apply_filters( 'woo_ce_' . $export_type . '_fields', $fields, $export_type );

	// Remove our content filters here to play nice with other Plugins
	remove_filter( 'sanitize_key', 'woo_ce_sanitize_key' );

	if( $remember = woo_ce_get_option( $export_type . '_fields', array() ) ) {
		$remember = maybe_unserialize( $remember );
		$size = count( $fields );
		for( $i = 0; $i < $size; $i++ ) {
			$fields[$i]['disabled'] = ( isset( $fields[$i]['disabled'] ) ? $fields[$i]['disabled'] : 0 );
			$fields[$i]['default'] = 1;
			if( !array_key_exists( $fields[$i]['name'], $remember ) )
				$fields[$i]['default'] = 0;
		}
	}

	switch( $format ) {

		case 'summary':
			$output = array();
			$size = count( $fields );
			for( $i = 0; $i < $size; $i++ ) {
				if( isset( $fields[$i] ) )
					$output[$fields[$i]['name']] = 'on';
			}
			return $output;
			break;

		case 'full':
		default:
			$sorting = woo_ce_get_option( $export_type . '_sorting', array() );
			$size = count( $fields );
			for( $i = 0; $i < $size; $i++ ) {
				$fields[$i]['reset'] = $i;
				$fields[$i]['order'] = ( isset( $sorting[$fields[$i]['name']] ) ? $sorting[$fields[$i]['name']] : $i );
			}
			// Check if we are using PHP 5.3 and above
			if( version_compare( phpversion(), '5.3' ) >= 0 )
				usort( $fields, woo_ce_sort_fields( 'order' ) );
			return $fields;
			break;

	}

}