Skip to content

Instantly share code, notes, and snippets.

View yanknudtskov's full-sized avatar

Yan Knudtskov yanknudtskov

View GitHub Profile
@yanknudtskov
yanknudtskov / functions.php
Created August 14, 2019 09:26
This file contains a bunch of helper functions that handle add caching to core WordPress functions.
<?php
/**
* This file contains a bunch of helper functions that handle add caching to core WordPress functions.
*/
/**
* Cached version of get_category_by_slug.
*
* @param string $slug Category slug
* @return object|null|bool Term Row from database. Will return null if $slug doesn't match a term. If taxonomy does not exist then false will be returned.
@yanknudtskov
yanknudtskov / avia-shortcode-overrides.php
Last active February 28, 2024 10:50
Avia Shortcodes Override. Place override shortcodes in /avia-override-shortcodes/ #enfold #shortcodes
/**
* Avia Shortcode Overrides
*/
add_filter('avia_load_shortcodes', 'avia_include_shortcode_template', 15, 1);
function avia_include_shortcode_template($paths)
{
$template_url = get_stylesheet_directory();
array_unshift($paths, $template_url.'/avia-override-shortcodes/');
return $paths;
@yanknudtskov
yanknudtskov / wordpress-db-get-autoload-size.sql
Created October 18, 2017 12:33
This will show you the autoloaded data size, how many entries are in the table, and the first 10 entries by size. #optimization #database #mysql
SELECT 'autoloaded data in KiB' as name, ROUND(SUM(LENGTH(option_value))/ 1024) as value FROM wp_options WHERE autoload='yes'
UNION
SELECT 'autoloaded data count', count(*) FROM wp_options WHERE autoload='yes'
UNION
(SELECT option_name, length(option_value) FROM wp_options WHERE autoload='yes' ORDER BY length(option_value) DESC LIMIT 10)
@yanknudtskov
yanknudtskov / child-theme-functions.js
Last active October 5, 2023 09:54
Dynamically add fees based on selected payment gateway in WooCommerce #woocommerce #dynamic-fees #fees
jQuery(document).ready(function() {
jQuery(document.body).on('change', 'input[name="payment_method"]', function() {
jQuery('body').trigger('update_checkout');
});
});
@yanknudtskov
yanknudtskov / functions.php
Last active October 4, 2023 17:39
Override The Events Calendar Plugin templates for events.Remember to copy the files/wp-content/themes/enfold/config-events-calendar/views/default-template.php/wp-content/themes/enfold/config-events-calendar/views/single-event.phpinto/wp-content/themes/enfold_child_theme_by_yanco/views/default-template.php/wp-content/themes/enfold_child_theme_by_…
<?php
add_action( 'after_setup_theme', 'enfold_child_theme_code' );
function enfold_child_theme_code() {
if(is_child_theme()) remove_action('tribe_events_template', 'avia_events_template_paths', 10, 2);
}
add_action('tribe_events_template', 'avia_events_template_paths_mod', 10, 2);
function avia_events_template_paths_mod($file, $template)
{
@yanknudtskov
yanknudtskov / woocommerce-duplicate-skus.sql
Last active August 31, 2023 09:55
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
@yanknudtskov
yanknudtskov / woocommerce-update-prices.sql
Last active August 1, 2023 23:45
Queries for updating all prices including variations in WooCommerceIn this instance all prices are subtracted 20% (0.8)#woocommerce #mysql
UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_regular_price' AND meta_value != ''
UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_sale_price' AND meta_value != ''
UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_price' AND meta_value != ''
UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_regular_price_tmp' AND meta_value != ''
UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_sale_price_tmp' AND meta_value != ''
UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_price_tmp' AND meta_value != ''
UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_min_variation_price' AND meta_value != ''
UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_max_variation_price' AND meta_value != ''
UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHERE meta_key = '_min_variation_regular_price' AND meta_value != ''
UPDATE wp_postmeta SET meta_value = meta_value*0.8 WHE
@yanknudtskov
yanknudtskov / functions.php
Last active June 20, 2023 19:30
WooCommerce Subscriptions check if the current user has an active subscription
<?php
function yanco_has_active_subscription( $user_id = '' ) {
if( function_exists( 'wcs_user_has_subscription' ) ) {
// When a $user_id is not specified, get the current user Id
if( '' == $user_id && is_user_logged_in() ) {
$user_id = get_current_user_id();
}
// User not logged in we return false
@yanknudtskov
yanknudtskov / functions.php
Created April 17, 2020 08:15
In some cases autoptimize JS scripts will be cached in Google and return 404 results if the autoptimize cache has been cleared. To get around that problem this piece of code returns a HTTP 410 Gone for all those scripts that return a 404 because they have been cleared from the Autoptimize cache.
<?php
add_action( 'template_redirect', 'yanco_404_redirect_to_410_for_autoptimize' );
function yanco_404_redirect_to_410_for_autoptimize() {
if( is_404() ) {
$search = 'cache/autoptimize/js/autoptimize_';
if( strpos( $_SERVER['REQUEST_URI'], $search ) !== false ) {
wp_redirect( $_SERVER['REQUEST_URI'], 410 );
exit;
@yanknudtskov
yanknudtskov / exclude-pattern-autoptimize.php
Last active March 23, 2023 03:36
Exclude an RUL pattern from Autoptimize #autoptimize #optimization
<?php
/**
* Exclude WooCommerce Point of Sale from Autoptimize
*/
add_filter( 'autoptimize_filter_noptimize', 'yanco_exclude_autoptimize', 10, 0);
function yanco_exclude_autoptimize() {
if ( strpos( $_SERVER['REQUEST_URI'], 'pattern-in-url' ) !== false ) {
return true;