久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Woocommerce 變體下拉選項標簽添加一些數據集

Woocommerce variation dropdown option tag add some dataset(Woocommerce 變體下拉選項標簽添加一些數據集)
本文介紹了Woocommerce 變體下拉選項標簽添加一些數據集的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..
<select class="license_type" name="license_type" id="license_type">
    <option value="license" data-set="500">Single Site License</option>
    <option value="license" data-set="700">5 Site License</option>
    <option value="license" data-set="1400">Developers License</option>
</select>

在 woocommerce 變體產品中 - 我想在選項標簽中添加一些數據集標簽.

In the woocommerce variation product - I want to add some data-set tags in option tag.

data-set="<? php  some code here to pull the price of the variation ?>"

是否可以通過鉤子/過濾器實現.

Is that possible through hook/filter.

推薦答案

function get_price_of_current_variant($product, $name, $term_slug) {

    $price = 0;
    foreach ($product->get_available_variations() as $variation) {
        if ($variation['attributes'][$name] == $term_slug)
        $price = $variation['display_price'];
    }

    return $price;
}


add_filter('woocommerce_dropdown_variation_attribute_options_html', 'wt_modifiy_variation_options', 10, 2);

function wt_modifiy_variation_options($html, $args) {


    $options = $args['options'];
    $product = $args['product'];
    $attribute = $args['attribute']; // The product attribute taxonomy
    $name = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title($attribute);
    $id = $args['id'] ? $args['id'] : sanitize_title($attribute);
    $class = $args['class'];
    $show_option_none = $args['show_option_none'] ? true : false;
    $show_option_none_text = __('Add your custom text in here', 'woocommerce');

    if (empty($options) && !empty($product) && !empty($attribute)) {
        $attributes = $product->get_variation_attributes();
        $options = $attributes[$attribute];
    }

    $html = '<select id="' . esc_attr($id) . '" class="' . esc_attr($class) . 'customdropdown" name="' . esc_attr($name) . '" data-attribute_name="attribute_' . esc_attr(sanitize_title($attribute)) . '" data-show_option_none="' . ( $show_option_none ? 'yes' : 'no' ) . '">';
    $html .= '<option value="">' . esc_html($show_option_none_text) . '</option>';



    if (!empty($options)) {
        if ($product && taxonomy_exists($attribute)) {
            $terms = wc_get_product_terms($product->get_id(), $attribute, array('fields' => 'all'));


            foreach ($terms as $term) {
                if (in_array($term->slug, $options)) {

                    $variat_price = get_price_of_current_variant($product, $name, $term->slug);


                    $data_attr = "data-custom=$variat_price";
                    $html .= '<option value="' . esc_attr($term->slug) . '" ' . selected(sanitize_title($args['selected']), $term->slug, false) . $data_attr . '>' . esc_html(apply_filters('woocommerce_variation_option_name', $term->name)) . '</option>';
                }
            }
        } else {
            foreach ($options as $option) {

                $selected = sanitize_title($args['selected']) === $args['selected'] ? selected($args['selected'], sanitize_title($option), false) : selected($args['selected'], $option, false);

                $variat_price = get_price_of_current_variant($product, $name, $option);

                $data_attr = "data-custom=$variat_price";
                $html .= '<option value="' . esc_attr($option) . '" ' . $selected . $data_attr . '>' .
                        esc_html(apply_filters('woocommerce_variation_option_name', $option)) . '</option>';
            }
        }
    }
    $html .= '</select>';


    return $html;
}

這是您要查找的代碼..

This is the code for what you are looking..

這篇關于Woocommerce 變體下拉選項標簽添加一些數據集的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 精品欧美一区二区三区久久久 | 青青草精品 | 亚洲综合视频一区 | 成人精品一区二区三区四区 | 亚洲国产精品一区 | 爱综合| 一区二区三区视频在线免费观看 | 欧美性video| 狠狠艹| 久久久黄色| 欧美黄色精品 | 久久精品免费观看 | 久久黄色精品视频 | 欧美黄色一区 | 一区二区在线观看av | 久久精品欧美一区二区三区麻豆 | 国产不卡在线观看 | 国产欧美精品一区二区色综合朱莉 | 一区二区三区视频在线 | 五月激情六月婷婷 | 成人免费看片网 | 精精精精xxxx免费视频 | 国产精品综合久久 | 亚洲高清电影 | 精品成人在线 | 国产亚洲精品久久久优势 | 亚洲欧洲中文 | h视频在线免费 | 免费a v网站 | 亚洲成人免费观看 | 色免费在线视频 | 在线免费黄色 | 国产传媒毛片精品视频第一次 | 人人九九精 | 成人综合久久 | 国产精品成人一区二区 | 在线激情视频 | 国产乱码精品一区二区三区五月婷 | 韩国av一区二区 | 在线观看中文字幕亚洲 | 日韩在线免费视频 |