Skip to content

Instantly share code, notes, and snippets.

View rwkyyy's full-sized avatar
🏠
Working from home

RwkY rwkyyy

🏠
Working from home
View GitHub Profile
@rwkyyy
rwkyyy / functions.php
Last active May 30, 2022 09:13
DEAD simple breadcrumb PHP function with Polylang
//breadcrumbs
function get_breadcrumb() {
//default link (home
echo '<a href="' . home_url() . '" rel="nofollow">Home</a>';
//polylang conditional, you can remove this if you do not need
if (pll_current_language() == 'ro') {
echo '<a href="' . home_url() . '" rel="nofollow">Acasă</a>';
} else if (pll_current_language() == 'en') {
@rwkyyy
rwkyyy / run.sql
Last active May 17, 2022 07:08
Clean WooCommerce order/product tables
/*Order*/
DELETE FROM wp_woocommerce_order_itemmeta;
DELETE FROM wp_woocommerce_order_items;
DELETE FROM wp_comments WHERE comment_type = 'order_note';
DELETE FROM wp_postmeta WHERE post_id IN ( SELECT ID FROM wp_posts WHERE post_type = 'shop_order' );
DELETE FROM wp_posts WHERE post_type = 'shop_order';
/*Products*/
DELETE FROM wp_postmeta WHERE post_id IN ( SELECT ID FROM wp_posts WHERE post_type IN ( 'product', 'product_variation' ));
DELETE FROM wp_posts WHERE post_type IN ( 'product', 'product_variation' );
@rwkyyy
rwkyyy / run.sql
Created April 29, 2022 12:45
WP migrate url old to new via SQL
UPDATE wp_options SET option_value = replace(option_value, 'oldurl.com', 'newurl.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'oldurl.com','newurl.com');
UPDATE wp_posts SET post_content = replace(post_content, 'oldurl.com', 'newurl.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'oldurl.com','newurl.com');
@rwkyyy
rwkyyy / functions.php
Created April 26, 2022 10:26
Browser Theme Color (Android) for WordPress
add_action('wp_head', 'head_meta_hookin');
function head_meta_hookin() {
echo '<meta name="theme-color" content="#6eb726">';
echo '<meta name="msapplication-navbutton-color" content="#6eb726">';
echo '<meta name="apple-mobile-web-app-capable" content="yes">';
echo '<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">';
}
@rwkyyy
rwkyyy / functions.php
Created March 29, 2022 14:05
Enable Catalog Visibility in WooCommerce Product Editor (Gutenberg)
// fix catalog visibility
// original author + credits to https://dev.to/kalimahapps/enable-gutenberg-editor-in-woocommerce-466m
function enable_taxonomy_rest( $args ) {
$args['show_in_rest'] = true;
return $args;
}
add_filter( 'woocommerce_taxonomy_args_product_tag', 'enable_taxonomy_rest' );
@rwkyyy
rwkyyy / functions.php
Created February 16, 2022 15:14
polylang + booster currency switcher - switch automatically on language change
//searched a lot for this, ended up coding it myself -- based on WOOCS and WPML.
add_filter('wp_head', function() {
$lang = get_locale();
switch ($lang)
{
case 'ro_RO':
wcj_session_set( 'wcj-currency', 'RON' );
break;
case 'fr_FR':
wcj_session_set( 'wcj-currency', 'EUR' );
@rwkyyy
rwkyyy / functions.php
Created January 13, 2022 21:03
afișare număr awb și buton în mail-urile de WC - Sameday România
function rwky_display_awb_mail( $order, $sent_to_admin, $plain_text ) {
// global $wpdb;
$awb = SamedayCourierQueryDb::getAwbForOrderId( sanitize_key( $order->get_id() ) );
$awbNumber = $awb->awb_number;
if ( $awbNumber ) {
echo 'Poți urmări expediția aici:<br><a href="https://sameday.ro/#awb=' . $awbNumber . '" class="button" >AWB: ' . $awbNumber . '</a></br></br>';
} else {
echo '';
@rwkyyy
rwkyyy / functions.php
Last active January 18, 2022 12:42
CLI close orders bulk
// CLI init & close BULK
function orders_close_query() {
$args = array(
'post_type' => 'shop_order',
'posts_per_page' => -1,
'post_status' => 'wc-shipped',
// 'order_by' => 'publish_date',
// 'order' => 'ASC'
);
@rwkyyy
rwkyyy / query.sql
Last active March 24, 2022 10:13
SQL cheatbook for big WP tables
--See what is eating up (duplicate no):
SELECT COUNT(meta_key), meta_key FROM wp_postmeta GROUP BY meta_key ORDER BY COUNT(meta_key) DESC;
-- See what is eating up (size kb/gb):
SELECT meta_key, (SUM(LENGTH(meta_id)+LENGTH(post_id)+LENGTH(meta_key)+LENGTH(meta_value)))/1048576 AS `Size`, COUNT(*) AS `Count` FROM wp_postmeta
GROUP BY `meta_key`
ORDER BY `Size` DESC
--Get a key that is duplicate
SELECT * FROM wp_postmeta WHERE `meta_key` LIKE ‘%keyword%’;
@rwkyyy
rwkyyy / functions.php
Last active December 2, 2020 16:09
restrict payment gateway based on coupon code
add_filter( 'woocommerce_available_payment_gateways', 'conditional_available_payment_gateways' 20, 1 );
function conditional_available_payment_gateways( $available_gateways ) {
if( is_admin() ) return $available_gateways; // Only for frontend admin
$coupon_code ='cod';
if ( WC()->cart->has_discount( $coupon_code ) ) {
unset( $available_gateways['cod'] );
}