Woocommerce variation dropdown option tag add some dataset

后端 未结 2 1215
梦如初夏
梦如初夏 2020-12-21 20:17
';
    $html .= '';



    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 .= '';
                }
            }
        } 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 .= '';
            }
        }
    }
    $html .= '';


    return $html;
}

This is the code for what you are looking..

提交回复
热议问题