Skip to content

Instantly share code, notes, and snippets.

tuongpgjz / auto-complete-order.php
Last active March 4, 2021 17:18
Auto complete WooCommerce order after paid
* skip the processing status for selling digital products on WooCommerce. Put this code into your theme functions.php or a plugin.
add_filter( 'woocommerce_payment_complete_order_status', 'salesnudge_skip_processing', 10, 1 );
function salesnudge_skip_processing( $stt = '' ){
return 'completed';
tuongpgjz / price.php
Last active September 12, 2021 13:16
// Display lowest price of variant on product archives WooCommerce
// Format "Starting at %s per unit" - Exp: Starting at $4.5 per unit
// Put this file to folder /woocommerce/loop/ of your theme
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
global $product;
tuongpgjz / functions.php
Last active November 13, 2021 16:16
Add popup sizechart from UX Block in flatsome theme -
// Snippet by
//display sizechart above add to cart button
// #1 put this code in to functions.php of your themes/child theme
// #2 create UX block with ID : sizechart.
// #3 Check your product page
//Notice: Change the width of popup on desktop by change the 800px with your expect value
tuongpgjz / variable.php
Last active November 13, 2021 16:16
Auto set default variants for WooCommerce products. Copy to woocommerce/single-product/add-to-cart/variable.php
Put this file to folder of your theme to overide default option
* Check "IMPORTANT HERE" part to set default variant with attribute. Else code will set first variant to default.
* By Anthony Pham from
tuongpgjz / remove-empty-terms.sql
Last active November 13, 2021 16:16
Remove empty product categories/tags on WooCommerce
-- 1) Go to WooCommerce > Status > Tools
-- 2) Find section "Term counts" and press Recount Terms
-- 3) Run this one with phpMyAdmin or tool similar
-- If you want to remove tags, change 'product_cat' to 'product_tag'
-- Anthony from
DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE count = 0 and taxonomy = 'product_cat')
tuongpgjz / update-woo-price.sql
Last active November 13, 2021 16:15
Update all price in store
-- Anthony from
-- Bạn cần phải biết số tiền hiện tại đang là bao nhiêu để điều chỉnh về giá mới.
-- Ví dụ muốn đổi hết sản phẩm đang có giá là 74 về 64 thì set _price và _regular_price về cùng giá mới 64
update `wp_postmeta` SET `meta_value` = 64 WHERE meta_key = '_price' AND meta_value = 74;
update `wp_postmeta` SET `meta_value` = 64 WHERE meta_key = '_regular_price' AND meta_value = 74;
-- Nếu có sale price, giá cũ sale là 74, giá cũ gốc _regular_price là 94 thì set như sau (giá mới là 84, giá sale mới là 64, nếu muốn bỏ giá sales thì cho giá sale = giá _regular_price):
update `wp_postmeta` SET `meta_value` = 64 WHERE meta_key = '_price' AND meta_value = 74;
update `wp_postmeta` SET `meta_value` = 84 WHERE meta_key = '_regular_price' AND meta_value = 94;
tuongpgjz / clean-store.sql
Created October 20, 2021 07:39
Clean orders on your store
-- This SQLs remove orders, orders notes, customers, coupons on your store
-- NOTICE: Replace wp_ by your prefix table
DELETE FROM wp_woocommerce_order_itemmeta;
DELETE FROM wp_woocommerce_order_items;
DELETE FROM wp_wc_order_stats;
tuongpgjz / clean-product.sql
Last active January 9, 2022 10:12
Remove all product data and product meta
-- This SQLs remove products and their meta data on your store
-- delete product info
DELETE FROM wp_posts WHERE post_type = 'product_variation';
DELETE FROM wp_posts WHERE post_type = 'product';
-- After remove products from posts table, must clear data in postmeta to reduce database size.
tuongpgjz / functions.php
Last active February 23, 2022 04:27
Force related product by tags instead of category on Woocommerce
<?php //Do not copy this line to your functions.php of theme
//copy from here then paste into functions.php of theme
add_filter( 'woocommerce_product_related_posts_relate_by_category', 'salesgen_product_related_posts_relate_by_category' );
function salesgen_product_related_posts_relate_by_category(){
return array();
tuongpgjz / postmeta-optimize.sql
Created December 31, 2021 07:52
Optimize postmeta table for big data on WordPress
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