Hallo,
habe leider ein Problem mit einem Custom Field und hoffe, jemand ist so nett und kann mir dabei helfen. :-?
Ziel ist es, ein eigenes Eingabefeld zu haben in dem ich einen Lagerplatz/Ort für meine Produkte eintragen kann und der mir im Bereich einer Bestellung dann auch angezeigt wird. Mit dem folgenden Code ist dies zu 90% erfüllt:
add_action( 'woocommerce_product_options_general_product_data', 'wc_custom_add_custom_fields' );
function wc_custom_add_custom_fields() {
// Gibt ein benutzerdefiniertes Feld im allgemeinen Tab des Produkts aus
woocommerce_wp_text_input( array(
'id' => '_lagerplatz',
'label' => 'Lagerplatz',
'description' => 'Bitte trage hier den Lagerplatz des Artikel ein.',
'desc_tip' => 'true',
'placeholder' => '000-000'
)
);
}
add_action( 'woocommerce_process_product_meta', 'wc_custom_save_custom_fields' );
function wc_custom_save_custom_fields( $post_id ) {
if ( ! empty( $_POST['_lagerplatz'] ) ) {
update_post_meta( $post_id, '_lagerplatz', esc_attr( $_POST['_lagerplatz'] ) );
}
}
// Code damit bei Bestellungen die bestellten Artikel unter Produkte mit angezeigt werden
add_filter( 'manage_edit-shop_order_columns', 'imarcon_set_custom_column_order_columns');
function imarcon_set_custom_column_order_columns($columns) {
// global $woocommerce;
$nieuwearray = array();
foreach($columns as $key => $title) {
if ($key=='billing_address') // in front of the Billing column
$nieuwearray['order_producten'] = __( 'Products', 'woocommerce' );
$nieuwearray[$key] = $title;
}
return $nieuwearray ;
}
add_action( 'manage_shop_order_posts_custom_column' , 'imarcon_custom_shop_order_column', 10, 2 );
function imarcon_custom_shop_order_column( $column ) {
global $post, $woocommerce, $the_order;
switch ( $column ) {
case 'order_producten' :
$terms = $the_order->get_items();
if ( is_array( $terms ) ) {
foreach($terms as $term)
{
echo $term['item_meta']['_qty'][0] .' x ' . $term['name'] .'<br />';
}
} else {
_e( 'Unable get the producten', 'woocommerce' );
}
break;
}
}
Alles anzeigen
Nun fehlt mir jedoch noch der Lagerplatz/Ort den ich gern hier
echo $term['item_meta']['_qty'][0] .' x ' . $term['name'] .'[B] - ' . $term['lagerplatz'] .'[/B]<br />';
mir ausgeben lassen würde.
Ich habe gelesen, dass man dafür die Funktion
get_post_meta( $product_id, ‚_lagerplatz‘, true)
nutzen sollte und im Vorwege die $product_id benötigt. Damit stoße ich jetzt aber an meine Grenzen und hoffe jemand von euch kann mir dabei helfen.
Gruß Frank