How about working with a team that puts the worries of the virtual environment aside and makes this burden more attractive to you with its wide range of services?
Contact Now: +90 850 305 25 95
E-mail:info@margarit.com.tr
Address: İvoksan, Neva Home Offices
1455 Street, 22/41 Yenimahalle / Ankara

Must-have shortcuts when using WordPress and Woocommerce

margarit-web-reklam-bilisim-2020

Working with Woocommerce seems easy, but the process of choosing between tiring and many alternatives becomes so boring and overwhelming while tiring you.

Then you will see that working with SQL can be much clearer and less detailed. However, for this, you need to know which database, which table, which row and metakey to search.

We convey vital information for Woocommerce and WordPress users with a few short but essential features. The "wp_" prefix, which is specified in the article, especially when providing operations on the database, is specified as a standard supplement, completely independent of your settings. You should use the codes by updating them with the prefix in your own installation settings.

Where can we find Woocommerce products in the database?

The products are basically positioned in two tables.

wp_posts table with a post_type like product or product_variation, wp_postmeta table with the corresponding post_id by product (the product ID).

Product categories, sub-categories, tags and features are included in the sub-tables.

wp_terms wp_termmeta wp_term_taxonomy wp_term_relationships wp_woocommerce_termmeta

Exporting all Woocommerce products with SQL

As a Woocommerce user, if you have thousands of product ranges, unfortunately, you install many plugins for your cashier system and try to find a solution with Cache systems.

However, since Woocommerce is a system that appeals to the whole world, it is a system that compulsorily runs many unnecessary functions simultaneously. To alleviate this load, you can lighten the distribution of functions that you deem unnecessary, so that the features you do not use are not called by the system and save you speed / time.

Just add the code I have given below to your theme's functions.php file, then you can delete the lines you want or add others. In this way, we are sure that you will gain visible speed!

add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 ); function child_manage_woocommerce_styles() { //remove generator meta tag remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) ); //first check that woo exists to prevent fatal errors if ( function_exists( 'is_woocommerce' ) ) { //dequeue scripts and styles if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) { wp_dequeue_style( ' woocommerce_frontend_styles' ); wp_dequeue_style( 'woocommerce_fancybox_styles' ); wp_dequeue_style( 'woocommerce_chosen_styles' ); wp_dequeue_style( 'woocommerce_prettyPhoto_css' ); wp_dequeue_script( 'wc_price_slider' ); wp_dequeue_script( 'wc-single-product' ); wp_dequeue_script( 'wc-add-to-cart' ); wp_dequeue_script( 'wc-cart-fragments' ); wp_dequeue_script( 'wc-checkout' ); wp_dequeue_script( 'wc-add-to-cart-variation' ); wp_dequeue_script( 'wc-single-product' ); wp_dequeue_script( 'wc-cart' ); wp_dequeue_script( 'wc-chosen' ); wp_dequeue_script( 'woocommerce' ); wp_dequeue_script( 'prettyPhoto' ); wp_dequeue_script( 'prettyPhoto-init' ); wp_dequeue_script( 'jquery-blockui' ); wp_dequeue_script( 'jquery-placeholder' ); wp_dequeue_script( 'fancybox' ); wp_dequeue_script( 'jqueryui' ); } } }

Change status of all products in Woocommerce with SQL

You have thousands of products and you have a resource problem because you are using WordPress, you want to change product statuses, names and similar features in packages of 50-60, right?

Then first we select the products with SQL.

SELECT wp_posts WHERE post_type='product'

Then we see if we will edit the correct tables, minimize our margin of error, and then use the update command.

UPDATE wp_posts SET post_status='publish' WHERE post_type='product'

With this command, you change the status of all products to Published, regardless of their status.
To save as a draft:

UPDATE wp_posts SET post_status='draft' WHERE post_type='product'

To save as pending review:

UPDATE wp_posts SET post_status='pending' WHERE post_type='product'

How do we organize Woocommerce product tabs?

If you are using Woocommerce, you will definitely need operations such as description, details, adding new tabs or changing tab layout.

Now I am adding these codes to the article for archiving purposes, so that both I and you can have a chance to review.

If you want to delete Woocommerce Tabs:


function woo_remove_product_tabs( $tabs ) { unset( $tabs['description'] ); // Remove the description tab unset( $tabs['reviews'] ); // Remove the reviews tab unset( $tabs['additional_information'] ); // Remove the additional information tab return $tabs; }

If you want to change the names of Woocommerce Tabs:

add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 ); function woo_rename_tabs( $tabs ) { $tabs['description']['title'] = __( 'More Information' ); // Rename the description tab $tabs['reviews']['title'] = __( 'Ratings' ); // Rename the reviews tab $tabs['additional_information']['title'] = __( 'Product Data' ); // Rename the additional information tab return $tabs; }

If you want to edit Woocommerce Tabs with a function:

add_filter( &#039;woocommerce_product_tabs&#039;, &#039;woo_custom_description_tab&#039;, 98 ); function woo_custom_description_tab( $tabs ) { $tabs[&#039;description&#039;][&#039;callback&#039;] = &#039;woo_custom_description_tab_content&#039;; // Custom description callback return $tabs; } function woo_custom_description_tab_content() { echo &#039;<h2>Custom Description</h2>&#039;; echo &#039;<p>Here&#039;sa custom description</p>&#39;;
}

If you want to change the order of Woocommerce Tabs:

add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 ); function woo_reorder_tabs( $tabs ) { $tabs['reviews']['priority'] = 5; // Reviews first $tabs['description']['priority'] = 10; // Description second $tabs['additional_information']['priority'] = 15; // Additional information third return $tabs; }

Woocommerce If you want to create a new tab:

add_filter( &#039;woocommerce_product_tabs&#039;, &#039;woo_new_product_tab&#039; ); function woo_new_product_tab( $tabs ) { // Adds the new tab $tabs[&#039;test_tab&#039;] = array( &#039;title&#039; =&gt; __( &#039;New Product Tab&#039;TP&#039;test_tab&#039;) 50&#039; , &#039;callback&#039; =&gt; &#039;woo_new_product_tab_content&#039; ); return $tabs; } function woo_new_product_tab_content() { // The new tab content echo &#039;<h2>New Product Tab</h2>&#039;; echo &#039;<p>Here&#039;s your new product tab.</p>&#39;;
    
}

Batch change the price of all products in Woocommerce with SQL

You have thousands of products, you don't want to deal with page by page.

You can change all product sales prices with a single SQL code.

UPDATE wp_postmeta m JOIN wp_posts p ON m.post_id=p.id AND m.meta_key = '_price' AND p.post_type = 'product' SET m.meta_value = price

If we want to print tables with prices:

SELECT p.id, p.post_title, m.meta_key, m.meta_value FROM wp_posts p INNER JOIN wp_postmeta m ON p.id=m.post_id AND m.meta_key='_price'

WordPress clearing all comments in one go with SQL

You saw that there are more than 5,000 comments, we said we can solve it with SQL.

It does not end with dealing with page by page, it can force both the system you use and the database density.

You can delete it in one go via phpmyadmin with SQL.

TRUNCATE `wp_commentmeta`; TRUNCATE `wp_comments`;

How can you delete all Woocommerce products in one move?

If you're using Woocommerce, you need more than a WordPress dashboard; It can get annoying especially when there are 8-10k products.

In the future, we can update the codes by adding code updates in order to delete systems such as category and brand.

To delete all products:

DELETE relations.*, taxes.*, terms.* FROM wp_term_relationships AS relations INNER JOIN wp_term_taxonomy AS taxes ON relations.term_taxonomy_id=taxes.term_taxonomy_id INNER JOIN wp_terms AS terms ON taxes.term_id=terms.term_id WHSELERE object_posts ID WHSELERE object_id WHERE post_type='product'); DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product'); DELETE FROM wp_posts WHERE post_type = 'product';

To delete all categories and tags:

DELETE a,c FROM wp_terms AS a LEFT JOIN wp_term_taxonomy AS c ON a.term_id = c.term_id LEFT JOIN wp_term_relationships AS b ON b.term_taxonomy_id = c.term_taxonomy_id WHERE c.taxonomy = &1_TP4T4product; DELETE a,c FROM wp_terms AS a LEFT JOIN wp_term_taxonomy AS c ON a.term_id = c.term_id LEFT JOIN wp_term_relationships AS b ON b.term_taxonomy_id = c.term_taxonomy_id WHERE c.taxonomy = &1_TP4T39;

To delete all orders:

DELETE FROM wp_woocommerce_order_itemmeta DELETE FROM wp_woocommerce_order_items DELETE FROM wp_posts WHERE post_type = 'shop_order'

To send orders to the trash:

update wp_posts set post_status = 'trash' where post_type = 'shop_order';

To delete pending orders:

DELETE FROM bo_posts WHERE post_type = 'shop_order' and post_status='wc-pending'

To delete pending orders:

DELETE FROM bo_posts WHERE post_type = 'shop_order' and post_status='wc-pending' DELETE FROM bo_woocommerce_order_itemmeta DELETE FROM bo_woocommerce_order_items
No Comments
Post a comment

en_USEnglish