Hallo Liebe Mietglieder,
brauche dringend Ihre Hilfe...
Ich möchte eine bzw. zweiter neue Felder im Checkout (Woocemerce) einfügen..
Eigentleich eine einleitung habe ich bereits gefunden aber die ist etwas älter und funktioniert nicht zur 100 %
Folgenceshabe ich hinzugefügt in funkctions.php
-----
/**
* Add the field to the checkout 1 + 2
**/
add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
echo '<div id="my_custom_checkout_field"><h3>'.__('Titel Text').'</h3>';
woocommerce_form_field( 'THIS_IS_FIELD_1', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('Label Text 1 <abbr class="required" title="required">*</abbr>'),
'placeholder' => __('Placeholder Text 1'),
), $checkout->get_value( 'THIS_IS_FIELD_1' ));
woocommerce_form_field( 'THIS_IS_FIELD_2', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('Label Text 2 <abbr class="required" title="required">*</abbr>'),
'placeholder' => __('Placeholder Text 2'),
), $checkout->get_value( 'THIS_IS_FIELD_2' ));
echo '</div>';
}
/**
* Process the checkout 1 + 2
**/
add_action('woocommerce_checkout_process', 'THIS_IS_FIELD_1_PROCESS');
function THIS_IS_FIELD_1_PROCESS() {
global $woocommerce;
// Check if set, if its not set add an error.
if (!$_POST['THIS_IS_FIELD_1'])
$woocommerce->add_error( __('<b>Veranstaltungsort</b> darf nicht leer sein.') );
}
add_action('woocommerce_checkout_process', 'THIS_IS_FIELD_2_PROCESS');
function THIS_IS_FIELD_2_PROCESS() {
global $woocommerce;
if (!$_POST['THIS_IS_FIELD_2'])
$woocommerce->add_error( __('<b>Veranstaltungsdatum</b> darf nicht leer sein.') );
}
/**
* Update the order meta with field value 1 + 2
**/
add_action('woocommerce_checkout_update_order_meta', 'THIS_IS_FIELD_1_UPDATE');
function THIS_IS_FIELD_1_UPDATE( $order_id ) {
if ($_POST['THIS_IS_FIELD_1']) update_post_meta( $order_id, 'Veranstaltungsort', esc_attr($_POST['THIS_IS_FIELD_1']));
}
add_action('woocommerce_checkout_update_order_meta', 'THIS_IS_FIELD_2_UPDATE');
function THIS_IS_FIELD_2_UPDATE( $order_id ) {
if ($_POST['THIS_IS_FIELD_2']) update_post_meta( $order_id, 'Veranstaltungsdatum', esc_attr($_POST['THIS_IS_FIELD_2']));
}
/**
* Add the field to order emails 1 + 2
**/
add_filter('woocommerce_email_order_meta_keys', 'THIS_IS_FIELD_1_EMAIL');
function webpresentatie_titel_order_meta_keys( $keys ) {
$keys[] = 'Field 1 Text';
return $keys;
}
add_filter('woocommerce_email_order_meta_keys', 'THIS_IS_FIELD_2_EMAIL');
function webpresentatie_subtitel_order_meta_keys( $keys ) {
$keys[] = 'Field 2 Text';
return $keys;
}
Alles anzeigen
---
Im Checkout sindn nun die Felder da und wenn man die ausfüllt erscheinen die auch im Backend
Nun folgendes Prblem:
[COLOR=#ff0000]1. Wenn man die Felde nicht ausfüllt sollte ja Fehlermeldung kommen aber ich bekomme folgendes:
[/COLOR]Fatal error: Call to undefined method WooCommerce::add_error() in /var/www/vhosts/*****/httpdocs/wp-content/themes/responsive/functions.php on line 81
-> Line 81 ist die: $woocommerce->add_error( __('<b>Veranstaltungsort</b> darf nicht leer sein.') );
[COLOR=#ff0000]2. Felder sollten auch in der Bestell Email erschein da bekomme ich aber folgende Fehler in der Email:[/COLOR]
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'THIS_IS_FIELD_1_EMAIL' not found or invalid function name in /var/www/vhosts/*******/httpdocs/wp-includes/plugin.php on line 235
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'THIS_IS_FIELD_2_EMAIL' not found or invalid function name in /var/www/vhosts/********/httpdocs/wp-includes/plugin.php on line 235
----
Bite um Hilfe.