Replace default “Select Option” text in Woocommerce variation attribute dropdowns by different custom ones

后端 未结 1 1495
栀梦
栀梦 2021-01-16 17:42

I am just starting out with Woocommerce and have a question about drop down select field for variable products. In woocommerce when nothing is selected on this dropdowns, \"

相关标签:
1条回答
  • In woocommerce the attributes IDs (or taxonomy) begin all by pa_ as "product attribute", so:

    • The <select> html tag for "Type" should have: id="pa_type" (but not id="type"),
    • The <select> html tag for "Size" should have: id="pa_size" (but not id="size").

    Now you can target each attribute by its taxonomy slug this way:

    add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'dropdown_variation_attribute_options', 10, 1 );
    function dropdown_variation_attribute_options( $args ){
    
        // For attribute "Type"
        if( 'pa_type' == $args['attribute'] )
            $args['show_option_none'] = __( 'Select Framed or Unframed Types', 'woocommerce' );
    
        // For attribute "Sizes"
        if( 'pa_size' == $args['attribute'] )
            $args['show_option_none'] = __( 'Select Framed or Unframed Sizes', 'woocommerce' );
    
        return $args;
    }
    

    Code goes in function.php file of your active child theme (or active theme).

    Tested and works.


    You are asking many different questions. Here I answer just one. It's the way on StackOverFlow.

    Everything is possible in WooCommerce, depending on your knowledge, skills and time to spend.

    Your 2nd question is something advanced, complicated and a bit too broad.

    0 讨论(0)
提交回复
热议问题