製品のバリエーションを選択オプションからラジオ入力に変更しようとしました。私は私の子供のテーマを複製し、ファイルvariable.php
を更新しました。いくつかの変更を行ったが、私はカートに追加しようとすると、私はエラーを持っている:Woocommerceの<variation>の値が無効です
Invalid value posted for Size
これは、選択したバージョンからのHTMLです:
<select id="size" class="" name="attribute_size" data-attribute_name="attribute_size" data-show_option_none="yes">
<option value="">Choose an option</option>
<option value="15" class="attached enabled">15</option>
<option value="15.5" class="attached enabled">15.5</option>
<option value="16" class="attached enabled">16</option>
</select>
そして、これはとHTMLですラジオ入力:あなたが見ることができるように
<ul class="product-size">
<li class="size">
<div>
<input style="display:none" type="radio" data-attribute-name="attribute_size" name="attribute_size" value="15" id="size_v_15">
<label for="size_v_15">15</label>
</div>
</li>
<li class="size">
<div>
<input style="display:none" type="radio" data-attribute-name="attribute_size" name="attribute_size" value="15.5" id="size_v_15.5" checked="checked">
<label for="size_v_15.5">15.5</label>
</div>
</li>
<li class="size">
<div>
<input style="display:none" type="radio" data-attribute-name="attribute_size" name="attribute_size" value="16" id="size_v_16">
<label for="size_v_16">16</label>
</div>
</li>
</ul>
、name
とvalue
の両方が、これらの2つのバージョンが同じです。しかし、私は上記のエラーを取得します。あなたは、私がvariable.php
ファイルに変更コードを必要とする場合には、ここにある:
<?php
function print_attribute_radio($checked_value, $value, $label, $name)
{
$checked = sanitize_title($checked_value) === $checked_value ? checked($checked_value, sanitize_title($value) , false) : checked($checked_value, $value, false);
$input_name = 'attribute_' . esc_attr($name);
$esc_value = esc_attr($value);
$id = esc_attr($name . '_v_' . $value);
$filtered_label = apply_filters('woocommerce_variation_option_name', $label);
printf('<div><input style="display:none" type="radio" data-attribute-name="%1$s" name="%1$s" value="%2$s" id="%3$s" %4$s><label for="%3$s">%5$s</label></div>', $input_name, $esc_value, $id, $checked, $filtered_label);
}
if (sanitize_title($attribute_name) == 'size'):
$sanitized_name = sanitize_title($attribute_name);
if (isset($_REQUEST['attribute_' . $sanitized_name])) {
$checked_value = $_REQUEST['attribute_' . $sanitized_name];
}
elseif (isset($selected_attributes[$sanitized_name])) {
$checked_value = $selected_attributes[$sanitized_name];
}
else {
$checked_value = '';
}
?>
<h3>Choose Your Size</h3>
<ul class="product-size">
<?php
foreach($options as $option) {
echo '<li class="size">';
print_attribute_radio($checked_value, $option, $option, $sanitized_name);
echo '</li>';
} ?>
</ul>
<script type="text/javascript">
jQuery('.product-size > li').click(function(e) {
jQuery('.product-size > li').removeClass('size-selected');
jQuery(this).addClass('size-selected');
var option_id = jQuery(this).find("input").attr("checked",true);
});
</script>
<?php endif; ?>
2つの属性があるため、ラジオボタンにvariation_idを追加できません。 – Tasos
私は自分の答えを編集しました。私は何度もstandart woocoomerce select変数をradio、colorbox、またはtextだけ異なるプロパティで置き換えています。あなたがここで見つけることができるexemplesの1つhttp://forgeofsvan.com/product/bevor-xv-century/もしあなたがそれのより多くのコードを必要とするなら、私にあなたにそれを与えることができることを教えてください。 –