WooCommerce产品变体下拉列表的自定义HTML [英] Custom HTML for WooCommerce product variation dropdown

查看:273
本文介绍了WooCommerce产品变体下拉列表的自定义HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取单个产品页面变体下拉菜单的自定义HTML .

此处.

另一个参考链接

其功能位于此处→

woocommerce/includes/wc-template-functions.php

我希望最终的HTML看起来像这样→

<select class="customdropdown" name="customdropdown" id="customdropdown">
    <option value="license_one" data-1="500">License One</option>
    <option value="license_two" data-2="700">License Two</option>
    <option value="license_three" data-3="1400">License Three</option>
</select>

什么是正确的过程? 我们必须编辑一些模板,还是必须通过在WooCommerce中使用某些挂钩进行更改?

如果有一些钩子.有人可以引导我找到合适的钩子吗?

解决方案

add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'wt_dropdown_choice' );

/**
 * Change the custom dropdown  "Choose an option" text on the front end
 */
function wt_dropdown_choice( $args ){
        if( is_product() ) {
                $args['show_option_none'] = "Add your custom text in here"; // Change your text here
                $args['class'] = 'customdropdown';
        }  
        return $args;    
}

尝试使用此代码将类添加到选择框中-您无法更改属性的ID和其他唯一名称,这将使添加到购物车功能无法正常工作

I want to get the CUSTOM HTML for Single Product Page variation Drop Down.

I got some clue here.

Another reference Link

Its Functions are located here →

woocommerce/includes/wc-template-functions.php

I want that the Final HTML to look like this →

<select class="customdropdown" name="customdropdown" id="customdropdown">
    <option value="license_one" data-1="500">License One</option>
    <option value="license_two" data-2="700">License Two</option>
    <option value="license_three" data-3="1400">License Three</option>
</select>

What is the correct process? We have to edit some template or we have to make changes by using some hooks in WooCommerce?

If there is some hook. Can someone guide me to the proper hook?

解决方案

add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'wt_dropdown_choice' );

/**
 * Change the custom dropdown  "Choose an option" text on the front end
 */
function wt_dropdown_choice( $args ){
        if( is_product() ) {
                $args['show_option_none'] = "Add your custom text in here"; // Change your text here
                $args['class'] = 'customdropdown';
        }  
        return $args;    
}

Try this code for adding class to the select box - You cannot change the id and other unique names for attributes, it will disable the add to cart function to work properly

这篇关于WooCommerce产品变体下拉列表的自定义HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆