Passen Sie den WooCommerce Admin-Bestellartikel meta an

Mit dem aktuellen Code kann ich das Textfeld hinzufügen, das Ergebnis im Warenkorb und in der Kasse anzeigen.

Bilder: Textcamp im Artikel:

Bildbeschreibung hier eingeben

Wert im Warenkorb:

Bildbeschreibung hier eingeben

Wert in der Kasse:

Bildbeschreibung hier eingeben

Aber ich kann es nicht in den Kaufdetails oder im Administrationsbereich erscheinen lassen.

Bilder: Checkout Details ohne den Wert:

Bildbeschreibung hier eingeben

Verwaltungsaufträge ohne den Wert: Bildbeschreibung hier eingeben

Dies ist der Code, könnte mir jemand sagen, wo der Fehler ist bitte? Ich danke dir sehr.

Der Code, den ich in meiner functions.php Datei verwende:

 // Add the field to the product add_action('woocommerce_before_add_to_cart_button', 'my_custom_checkout_field'); function my_custom_checkout_field() { global $product; $id = $product->get_id(); // Get the field name of InputText1 $InputText1Name = get_post_meta($id, 'InputText1', true); if ((!empty(get_post_meta($id, $InputText1, true)))){ echo '
'; echo ' '; echo '
'; } } // Store custom field function save_my_custom_checkout_field( $cart_item_data, $product_id ) { if( isset( $_REQUEST['$InputText1V'] ) ) { $cart_item_data[ '$InputText1V' ] = $_REQUEST['$InputText1V']; /* below statement make sure every add to cart action as unique line item */ $cart_item_data['unique_key'] = md5( microtime().rand() ); } return $cart_item_data; } add_action( 'woocommerce_add_cart_item_data', 'save_my_custom_checkout_field', 10, 2 ); // Render meta on cart and checkout function render_meta_on_cart_and_checkout( $cart_data, $cart_item = null ){ // Get the product id inside the cart foreach( WC()->cart->get_cart() as $cart_item ){ $product_id = $cart_item['product_id']; } // Get the field name of InputText1 $InputText1Name = get_post_meta($product_id, 'InputText1', true); $custom_items = array(); /* Woo 2.4.2 updates */ if( !empty( $cart_data ) ) { $custom_items = $cart_data; } if( isset( $cart_item['$InputText1V'] ) ) { $custom_items[] = array( "name" => $InputText1Name, "value" => $cart_item['$InputText1V'] ); } return $custom_items; } add_filter( 'woocommerce_get_item_data', 'render_meta_on_cart_and_checkout', 10, 2 ); // Display as order meta function my_field_order_meta_handler( $item_id, $values, $cart_item_key ) { if( isset( $values['$InputText1V'] ) ) { wc_add_order_item_meta( $product_id, "$InputText1V", $values['$InputText1V'] ); } } // 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 ($_POST['$InputText1V']) update_post_meta( $order_id, '$InputText1Name', esc_attr($_POST['$InputText1V'])); } // Update the user meta with field value add_action('woocommerce_checkout_update_user_meta', 'my_custom_checkout_field_update_user_meta'); function my_custom_checkout_field_update_user_meta( $user_id ) { if ($user_id && $_POST['$InputText1V']) update_user_meta( $user_id, '$InputText1V', esc_attr($_POST['$InputText1V']) ); } add_filter( 'woocommerce_hidden_order_itemmeta', 'hide_order_item_meta_fields' ); // 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 ){ $order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id; echo '

'.__($InputText1V).': ' . get_post_meta( $order_id, $InputText1V, true ) . '

'; } function hide_order_item_meta_fields( $fields ) { $fields[] = 'current_view'; $fields[] = 'custom_image';//Add all meta keys to this array,so that it will not be displayed in order meta box return $fields; } add_action( 'woocommerce_after_order_itemmeta', 'order_meta_customized_display',10, 3 ); function order_meta_customized_display( $item_id, $item, $product ){ $order_product_id = $item['product_id']; $field1name = get_post_meta($order_product_id, 'InputText1', true); echo'
'; print_r($InputText1V); echo'
'; echo $field1name; echo ': '; }

Solutions Collecting From Web of "Passen Sie den WooCommerce Admin-Bestellartikel meta an"