Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Wackes

    (@wackes)

    Hi Ewout

    Yes, I want is to show my custom product field per product on the packing slip: My custom field

    And this is the field I want to add to the packing slip per product:
    my custom product field

    Can you advice me on the correct code for this? Thanks in advance =)

    Thread Starter Wackes

    (@wackes)

    HI Ewout

    Thanks for your reply!

    I have added your code, but cant get the values from my custom field to show on the packingslip.

    This is what I have in funitions.php

    //Warhouse location 
    
    		// Display Fields
    		add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
    
    		// Save Fields
    		add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
    
    		function woo_add_custom_general_fields() {
    
    		  global $woocommerce, $post;
    
    		  echo '<div class="options_group">';
    
    		  // Custom fields will be created here...
    
    		  // Text Field
    		woocommerce_wp_text_input(
    			array(
    				'id'          => '_warehouse_location',
    				'label'       => __( 'Lagerplats', 'woocommerce' ),
    				'placeholder' => 'Lagerplats',
    				'desc_tip'    => 'true',
    				'description' => __( 'Fyll i lagerplats', 'woocommerce' )
    			)
    		);
    
    		  echo '</div>';
    
    		}
    
    		function woo_add_custom_general_fields_save( $post_id ){
    
    			// Text Field
    			$woocommerce_warehouse_location = $_POST['_warehouse_location'];
    			if( !empty( $woocommerce_warehouse_location ) )
    				update_post_meta( $post_id, '_warehouse_location', esc_attr( $woocommerce_warehouse_location ) );
    		}
    
    //Warehouse location ends here

    And this is what I added to packing-slip.php:

    <table class="order-details">
    	<thead>
    		<tr>
    			<th class="product-label"><?php _e('Product', 'wpo_wcpdf'); ?></th>
    			<th class="quantity-label"><?php _e('Quantity', 'wpo_wcpdf'); ?></th>
    			<th class="quantity-label"><?php _e('Warehouse location', 'wpo_wcpdf'); ?></th>
    		</tr>
    	</thead>
    	<tbody>
    		<?php $items = $wpo_wcpdf->get_order_items(); if( sizeof( $items ) > 0 ) : foreach( $items as $item ) : ?><tr>
    			<td class="description">
    				<span class="item-name"><?php echo $item['name']; ?></span><span class="item-meta"><?php echo $item['meta']; ?></span>
    				<dl class="meta">
    					<?php if( !empty( $item['sku'] ) ) : ?><dt><?php _e( 'SKU:', 'wpo_wcpdf' ); ?></dt><dd><?php echo $item['sku']; ?></dd><?php endif; ?>
    					<?php if( !empty( $item['weight'] ) ) : ?><dt><?php _e( 'Weight:', 'wpo_wcpdf' ); ?></dt><dd><?php echo $item['weight']; ?><?php echo get_option('woocommerce_weight_unit'); ?></dd><?php endif; ?>
    				</dl>
    			</td>
    			<td class="quantity"><?php echo $item['quantity']; ?></td>
    			<td> <?php echo 'Warehouse location: ' . get_post_meta($wpo_wcpdf->export->order->id,'_warehouse_location',true); ?></td>
    		</tr><?php endforeach; endif; ?>
    	</tbody>
    </table><!-- order-details -->
Viewing 2 replies - 1 through 2 (of 2 total)