php - 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 和其他唯一名称,它将禁用添加到购物车功能以正常工作
推荐阅读
- javascript - 如何使用 v-for (Vue.js) 循环 JSON 对象并将渲染的 DOM 拆分为两个 div 容器?
- java - OpenCV4 中似乎缺少 Imgproc.undistort()
- javascript - 从前端到后端的大图像,无需 base64 编码
- vba - MSAccess 在打开文件时崩溃
- c# - 关闭后是否需要“处置”“Windows.Form”?
- graphql - 如何在 React-Admin 中配置端点和自定义 graphql 查询
- sql - 如何在 string_agg 中合并已排序的重复值
- java - 在这种情况下如何将元素添加到 ArrayList
- xml - 无法使用 SRA 工具包中的 fastq-dump,因为在 @INC 中找不到 XML/LibXML.pm
- python - 如何在 django.views.generic 中添加额外的类别字段