Estoy tratando de agregar un nuevo campo en la restricción de uso de cupones.
Aquí está mi código:
function add_coupon_cpt_field() {
$value = get_post_meta( $post->ID, '_select', true );
if( empty( $value ) ) $value="";
$my_c_posts = get_posts( array(
'posts_per_page' => -1,
'orderby'=> 'date',
'order'=> 'DESC',
'post_type'=> 'tour',
'post_status'=> 'publish',
) );
$options[''] = __( 'Select a value', 'woocommerce'); // default value
foreach ($my_c_posts as $key => $post)
$options[$key] = $post->post_title;
echo '<div class="options_group">';
woocommerce_wp_select( array(
'id' => '_select',
'label' => __( 'Select Tour', 'woocommerce' ),
'options' => $options,
'value' => $value,
) );
echo '</div>';
}
add_action( 'woocommerce_coupon_options_usage_restriction', 'add_coupon_cpt_field', 10, 0 );
// Save Fields
add_action( 'woocommerce_coupon_options_save', 'custom_posts_fields_save' );
function custom_posts_fields_save( $post_id ){
$woocommerce_select = $_POST['_select'];
if( !empty( $woocommerce_select ) )
update_post_meta( $post_id, '_select', esc_attr( $woocommerce_select ) );
else {
update_post_meta( $post_id, '_select', '' );
}
}
Los títulos se muestran, pero cuando guardo el cupón, la selección no se guarda. ¿Algún consejo?