Skip to content

Instantly share code, notes, and snippets.

@Lonsdale201
Lonsdale201 / code
Created July 29, 2024 10:56
Dynamic coupon for wc by exit intent custom popup (beta)
// place the code in the child theme functions.php or a custom code snippets plugin, like FluentSnippets
// Define the coupon discount rate
define('COUPON_DISCOUNT_RATE', 10); // 10% discount
// Enqueue custom script for exit intent detection
function enqueue_exit_intent_script() {
if (is_cart() || is_checkout()) {
?>
@yankiara
yankiara / oxygen-repeater-dynamic-query.php
Last active July 15, 2024 15:17
Use dynamic queries with Oxygen's repeater
/* I'll put here different examples of dynamic query for Oxygen repeater :
* - Use one of the following repeater_dynamic_query definitions
* in code block just BEFORE the repeater
* - Set the repeater custom query settings : post type, number of posts, order...
* - Add the remove_action in a code block AFTER the repeater
*/
/****************************************************************************************************
* Display related posts for any CPT with taxonomy:
@stevebauman
stevebauman / Throttle.php
Last active October 20, 2024 03:30
Laravel Throttle Validation Rule
<?php
namespace App\Rules;
use Illuminate\Http\Request;
use Illuminate\Cache\RateLimiter;
use Illuminate\Contracts\Validation\Rule;
class Throttle implements Rule
{
@UmeshSingla
UmeshSingla / skip_directory_smush.php
Created January 31, 2017 12:16
WP Smush - Skip a directory or a list of directories from Smushing
<?php
//Allows to skip multiple directories, as specified in array
add_filter( 'wp_smush_image', 'filter_by_directory', '', 2 );
function filter_by_directory( $smush, $id ) {
$file_path = get_attached_file( $id );
//List of directories to be ignored
$dirs = array(
'uploads/2016/11',
'uploads/2017/01'
);
@yanknudtskov
yanknudtskov / woocommerce-duplicate-skus.sql
Last active July 9, 2024 03:28
Select Duplicate SKUs from WooCommerce Database #woocommerce #mysql
# SELECT any post_status
SELECT meta_value,COUNT(meta_value),GROUP_CONCAT(DISTINCT post_id ORDER BY post_id SEPARATOR ',') post_id
FROM wp_postmeta
WHERE meta_key = '_sku'
AND meta_value != ''
GROUP BY meta_value HAVING COUNT(meta_value) > 1
# SELECT only from products that are already published or in draft
SELECT meta_value,COUNT(meta_value),GROUP_CONCAT(DISTINCT post_id ORDER BY post_id SEPARATOR ',') post_id
FROM wp_postmeta
@mikaelz
mikaelz / delete-all-woocommerce-products.php
Last active October 28, 2024 04:07
Remove all WooCommerce products from database via SQL
<?php
require dirname(__FILE__).'/wp-blog-header.php';
$wpdb->query("DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%')");
$wpdb->query("DELETE FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%'");
$wpdb->query("DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy)");
$wpdb->query("DELETE FROM wp_term_relationships WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'))");
$wpdb->query("DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'))");
$wpdb->query("DELETE FROM wp_posts WHERE post_type IN ('product','product_variation')");