Open AliMD opened 12 years ago
:imp:
@AliMD Ba ejaze saheb khune @zohreh-z men ye soal beporsam age bekhaym dropdown bezarim chtori mishe ? man kode ziro minevisam vali save nemishe:
<?php
add_action('add_meta_boxes','add_my_meta');
add_action('save_post','save_my_meta');
function add_my_meta(){
add_meta_box('my_meta', 'ویژگی های منحصربفرد محصول','my_inner_meta_box','products','advanced','default');
}
function my_inner_meta_box($post){
wp_nonce_field(plugin_basename(__FILE__), 'wpnonce');
$post_id=$post->ID;
$price=get_post_meta($post_id,'price',true);
$off=get_post_meta($post_id,'off',true);
$offtype=get_post_meta($post_id,'offtype',true);
?>
<label for="meta_price">قیمت:</label>
<input type="text" name="meta_price" value="<?php echo "$price"; ?>" >
<label for="meta_off">تخفیف:</label>
<input type="text" name="meta_off" value="<?php echo "$off"; ?>" >
<label for="meta_offtype">نوع تخفیف:</label>
<select name="meta_offtype">
<option value="<?php echo"$offtype"; ?>">درصد</option>
<option value="<?php echo"$offtype"; ?>">ریال</option>
</select>
<?php
}
function save_my_meta($post_id){
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
if(!wp_nonce_field(plugin_basename(__FILE__), 'wpnonce'))
return;
if('products'==$_POST['post_type'])
{
if ( is_admin() ){
$price=$_POST['meta_price'];
update_post_meta($post_id,'price',$price);
$off=$_POST['meta_off'];
update_post_meta($post_id,'off',$off);
$offtype=$_POST['meta_offtype'];
update_post_meta($post_id,'offtype',$offtype);
}
}
else
return;
}
?>
baghie ro save va update mikone ama offtype (نوع تخفیف) ro save nemikone
pishnahad mikonam tag sellect ro too w3schools dobare bekhoon :trollface: value option ha chera yeki yan !!! to bayad ooni ke az meta mikhooni ro selected koni na value sho avaz koni
be tamame input ha va select ha alave bar name id ham bede (html5)
@mahlad :+1: nagofatm value selectet moshkel dare w3schools ro chek kon hatman mr alimd bayad bege........ :trollface:
jedi nagoftii khob...!!!
nashr akazib bar khalafe mavazin sharist, hazrat ali.md (ع)
mesle maaaaard dare kar mikone.