1. Home
  2. WC Vendors Pro
  3. Code Snippets
  4. Add Tax ID to Shipping Label

Add Tax ID to Shipping Label

WC Vendors Pro includes a shipping label that has two sections. The top section is the shipping label that can be cut off and attached to the outside of the package. While the second half of the label is very close to an invoice that can be included with shipping.

With a couple of adjustments to the store settings page fields and an updated shipping label template, you can get a nice looking Tax Invoice for your vendors to include in their shipments.

Add Tax ID field to the store settings page. You will need to use the following code snippet to add this to your vendor store setting page. This as with all code snippets will go in your themes functions.php.

 <?php 
/**	
 * Add the Tax ID Field to the settings page 
 * 
 * In this example we are using ABN/ACN for Australian GST Invoices
 * You can update this tax label to whatever suits your requirements. 
 */
add_action( 'wcvendors_settings_before_company_url', 'wcv_add_tax_field' ); 
function wcv_add_tax_field(){ 
	$key = 'wcv_custom_settings_tax_id'; 
	$value = get_user_meta( get_current_user_id(), $key, true );
	WCVendors_Pro_Form_Helper::input(
		apply_filters(
			'wcv_vendor_tax_id',
			array(
				'id'                => $key,
				'label'             => __( 'ABN/ACN', 'wcvendors-pro' ),
				'placeholder'       => __( '00 000 000 000', 'wcvendors-pro' ),
				'desc_tip'          => 'true',
				'description'       => __( 'Your ABN/ACN', 'wcvendors-pro' ),
				'type'              => 'text',
				'value'				=> $value,
			)
		)
	);
}

The second half of this process will require that you override the shipping label template that ships with WC Vendors Pro. The filename for this template is called shipping-label.php and is located in wc-vendors-pro/templates/dashboard/order/shipping-label.php.

Place the following file in your theme’s template override directory. For example, if your theme is called ‘wc-vendors-test‘ this template will go in wp-content/themes/wc-vendors-test/wc-vendors/dashboard/order/.

<?php
/**
 * The template for displaying the shipping label
 *
 * Override this template by copying it to yourtheme/wc-vendors/dashboard/order
 *
 * @package    WCVendors_Pro
 * @version    1.7.5
 * @since      1.0.4
 *
 * The following variables are available in this template
 *
 *  $order
 *  $store_name
 *  $store_address1
 *  $store_address2
 *  $store_city
 *  $store_state
 *  $store_country
 *  $store_postcode
 *  $products
 */
$tax_id = get_user_meta( get_current_user_id(), 'wcv_custom_settings_tax_id', true );
?>

<html>
<head>
	<title></title>
	<style type="text/css">
		body {
			padding: 2em 3em;
			font-family: arial,sans-serif;
			line-height: 1.48;
			font-size: 14px;
			max-width: 21cm;
		}
		.row {
			display: flex;
			justify-content: space-between;
		}
		.row > * {
			flex-shrink: 0;
			flex-grow: 0;
		}
		.row > *:nth-child(2) {
			width: 40%;
		}
		#shipping-label {
			text-transform: uppercase;
			border-bottom: 2px dashed #aaa;
			margin-bottom: 2em;
			padding-bottom: 2em;
		}
		#shipping-label .customer {
			font-size: 18px;
		}
		#shipping-label .vendor {
			text-align: right;
			font-size: 12px;
		}
		#vendor-info {
			margin-bottom: 2em;
		}
		#customer-info {
			margin-bottom: 2em;
		}
		.tax-id { 
			width: 100%;
			line-height: 12px;
			margin-bottom: 2em;
		}
		.vendor-logo {
			font-weight: bold;
			text-transform: uppercase;
			font-size: 3em;
		}
		.vendor-logo img {
			max-height: 120px;
			width: auto;
		}
		address {
			font-style: normal;
		}
		h3 {
			text-transform: uppercase;
			margin: 0;
		}
		table {
			border-collapse: collapse;
			font-size: 14px;
			width: 100%;
		}
		td, th {
			border-width: 1px 0;
			border-style: solid;
			border-color: #aaa;
			padding: 5px 10px;
		}
		table thead {
			background: #222;
			color: #fff;
		}
		table .product {
			width: 80%;
			text-align: left;
		}
		table .quantity {
			width: 20%;
			text-align: center;
		}
	</style>
</head>
<body>
	<div id="shipping-label">
		<div class="row">
			<address class="customer">
				<h3><?php _e( 'Ship to:', 'wcvendors-pro' ); ?></h3>
				<?php echo $ship_to; ?>
			</address>
			<address class="vendor">
				<?php echo $store_name; ?><br/>
				<?php echo $ship_from; ?>
			</address>
		</div>
	</div>

	<div id="vendor-info">
		<?php if ( ! empty( $tax_id ) ) : ?>
		<div class="row">
		<div></div>
		<div class="tax-id">
			<h1>TAX INVOICE</h1>
			<strong>ABN/ACN: <?php echo $tax_id; ?></strong><br />
			</div>
		</div>
		<?php endif; ?>
		<div class="row">
			<div class="vendor-logo">
				<?php echo $store_icon ? $store_icon : $store_name; ?>
			</div>
			<address>
            	<strong><?php echo $store_name; ?></strong><br/>
				<?php echo $ship_from; ?>
			</address>
		</div>
	</div>

	<div id="customer-info">
		<div class="row">
			<address>
				<?php echo $ship_to; ?>
			</address>
			<div class="order-details">
				<?php echo __( 'Order number:', 'wcvendors-pro' ); ?> <?php echo $order->get_order_number(); ?></br>
				<?php echo __( 'Order date:', 'wcvendors-pro' ); ?> <?php echo $order->get_date_created()->format( 'F j, Y' ); ?>
			</div>
		</div>
	</div>

	<table id="picking-list">
		<thead>
			<tr>
				<th class="product"><?php echo __( 'Product', 'wcvendors-pro' ); ?></th>
				<th class="quantity"><?php echo __( 'Quantity', 'wcvendors-pro' ); ?></th>
			</tr>
		</thead>
		<tbody>
			<?php foreach ( $products as $product ) : ?>
				<tr>
					<td class="product"><?php echo $product['name']; ?></td>
					<td class="quantity"><?php echo $product['quantity']; ?></td>
				</tr>
			<?php endforeach; ?>
		</tbody>
	</table>

</body>
</html>

Vendors will now have a shipping label that looks like this. You can update the wording in the template above to suit your particular tax jurisdiction.

actions

Updated on March 20, 2021

Was this article helpful?