• Resolved alexli126

    (@alexli126)


    Hello,

    Thanks for the great plugin.

    We would like to set value of gender to product like Male, Female, Unisex, and set product feeds to Google, that is recommend by Google.

    So, I set gender globally:

    https://prnt.sc/qCyaRChXQGuI

    and please note that pa_gender is included in the url :

    https://mysite.com/wp-admin/edit-tags.php?taxonomy=pa_gender&post_type=product

    For a specific variable product, some variations are Unisex, but some are Female, and please check the screenshot to understand what I mean:

    https://prnt.sc/uRv7AquycuFo

    There are blue, black green colors, and the gender of these colors varaitons should be unisex, but pink color one should be Female.

    However, for user-friendly purpose, the Gender option are useless, and these option are sometimes cause the customer confused. The Gender here are actually only used for Google feeds.

    So, I tried code snippet to set gender optional but not required before adding to cart, and tried to hide Gender option by CSS. Here are code snippts I tried:

    // Make the gender attribute optional in the dropdown
    add_filter('woocommerce_dropdown_variation_attribute_options_args', 'make_gender_optional', 10, 1);

    function make_gender_optional($args) {
    if (isset($args['attribute']) && $args['attribute'] === 'pa_gender') {
    $args['show_option_none'] = __('No preference', 'woocommerce');
    $args['option_none_value'] = ''; // Optionally set the value to empty
    }
    return $args;
    }

    // Ensure variations are active regardless of attribute selection
    add_filter('woocommerce_variation_is_active', 'allow_empty_gender_variation', 10, 2);

    function allow_empty_gender_variation($is_active, $variation) {
    return true; // Always show variations as active
    }

    Unfortunately, it does not work.

    Considering this plugin is activated, and I tried the code below:

    // Make the gender attribute optional in the dropdown
    add_filter('woocommerce_dropdown_variation_attribute_options_args', 'make_gender_optional', 10, 1);

    function make_gender_optional($args) {
    if (isset($args['attribute']) && $args['attribute'] === 'pa_gender') {
    $args['show_option_none'] = __('No preference', 'woocommerce');
    $args['option_none_value'] = ''; // Optionally set the value to empty
    }
    return $args;
    }

    // Ensure variations are active regardless of attribute selection
    add_filter('woocommerce_variation_is_active', 'allow_empty_gender_variation', 10, 2);

    function allow_empty_gender_variation($is_active, $variation) {
    return true; // Always show variations as active
    }

    // Adjusting for Variation Swatches for WooCommerce plugin
    add_filter('woocommerce_variation_option_name', 'adjust_variation_option_name', 10, 1);

    function adjust_variation_option_name($name) {
    // Check if the attribute is 'pa_gender'
    if ($name === 'pa_gender') {
    $name = ''; // Or customize as needed
    }
    return $name;
    }

    Unfortunately, it does not work either.

    Could you please show a code snippet to better match this plugin and set gender to be optional and set it invisiable at frontend please?

    Thank so much

Viewing 1 replies (of 1 total)
  • Plugin Support fizanzvai

    (@fizanzvai)

    Hi,

    Thanks for reaching out to us. Using basic WooCommerce Variable Product you can’t achieve this goal. There is no conditional system with WooCommerce Variable Product. Our plugin just converts the default dropdown and display swatches. Our plugin follows the WooComerce structures.

    You can search for a plugin called Product Addons for WooCommerce. Perhaps that plugin will help you to set conditional options.

    Thank You

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.