How can we help? 👋

Vehicle Application Table

Display a handy table that lists a product’s vehicle fitment applications.

Use the following PHP code snippet on your WooCommerce product page to display a table of vehicle fitment applications. This table uses the vehicle fitment metadata synced to your store via Partbot.

global $product;
echo '<h2>Vehicles</h2>';

if( $product->is_type( 'variable' ) ) {
	foreach ( $product->get_available_variations() as $variation) {
		$vehicle_applications = json_decode(get_post_meta($variation['variation_id'], 'partbot.vehicle_applications', true));
		foreach ( $vehicle_applications as $vehicle_application ) {
			echo "<h3>{$vehicle_application->title}</h3>";
			echo "<table class='pb_vehicles'>";
			echo "<tr><th>MAKE</th><th>MODEL</th><th>FROM</th><th>TO</th><th>BODY</th><th>SERIES</th><th>ENGINE</th><th>VARIANT</th><th>DRIVETRAIN</th></tr>";
			foreach ($vehicle_application->vehicles as $vehicle) {
				echo "<tr>";
				echo "<td>{$vehicle->make}</td>";
				echo "<td>{$vehicle->model}</td>";
				echo "<td>{$vehicle->from}</td>";
				echo "<td>{$vehicle->to}</td>";
				echo "<td>{$vehicle->body}</td>";
				echo "<td>{$vehicle->series}</td>";
				echo "<td>{$vehicle->engine}</td>";
				echo "<td>{$vehicle->variant}</td>";
				echo "<td>{$vehicle->drivetrain}</td>";
				echo "</tr>";
			}
			echo "</table>";
		}
	}
} else {
	$vehicle_applications = json_decode(get_post_meta($product->id, 'partbot.vehicle_applications', true));
	foreach ( $vehicle_applications as $vehicle_application ) {
		echo "<h3>{$vehicle_application->title}</h3>";
		echo "<div class='pb_vehicles_container'>";
		echo "<table class='pb_vehicles'>";
		echo "<tr><th>MAKE</th><th>MODEL</th><th>FROM</th><th>TO</th><th>BODY</th><th>SERIES</th><th>ENGINE</th><th>VARIANT</th><th>DRIVETRAIN</th></tr>";
		foreach ($vehicle_application->vehicles as $vehicle) {
			echo "<tr>";
			echo "<td>{$vehicle->make}</td>";
			echo "<td>{$vehicle->model}</td>";
			echo "<td>{$vehicle->from}</td>";
			echo "<td>{$vehicle->to}</td>";
			echo "<td>{$vehicle->body}</td>";
			echo "<td>{$vehicle->series}</td>";
			echo "<td>{$vehicle->engine}</td>";
			echo "<td>{$vehicle->variant}</td>";
			echo "<td>{$vehicle->drivetrain}</td>";
			echo "</tr>";
		}
		echo "</table>";
		echo "</div>";
	}
}
 
💡
Don’t forget to style the table to match your website theme!
 
Did this answer your question?
😞
😐
🤩