• Resolved sietssoo

    (@sietssoo)


    Hi there, I added the following code as a snippet. This code adds an extra check out field in the woocommerce check out page, which requires the buyers discord username. Is it possible to add the discord username field in the webhook?

    add_action('woocommerce_before_checkout_billing_form','add_discord_field');
    add_action( 'woocommerce_checkout_update_order_meta', 'discord_save_what_we_added' );
    add_action('woocommerce_checkout_process', 'discord_check_if_filled');
    
    function add_discord_field( $checkout ){
    	woocommerce_form_field( 'discord_field', array(
    		'type'          => 'text',
    		'required'		=> true,
    		'class'         => array('discord-field', 'form-row-wide'),
    		'placeholder'	=> 'vb. Verrekijker#9909',
    		'label'         => 'Discord gebruikersnaam',
    		'label_class'   => 'discord-label'), 
    						   $checkout->get_value( 'discord_field' ) );
    }
    function discord_save_what_we_added( $order_id ){
    	if( !empty( $_POST['discord_field'] ) )
    		update_post_meta( $order_id, 'discord_field', sanitize_text_field( $_POST['discord_field'] ) );
    }
    function discord_check_if_filled() {
    	if ( empty( $_POST['discord_field'] ) )
    		wc_add_notice( 'Vul alstublieft uw discord gebruikersnaam. Geen discord? Vul dan in: GEEN', 'error' );
    }

    Hope somebody can help me.

  • The topic ‘Extra woocommerce field’ is closed to new replies.