我为woocommerce WordPress中的产品创建了一些复选框选项,并且我已经点击了200多个具有相同复选框的产品。我想将“默认情况”全部选中,但也需要如果我想取消选中任何一个,则需要另存为未选中。
代码:
function woocom_general_product_data_custom_field() {
global $post;
$roomforone = get_post_meta($post->ID,"roomforone",true);
$roomforfour = get_post_meta($post->ID,"roomforfour",true);
?>
<div class="all-fields">
<div class="inner">
<label for="roomforone" class="room1">Suitable for shipping in Vienna:
</label>
<input type="checkbox" name="roomforone" id="roomforone" value="yes"
echo <?php if($roomforone=='yes'){echo "checked='checked'";} else { echo
"";} ?>/><br />
</div>
<div class="inner">
<label for="roomforfour" class="room4">Suitable for shipping in Austria:
</label>
<input type="checkbox" name="roomforfour" id="roomforfour" value="yes"
echo <?php if($roomforfour=='yes'){echo "checked='checked'";} else { echo "";} ?>/><br />
</div>
</div>
function woocom_save_general_proddata_custom_field( $post_id ) {
$roomforone = "no";
if(isset($_POST["roomforone"]))
{
$roomforone = $_POST["roomforone"];
}
update_post_meta( $post_id, 'roomforone', $roomforone );
$roomforfour = "no";
if(isset($_POST["roomforfour"]))
{
$roomforfour = $_POST["roomforfour"];
}
update_post_meta( $post_id, 'roomforfour', $roomforfour );
}