Skip to content

Instantly share code, notes, and snippets.

@tuongpgjz
tuongpgjz / run.sql
Created October 12, 2022 02:55
Remove all empty categories in WooCommerce
View run.sql
-- Run this SQL commands from PhpMyAdmin or similar ways
-- change the wp_ to your tables prefix to make it works
-- Script from SalesGen.io
DELETE FROM wp_term_taxonomy WHERE taxonomy = 'product_cat' AND count = 0;
DELETE t FROM wp_terms t LEFT JOIN wp_term_taxonomy tt ON tt.term_id = t.term_id WHERE tt.term_id IS NULL;
@tuongpgjz
tuongpgjz / run.sql
Created October 12, 2022 02:53
Correct product count on categories WooCommerce - SQL
View run.sql
-- Run this SQL commands from PhpMyAdmin or similar ways
-- change the wp_ to your tables prefix to make it works
-- Script from SalesGen.io
UPDATE wp_term_taxonomy tt SET count = (SELECT COUNT(object_id) FROM wp_term_relationships WHERE term_taxonomy_id = tt.term_taxonomy_id) WHERE taxonomy = 'product_cat';
@tuongpgjz
tuongpgjz / price.sql
Created July 18, 2022 14:39
Update product price base on category
View price.sql
-- SalesGen.io
-- Change 'category name' by your category name
-- Reduce current price 5
update `wp_postmeta` SET meta_value = meta_value - 5 WHERE meta_key IN ('_regular_price', '_price') AND meta_value <> '' AND post_id IN (SELECT object_id from wp_term_relationships WHERE term_taxonomy_id IN(SELECT term_taxonomy_id FROM `wp_term_taxonomy` WHERE taxonomy = 'product_cat' AND term_id IN (SELECT term_id FROM `wp_terms` WHERE name = 'category name')));
-- Increase current price 5
update `wp_postmeta` SET meta_value = meta_value + 5 WHERE meta_key IN ('_regular_price', '_price') AND meta_value <> '' AND post_id IN (SELECT object_id from wp_term_relationships WHERE term_taxonomy_id IN(SELECT term_taxonomy_id FROM `wp_term_taxonomy` WHERE taxonomy = 'product_cat' AND term_id IN (SELECT term_id FROM `wp_terms` WHERE name = 'category name')))
@tuongpgjz
tuongpgjz / gist:b2453c4cb1e6b61e80e580c823304ea4
Last active June 23, 2022 09:48
Remove WooCommerce products by category name or a part of category name
View gist:b2453c4cb1e6b61e80e580c823304ea4
-- replace category_name by your category name
DELETE FROM wp_posts WHERE ID IN (SELECT object_id from wp_term_relationships WHERE term_taxonomy_id IN(SELECT term_taxonomy_id FROM `wp_term_taxonomy` WHERE taxonomy = 'product_cat' AND term_id IN (SELECT term_id FROM `wp_terms` WHERE name like '%category_name%')))
@tuongpgjz
tuongpgjz / delete trash product.sql
Created June 22, 2022 07:47
Delete trash product by mysql
View delete trash product.sql
-- Delete product variants
DELETE FROM wp_posts WHERE post_type = 'product_variation' AND post_parent IN (DELETE FROM wp_posts WHERE post_type = 'product' AND post_status = 'trash');
-- Delete main product
DELETE FROM wp_posts WHERE post_type = 'product' AND post_status = 'trash';
-- clean metapost
DELETE pm
FROM wp_postmeta pm
@tuongpgjz
tuongpgjz / functions.php
Last active May 15, 2022 14:10
remove price range on product page woocommerce
View functions.php
<?php
// SalesGen.io
// WooCommerce plugins, woocommerce upsell, woocommerce buy more save more
/*** Follow Steps ***/
// 1 Put the code below into the functions.php of your theme
add_filter('woocommerce_get_price_html', 'salesgen_hide_variation_price', 99, 2);
function salesgen_hide_variation_price( $v_price, $v_product ) {
@tuongpgjz
tuongpgjz / paypal-duplicate-custom.css
Created April 1, 2022 15:14
Hide some duplicate paypal button on WooCommerce checkout page
View paypal-duplicate-custom.css
div[id^=zoid-paypal-buttons]:nth-child(3),
div[id^=zoid-paypal-buttons]:nth-child(1) {
display: none!important;
}
@tuongpgjz
tuongpgjz / functions.php
Last active March 24, 2023 04:40
Auto update Product Addons price to top position
View functions.php
/*
Anthony from SalesGen.io
Demo page https://demo.salesgen.io/product/ninja-design/
Copy this script into your functions.php file theme
*/
add_action('wp_footer', function(){
/* Code By SalesGen.io */
?>
@tuongpgjz
tuongpgjz / functions.php
Created January 1, 2022 13:38
Replace woocommerce product tab with new one
View functions.php
<?php
//SalesGen.io
//remove reviews and additional_information tab
add_filter( 'woocommerce_product_tabs', 'salesgen_remove_product_tabs', 98 );
function salesgen_remove_product_tabs( $tabs ) {
if(is_product()){
unset( $tabs['additional_information'] ); // Remove the additional information tab
unset( $tabs['reviews'] ); // Remove the additional information tab
@tuongpgjz
tuongpgjz / postmeta-optimize.sql
Created December 31, 2021 07:52
Optimize postmeta table for big data on WordPress
View postmeta-optimize.sql
ALTER TABLE wp_postmeta ADD key(post_id, meta_key(100), meta_value(191));
ALTER TABLE wp_postmeta ADD key(meta_key(100), meta_value(191));
-- change wp_postmeta to your table with prefix