Skip to content

Instantly share code, notes, and snippets.

@shreyans94
shreyans94 / gist:05b10194cf2f57cf054a5cf3da3fd931
Created January 23, 2018 21:32
Display ACF for woocommerce variations in backend
// Render fields at the bottom of variations - does not account for field group order or placement.
add_action( 'woocommerce_product_after_variable_attributes', function( $loop, $variation_data, $variation ) {
global $abcdefgh_i; // Custom global variable to monitor index
$abcdefgh_i = $loop;
// Add filter to update field name
add_filter( 'acf/prepare_field', 'acf_prepare_field_update_field_name' );
// Loop through all field groups
$acf_field_groups = acf_get_field_groups();
foreach( $acf_field_groups as $acf_field_group ) {
@shreyans94
shreyans94 / gist:39b688682fc9b164d2ab3911688b2e21
Created January 23, 2018 21:39
Move Woocommerce Short Description Below Add to Cart in Product Page
//* change product excerpt and add to cart order in the single product page *//
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 50 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 20 );
@shreyans94
shreyans94 / Remove woocommerce print invoice and packing slip plugin invoice link from emails.txt
Last active January 29, 2018 14:16
Remove woocommerce print invoice and packing slip plugin invoice link from emails
@shreyans94
shreyans94 / gist:500e105a441279ac0cd945ad93ab7c3b
Last active January 29, 2018 14:16
Product Variation Custom Fields
add_filter( 'woocommerce_available_variation', 'load_variation_settings_fields' );
function load_variation_settings_fields($variations) {
// duplicate the line for each field
/*$variations['veg_nonveg'] = get_post_meta( $variations[ 'variation_id' ], '_veg-nonveg');
$variations['no_serving'] = get_post_meta( $variations[ 'variation_id' ], '_no-serving', true );
$variations['serving_size'] = get_post_meta( $variations[ 'variation_id' ], '_serving-size', true );
$variations['total_protein'] = get_post_meta( $variations[ 'variation_id' ], '_total-protein', true );
$variations['protein_percentage'] = get_post_meta( $variations[ 'variation_id' ], '_protein-percentage', true );
$variations['protein_per_serving'] = get_post_meta( $variations[ 'variation_id' ], '_protein-per-serving', true );
@shreyans94
shreyans94 / gist:dad92a9d587a883a32efd998bb594f0b
Created January 23, 2018 21:41
Edit Woocommerce/Wordpress Password Strength and its Text (From strength 3 to 1)
function wc_ninja_remove_password_strength() {
if ( wp_script_is( 'wc-password-strength-meter', 'enqueued' ) ) {
wp_dequeue_script( 'wc-password-strength-meter' );
}
}
add_action( 'wp_print_scripts', 'wc_ninja_remove_password_strength', 100 );
add_filter( 'woocommerce_min_password_strength', create_function( '', 'return 1;' ) );
add_action( 'wp_enqueue_scripts', 'my_strength_meter_localize_script' );
@shreyans94
shreyans94 / gist:74549e9b9c5bd3f293d5dc246c28f524
Created January 23, 2018 21:41
Change Woocommerce Out of Stock Text
add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
function wcs_custom_get_availability( $availability, $_product ) {
// Change Out of Stock Text
if ( ! $_product->is_in_stock() ) {
$availability['availability'] = __('<b>SOLD OUT!</b><BR><BR>
<font color=#007a00;> </font>', 'woocommerce');
}
return $availability;
@shreyans94
shreyans94 / gist:291e722dc055c5b84abab2eef7e87fc2
Created January 23, 2018 21:40
remove coupon field on woocommerce cart page
// hide coupon field on cart page.
function hide_coupon_field_on_cart( $enabled ) {
if ( is_cart() ) {
$enabled = false;
}
return $enabled;
}
add_filter( 'woocommerce_coupons_enabled', 'hide_coupon_field_on_cart' );
@shreyans94
shreyans94 / gist:7fbd541c7298908304fbea4a14de92fd
Created January 23, 2018 21:39
Add Sale Badge On Product Page (WooThumbs Comaptibility)
add_action('woocommerce_before_single_product_summary','flatsome_sale_flash_custom',21);
function flatsome_sale_flash_custom(){
do_action('flatsome_sale_flash');
}
@shreyans94
shreyans94 / gist:7e8da767176feb1dda5966c8f0dcb79f
Created January 23, 2018 21:38
WooCommerce Variations Ajax Fix
function iconic_wc_ajax_variation_threshold( $qty, $product ) {
return 50;
}
add_filter( 'woocommerce_ajax_variation_threshold', 'iconic_wc_ajax_variation_threshold', 10, 2 );
@shreyans94
shreyans94 / gist:a36f46b06af060cb95ce12e4d3d8d715
Created January 23, 2018 21:38
Change subject in woocommerce new order email
/**
* @snippet Add Billing First_name to Email Receipt
* @how-to Watch tutorial @ https://businessbloomer.com/?p=19055
* @sourcecode https://businessbloomer.com/?p=19870
* @author Rodolfo Melogli
* @testedwith WooCommerce 2.5.2
*/
add_filter('woocommerce_email_subject_customer_processing_order', 'bbloomer_change_processing_email_subject', 10, 2);