Skip to content

Instantly share code, notes, and snippets.

View bmakowski's full-sized avatar

Bartek Makowski bmakowski

  • Poland, Bydgoszcz
View GitHub Profile
@bmakowski
bmakowski / query.sql
Created October 28, 2020 18:35
clear all orders, subscriptions and customers
delete
p,pm
from wp_posts p
join wp_postmeta pm on pm.post_id = p.id
where p.post_type = 'shop_order';
delete
p,pm
from wp_posts p
join wp_postmeta pm on pm.post_id = p.id
where p.post_type = 'shop_subscription';
@bmakowski
bmakowski / regex.txt
Last active November 22, 2018 11:55
Regex: Validate spaces between Street Address
/^\d+(\s[A-Z]*[a-z]*[.]*){1,}(\s\d*)*$/
@bmakowski
bmakowski / reviews.sql
Last active July 15, 2018 20:36
Enable WooCommerce reviews
-- to open reviews for currently added products
UPDATE wp_posts SET comment_status = 'open' WHERE post_type = 'product';
-- to close reviews
UPDATE wp_posts SET comment_status = 'closed' WHERE post_type = 'product';
@bmakowski
bmakowski / array.php
Created June 27, 2018 09:39
Convert an array of strings into an array of integers
<?php
// Traditional way
$array = array('0', '1', '2');
foreach ($array as $key => $var) {
$array[$key] = (int)$var;
}
// The nice way
$array = array('0', '1', '2');
@bmakowski
bmakowski / functions.php
Created May 29, 2018 08:58
WooCommerce additional custom popup on checkout when processing payment
add_action( 'woocommerce_before_checkout_form', 'custom_payment_overlay' );
function custom_payment_overlay(){
echo sprintf('<div class="custom-payment-popup"><div class="wpt-payment-overlay"></div><div class="wpt-payment-message">%s</div></div>',
'We are processing your payment. Please hold on and do not refresh your browser.'
);
}
@bmakowski
bmakowski / query.sql
Created May 25, 2018 11:39
WordPress SQL delete all WooCommerce customers
delete
u,um
from wp_users u
join wp_usermeta um on um.user_id = u.id
where um.meta_key = 'wp_user_level' and um.meta_value = 0
@bmakowski
bmakowski / query.sql
Created May 13, 2018 14:43
Wordpress SQL Delete Custom Post Types and Meta
delete
p,pm
from wp_posts p
join wp_postmeta pm on pm.post_id = p.id
where p.post_type = 'companies'
@bmakowski
bmakowski / delete customers.txt
Created April 25, 2018 11:41
Delete all WooCommerce Customers by WP CLI
wp user list --field=ID --role=customer | xargs wp user delete --yes
@bmakowski
bmakowski / ragex.txt
Created January 17, 2018 02:52
Validate domain ragular expression
This allows only domains with "." for example "example.com"
^(?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63}$
This allows also one-name domains like "localhost". "." is optional
^(?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.?){1,126}(?!\d+)[a-zA-Z\d]{1,63}$
@bmakowski
bmakowski / preg_match_domain_name.php
Last active December 13, 2017 16:15
Preg Match domain name
<?php
if( !preg_match('/^(?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63}$/', $domain) ){
// didn't match return error
return false;
}