WordPress: Multi-Product Embed
Dynamically display the correct 3D model on each of your WooCommerce product pages using this step-by-step guide.
Developer Recommended
This guide requires editing your theme's code. We strongly recommend using a child theme to avoid losing your changes when you update your main theme. If you're not comfortable with this, please consult a web developer.
Step 1: Set Up Products in Dezyn3D
First, link your WooCommerce products to 3D models in Dezyn3D.
- Go to your Products & Inventory page.
- Add your products. The Product ID you use in Dezyn3D must match your WooCommerce Product ID or SKU.
- Link a 3D model to each product in the inventory list.
Step 2: Add Code to Your Theme
This code snippet needs to be added to your child theme's functions.php file.
- In your WordPress admin dashboard, go to Appearance > Theme File Editor.
- From the "Select theme to edit" dropdown, choose your child theme.
- Select the
functions.phpfile from the list on the right. - Copy the PHP code snippet below and paste it at the end of the file.
- Replace "REPLACE_WITH_YOUR_USER_ID" with your actual User ID from the Dezyn3D Products & Inventory page.
- (Optional) If you use SKUs instead of IDs, change
$product->get_id()to$product->get_sku()in the code. - Click Update File to save your changes. The 3D model will now automatically appear on product pages that have one linked.
Code Snippet
add_action( 'woocommerce_after_single_product_summary', 'dezyn3d_display_model', 15 );
function dezyn3d_display_model() {
global $product;
if ( ! is_product() ) {
return;
}
$product_id = $product->get_id();
// Or use SKU: $product_id = $product->get_sku();
// IMPORTANT: Replace with your actual User ID from Dezyn3D
$your_user_id = "REPLACE_WITH_YOUR_USER_ID";
// Construct the embed URL
$embed_url = "https://embed.dezyn.app/v1?uid=" . $your_user_id . "&product_id=" . $product_id;
?>
<div class="dezyn3d-model-container" style="width: 100%; height: 600px; margin: 2rem 0;">
<iframe
src="<?php echo esc_url( $embed_url ); ?>"
width="100%"
height="100%"
frameborder="0"
title="<?php echo esc_attr( $product->get_name() ); ?> 3D Model"
loading="lazy">
</iframe>
</div>
<?php
}