Skip to content

Instantly share code, notes, and snippets.

View bvdr's full-sized avatar
👋
Hello World!

Bogdan Dragomir bvdr

👋
Hello World!
View GitHub Profile
@bvdr
bvdr / WP CLI
Last active September 22, 2021 13:42
WP CLI COMMANDS
# REMOVE ALL ITEMS IN POST TYPE
wp post list --path='./wp' --field=ID --post_type=product --posts_per_page=2000 | xargs wp post delete --force
# REMOVE ALL ATTRIBUTES
wp wc product_attribute list --context='edit' --path='./wp' --field=id --user=dekode | xargs -n1 -I % sh -c 'echo "Removing attribute %"; wp wc product_attribute delete % --user=dekode'
@bvdr
bvdr / override_translatable_strings.php
Last active June 17, 2021 11:34
Overide translatable strings in WordPress and Plugins
<?php
/**
* Custom Translated text for overwriting woocommerce
*
* @param string $translated_text Custom translated text.
* @param string $text Text.
* @param string $domain Translation domain.
*
* @return string|void
*/
@bvdr
bvdr / allow-recurring-events-in-stagemode.php
Last active October 1, 2020 13:44
Activate WooCommerce Subscriptions recurring events for custom billing email for testing recurring payments
<?php
/**
* Test recurring payments in staging mode.
* [USAGE] WooCommerce subscriptin is handling subscriptions as manual subscriptions if the 'stage' mode is on.
* Luckly we can hook and filter by signup email. We don't want this to be working with all existing subscriptions so
* we are filtering by email.
*
* [INSTALLATION] This can be packed as mu-plugin.
*
* [DISCLAMER] This is critical developer only information and it can trigger real payments in your stage environment.
@bvdr
bvdr / autocomplete-orders.php
Created February 26, 2020 09:06
Autocomplete orders in WooCommerce
<?php
/**
* Autocomplete orders in subscription.
*
* @package CustomWoo
*/
declare( strict_types=1 );
namespace Custom\Woo\Extras;
@bvdr
bvdr / disable-woocommerce-email-inline-styles.php
Last active May 30, 2019 10:05
Disable woocommerce emails inline styling
<?php
if ( ! function_exists( __NAMESPACE__ . '\\disable_email_styling' ) ) {
function disable_email_styling() {
add_filter( 'woocommerce_email_styles', '__return_null', 20 );
}
add_action( 'init', __NAMESPACE__ . '\\disable_email_styling' );
}
@bvdr
bvdr / select-active-subscribers.sql
Created February 1, 2019 18:18
Select subscriptions
create table wp_custom_payments
select
p.ID as order_id,
p.post_date,
p.post_status,
max( CASE WHEN pm.meta_key = '_billing_email' and p.ID = pm.post_id THEN pm.meta_value END ) as billing_email,
max( CASE WHEN pm.meta_key = '_billing_first_name' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_first_name,
max( CASE WHEN pm.meta_key = '_billing_last_name' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_last_name,
max( CASE WHEN pm.meta_key = '_order_total' and p.ID = pm.post_id THEN pm.meta_value END ) as order_total,
max( CASE WHEN pm.meta_key = '_customer_ip_address' and p.ID = pm.post_id THEN pm.meta_value END ) as order_ip,
@bvdr
bvdr / git-clone-in-non-empty-folder.sh
Created January 9, 2018 10:37
Git clone into not empty folder/directory
# Creates empty repo in current folder
git init
# Links to remote
git remote add origin PATH/TO/REPO
# Gets remote repo
git fetch
# Resets to master branch from remote
@bvdr
bvdr / get_active_subscribers.sql
Created August 1, 2016 15:02
Selects active subscription users in WooCommerce Subscriptions
select
p.ID as order_id,
p.post_date,
max( CASE WHEN pm.meta_key = '_billing_email' and p.ID = pm.post_id THEN pm.meta_value END ) as billing_email,
max( CASE WHEN pm.meta_key = '_billing_first_name' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_first_name,
max( CASE WHEN pm.meta_key = '_billing_last_name' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_last_name,
max( CASE WHEN pm.meta_key = '_order_total' and p.ID = pm.post_id THEN pm.meta_value END ) as order_total,
max( CASE WHEN pm.meta_key = '_payment_method' and p.ID = pm.post_id THEN pm.meta_value END ) as payment_method,
max( CASE WHEN pm.meta_key = '_order_tax' and p.ID = pm.post_id THEN pm.meta_value END ) as order_tax,
max( CASE WHEN pm.meta_key = '_paid_date' and p.ID = pm.post_id THEN pm.meta_value END ) as paid_date,
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
@bvdr
bvdr / get-image-color-wordpress.js
Last active March 16, 2016 13:23
Create a `Get Color` button under featured image in WordPress to get the dominant color from the featured image. In this example the color is set to an Advanced Custom Fields color picker field but you can do pretty much everything with it. Credits to used libraries are in the file. This file should be loaded with admin_enqueue
/*!
* Color Thief v2.0
* by Lokesh Dhakar - http://www.lokeshdhakar.com
*
* Thanks
* ------
* Nick Rabinowitz - For creating quantize.js.
* John Schulz - For clean up and optimization. @JFSIII
* Nathan Spady - For adding drag and drop support to the demo page.
*