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

别说谁变了你拦得住时间么 提交于 2019-11-29 13:04:43

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!