Learn how to make integrating WooCommerce into your Divi site easier by enabling dynamic content on product fields in Divi's Woo modules.
Integrating dynamic content for product fields offers numerous benefits. For example, you can:
- Automatically update product prices and descriptions across multiple pages when you update them in WooCommerce.
- Pull specific details from a product database into a Theme Builder template to avoid having to manually update each post.
- Streamline content creation, ensuring consistency and accuracy in product information displayed across your site.
Enable Dynamic Content on Divi Woo Product Fields using PHP
Integrating dynamic content into Divi's WooCommerce modules can streamline your website management and improve its flexibility. By adding a simple PHP code snippet to your child theme's functions.php file or through a plugin like Code Snippets, you can activate this feature. This snippet enables dynamic content on the product picker in supported Woo modules:
// === Enable On Woo Product Pickers ===
class EnableDynamicContentOnWooProductPickers {
private $module_slugs = array(
'et_pb_wc_description',
'et_pb_wc_add_to_cart',
'et_pb_wc_gallery',
'et_pb_wc_images',
'et_pb_wc_additional_info',
'et_pb_wc_breadcrumb',
'et_pb_wc_cart_notice',
'et_pb_wc_meta',
'et_pb_wc_price',
'et_pb_wc_rating',
'et_pb_wc_related_products',
'et_pb_wc_reviews',
'et_pb_wc_stock',
'et_pb_wc_tabs',
'et_pb_wc_title',
'et_pb_wc_upsells'
);
public function __construct() {
foreach ($this->module_slugs as $slug) {
\add_filter('et_pb_all_fields_unprocessed_' . $slug, array($this, 'enable_on_product_field'));
}
\add_filter('wp_footer', array($this, 'dynamic_content_icon_styles'));
}
public function enable_on_product_field($fields) {
if (isset($fields['product']) && is_array($fields['product'])) {
$fields['product']['dynamic_content'] = 'text';
}
return $fields;
}
public function dynamic_content_icon_styles() {
if (is_admin() || !empty($_GET['et_fb'])) {
?>
<style>
/* Reposition the dynamic content icon to avoid covering the select controls */
.et-fb-settings-option-dynamic__button--select_product {
right: 24px !important;
}
/* Enabling dynamic content makes the AI button display, so hide it */
.et-db #et-boc .et-l button.et-fb-settings-option-ai__button--select_product {
display: none;
}
/* Hide / replace the warning message shown when dynamic content is deactivated */
.et-fb-option--select-product .et-fb-option--warning {
visibility: hidden;
height: 0 !important;
overflow: hidden;
margin: 0 !important;
padding: 0 !important;
}
.et-fb-option--select-product:has(.et-fb-option--warning)::after {
content: "Please save these module settings and reopen to restore this setting.";
display: block;
color: #333;
font-size: 13px;
font-weight: 600;
background-color: #f9f9f9;
padding: 10px;
margin-top: 10px;
}
</style>
<?php
}
}
}
new EnableDynamicContentOnWooProductPickers();
The PHP code snippet adds a filter to each module, enabling dynamic content for product fields. It also adds some CSS to better position the dynamic content. Normally, if you set the product to a dynamic content field, but then delete the field again, Divi will display an error box. The CSS in the code above handles this by presenting a more informative instruction that informs the user that simply saving and restarting the module settings will restore the product field.
For the dynamic content feature to work, the custom field you choose from the dynamic content menu should return the appropriate product ID, which is essentially just the WordPress post ID of the product. This ensures the correct product data is dynamically pulled and displayed.
Enabling Dynamic Content on Divi Woo Product Fields using Divi Dynamic Content Extended
This powerful feature will be included in the next release of Divi Dynamic Content Extended, version 1.3. By enabling dynamic content within Divi's WooCommerce modules, you can significantly enhance your website's dynamic display capabilities, ensuring your content is always up-to-date and relevant.
Stay tuned for this update and transform the way you manage product data on your Divi-powered site.
Supported WooCommerce Modules
This feature supports an array of WooCommerce modules, enabling dynamic content across various fields. The supported modules include:
- Woo Product Description
- Woo Add to Cart
- Woo Product Gallery
- Woo Product Images
- Woo Additional Information
- Woo Breadcrumbs
- Woo Cart Notice
- Woo Product Meta
- Woo Product Price
- Woo Product Rating
- Woo Related Products
- Woo Product Reviews
- Woo Product Stock
- Woo Product Tabs
- Woo Product Title
- Woo Upsells
0 Comments