Skip to content

Instantly share code, notes, and snippets.

@daddiofaddio
daddiofaddio / acf-multiselect-limit.txt
Last active June 11, 2022 22:54
ACF multi-select add limit/custom validation
/* SET ACF MULTI-SELECT LIMIT & CUSTOM VALIDATION */
function acf_validate_value_la_custom_select( $valid, $value, $field, $input ){
if( !$valid ) {
return $valid;
}
if((is_countable($value)) && (count($value) > 4)) {
$valid = 'You can only select 4 custom badges.';
} else {
$valid = true;
}
@daddiofaddio
daddiofaddio / gist:77607850907e0f340874be98e526cb87
Created June 11, 2022 22:30
Remove Woocommerce checkout fields (functions.php)
/* REMOVE WOO CHECKOUT FIELDS */
function custom_remove_woo_checkout_fields($fields) {
// remove billing fields
unset($fields['billing']['billing_first_name']);
unset($fields['billing']['billing_last_name']);
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_city']);
unset($fields['billing']['billing_postcode']);
@daddiofaddio
daddiofaddio / gist:a9b889e87feedc3676d6644b27a30fcc
Created June 11, 2022 22:33
Remove Woocommerce billing fields for logged in users only (functions.php)
/* REMOVE ALL WOO BILLING FIELDS FOR LOGGED IN USERS ONLY */
function custom_override_checkout_fields( $fields ) {
if( is_user_logged_in() ) {
unset($fields['billing']);
$fields['billing'] = array();
}
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
@daddiofaddio
daddiofaddio / gist:758d2c95444a68de7d7629b8bf15ba78
Created June 11, 2022 22:35
Remove Woocommerce Billing Details header for logged in users only (functions.php)
/* REMOVE WOO BILLING DETAILS HEADER FOR LOGGED IN USERS ONLY */
function wc_order_review_strings( $translated_text, $text, $domain ) {
if( is_user_logged_in() ) {
switch ($translated_text) {
case 'Billing details' :
$translated_text = __( '', 'woocommerce' );
break;
}
}
return $translated_text;
@daddiofaddio
daddiofaddio / gist:9255b91d0f73451b99ce5f4e6e6b20c8
Created June 11, 2022 22:37
Remove Woocommerce checkout redirect empty cart/expired message (functions.php)
/* REMOVE WOO EMPTY CART CHECKOUT ERROR MESSAGE */
add_filter('woocommerce_checkout_redirect_empty_cart', '__return_false');
add_filter('woocommerce_checkout_update_order_review_expired', '__return_false');
@daddiofaddio
daddiofaddio / gist:1b074ffd34dca40c0dbb10a47b238e79
Created June 11, 2022 22:46
Display avatar & username shortcode (functions.php)
/* DISPLAY AVATAR AND USERNAME SHORTCODE */
function custom_display_avatar() {
if (is_user_logged_in()) {
global $current_user;
wp_get_current_user();
return get_avatar($current_user->ID, 96);
}
else {
return get_avatar('https://url-to-custom-default-avatar-img.webp');
}
@daddiofaddio
daddiofaddio / gist:790ca17d7c2b9919ac91804a9c3086d1
Created June 11, 2022 22:49
Enqueue custom css/hide element on specific page (functions.php)
/* ENQUEUE CUSTOM CSS/HIDE ELEMENT ON SPECIFIC PAGE */
function ploa_add_custom_css() {
wp_enqueue_style('custom-css');
if ( is_page(309)) {
$custom_css = ".payment-plan-61 .acf-field.acf-field-select.acf-field-62kjk9b59635b1b {display: none;}";
wp_add_inline_style( 'custom-css', $custom_css);
}
}
add_action( 'wp_enqueue_scripts', 'ploa_add_custom_css' );
@daddiofaddio
daddiofaddio / gist:6ba03bb58cf6ec27209312402feec03d
Created June 11, 2022 22:53
Fix for no logout in Woocommerce & bypass logout confirmation (functions.php)
/* FIX FOR WOO NO LOGOUT */
function ploa_bypass_logout_confirmation() {
global $wp;
if ( isset( $wp->query_vars['customer-logout'] ) ) {
wp_redirect( str_replace( '&', '&', wp_logout_url( wc_get_page_permalink( 'myaccount' ) ) ) );
exit;
}
}
add_action( 'template_redirect', 'ploa_bypass_logout_confirmation' );
@daddiofaddio
daddiofaddio / gist:6d48a101263720f5d5015bf6ce9902d6
Last active June 11, 2022 22:59
Migrate Bootstrap 4 classes to Bootstrap 5
#MIGRATE BOOTSTRAP4 CLASSES TO BOOTSTRAP5
set -x
set -e
migration_folder=$1
find_regex=".*/*.tsx?|.*/*.scss?|.*/*.php?|.*/*.css?|.*/*.js?|.*/*.html?"
ignore_path="*/$1node_modules/*"
find $migration_folder -regextype posix-egrep -regex $find_regex -type f -not -path $ignore_path | xargs sed -i.bak -E '/[(class)(")]/{
s/([mp])l(-[0-5])/\1s\2/g
s/([mp])r(-[0-5])/\1e\2/g
s/no-gutters/g-0/g
@daddiofaddio
daddiofaddio / gist:64b8245a81c26c32dd14f8f1461ff7ec
Created June 11, 2022 23:02
Woocommerce remove & replace Select2 styles with Bootstrap5
/* WOO REMOVE & REPLACE SELECT2 STYLES TO BS */
add_action('wp_enqueue_scripts', 'agentwp_dequeue_stylesandscripts', 100);
function agentwp_dequeue_stylesandscripts() {
if (class_exists('woocommerce')) {
wp_dequeue_style('selectWoo');
wp_deregister_style('selectWoo');
wp_dequeue_style('select2');
wp_deregister_style('select2');
wp_dequeue_script('selectWoo');
wp_deregister_script('selectWoo');