add_action( 'woocommerce_product_options_lottery', 'custom_woocommerce_product_options_lottery', 20);
function custom_woocommerce_product_options_lottery(){
woocommerce_wp_textarea_input(
array(
'id' => '_lottery_custom_ticket_names',
'wrapper_class' => '',
'description' => __( 'Enter ticket names separated with ","', 'wc-lottery-pn' ),
'label' => __( 'Ticket names', 'wc_lottery' ),
'desc_tip' => 'false',
)
);
}
add_action( 'lottery_product_save_data' , 'custom_lottery_product_save_data' , 10, 2 );
function custom_lottery_product_save_data( $post_id, $post ){
if ( isset( $_POST['_lottery_custom_ticket_names'] ) && ! empty( $_POST['_lottery_custom_ticket_names'] ) ) {
update_post_meta( $post_id, '_lottery_custom_ticket_names', $_POST['_lottery_custom_ticket_names'] );
} else {
delete_post_meta( $post_id, '_lottery_custom_ticket_names' );
}
}
add_filter( 'change_ticket_numbers_to_alphabet', 'custom_ticket_number_display_html', 1, 3);
function custom_ticket_number_display_html( $ticket_number, $_ticket_number, $product ){
$lottery_custom_ticket_names = get_post_meta( $product->get_id(), '_lottery_custom_ticket_names', true );
$names_array = explode(',', $lottery_custom_ticket_names);
if ( isset( $names_array[ intval($_ticket_number ) -1 ] ) ){
return trim( $names_array[ intval($_ticket_number ) -1 ] );
}
return $ticket_number;
}
Comments