Home / eCommerce / Fix “Send to Friend” Field Visibility for Variable Gift Cards
Duplicate Snippet

Embed Snippet on Your Site

Fix “Send to Friend” Field Visibility for Variable Gift Cards

This fix ensures the “Send to Friend” fields display correctly based on the selected variable gift card value when using the Themify Ultra theme.

Code Preview
php
<?php
function themify_fix_agcfw_variable_product_scripts() {
    // Only run on single product pages
    if ( ! is_product() ) {
        return;
    }
	
    // Only run if Themify theme is active
    if ( ! class_exists( 'Themify_Enqueue_Assets' ) ) {
        return;
    }
    
    // Only run if WooCommerce Script Optimization is enabled
    if ( function_exists( 'themify_check' ) && themify_check( 'setting-optimize-wc', true ) ) {
        return; // Optimization is disabled, no need to fix
    }
    
    global $wp_scripts;
    
    // Remove wc-add-to-cart-variation from the "done" list if it was marked
    // This allows it to load normally through WordPress
    if ( isset( $wp_scripts->done ) && is_array( $wp_scripts->done ) ) {
        $done_key = array_search( 'wc-add-to-cart-variation', $wp_scripts->done );
        if ( false !== $done_key ) {
            unset( $wp_scripts->done[ $done_key ] );
        }
    }
}
add_action( 'wp_enqueue_scripts', 'themify_fix_agcfw_variable_product_scripts', 12 );
/**
 * Remove wc-add-to-cart-variation from Themify's dynamic load array on product pages
 * This prevents the theme from trying to load it dynamically
 */
function themify_remove_variation_script_from_theme_optimization( $vars ) {
    // Only modify on product pages
    if ( is_product() && isset( $vars['wc_js']['wc-add-to-cart-variation'] ) ) {
        // Remove from the dynamic load array
        unset( $vars['wc_js']['wc-add-to-cart-variation'] );
    }
    
    return $vars;
}
add_filter( 'themify_main_script_vars', 'themify_remove_variation_script_from_theme_optimization' );

Comments

Add a Comment