Hallo,
Ich habe versucht nach den Angaben der Seite https://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/ eigene Felder zu erstellen.
Diese erscheinen auch auf der Seite checkout. Wenn ich sie allerdings ausfülle werden die Eingaben nicht ausgegeben, bzw erscheinen nicht auf der order-received Seite.
Zu berücksichtigen hierbei ist, dass ich das German Market Plugin benutze und da ja noch eine Seite vorangestellt ist (bestellung_pruefen_bezahlen). Auch auf dieser Seite erscheint nichts von dem, was ich eingegeben habe. Ich benutze Woocommerce 2.4.7 und die aktuellste Version von Wordpress. Eventuell auch noch wichtig: Ich habe den Tabellenpräfix geändert - also nicht wp_
Hier ist mein Code:
/**
* Add the field to the checkout
*/
add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );
function my_custom_checkout_field( $checkout ) {
echo '<div id="my_custom_checkout_field"><h2>' . __('My Field') . '</h2>';
woocommerce_form_field( 'my_field_name', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('Fill in this field'),
'placeholder' => __('Enter something'),
), $checkout->get_value( 'my_field_name' ));
echo '</div>';
}
/**
* Process the checkout
*/
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
function my_custom_checkout_field_process() {
// Check if set, if its not set add an error.
if ( ! $_POST['my_field_name'] )
wc_add_notice( __( 'Please enter something into this new shiny field.' ), 'error' );
}
/**
* Update the order meta with field value
*/
add_action( 'woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta' );
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ( ! empty( $_POST['my_field_name'] ) ) {
update_post_meta( $order_id, 'My Field', sanitize_text_field( $_POST['my_field_name'] ) );
}
}
/**
* Display field value on the order edit page
*/
add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order){
echo '<p><strong>'.__('My Field').':</strong> ' . get_post_meta( $order->id, 'My Field', true ) . '</p>';
}
Alles anzeigen
Für jede Hilfe dankbar
Mxmanuel