Documentation

WordPress: Multi-Product Embed

Dynamically display the correct 3D model on each of your WooCommerce product pages using this step-by-step guide.

Step 1: Set Up Products in Dezyn3D

First, link your WooCommerce products to 3D models in Dezyn3D.

  1. Go to your Products & Inventory page.
  2. Add your products. The Product ID you use in Dezyn3D must match your WooCommerce Product ID or SKU.
  3. 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.

  1. In your WordPress admin dashboard, go to Appearance > Theme File Editor.
  2. From the "Select theme to edit" dropdown, choose your child theme.
  3. Select the functions.php file from the list on the right.
  4. Copy the PHP code snippet below and paste it at the end of the file.
  5. Replace "REPLACE_WITH_YOUR_USER_ID" with your actual User ID from the Dezyn3D Products & Inventory page.
  6. (Optional) If you use SKUs instead of IDs, change $product->get_id() to $product->get_sku() in the code.
  7. 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
}