tag to keep the paragraph sanity. * - runs other shortcodes if any using do_shortcode. * * @since 4.4.1 * * @param string $description Product description i.e. Post content. * * @return string */ function et_builder_wc_parse_description( $description ) { if ( ! is_string( $description ) ) { return $description; } global $wp_embed; $parsed_description = et_strip_shortcodes( $description ); $parsed_description = $wp_embed->run_shortcode( $parsed_description ); $parsed_description = do_shortcode( $parsed_description ); $parsed_description = wpautop( $parsed_description ); return $parsed_description; } /** * Deletes ET_BUILDER_WC_PRODUCT_PAGE_CONTENT_STATUS_META_KEY when Builder is OFF. * * The deletion allows switching between Divi Builder and the GB builder smoothly. * * @link https://github.com/elegantthemes/Divi/issues/22477 * * @since 4.14.0 * * @param WP_Post $post Post Object. */ function et_builder_wc_delete_post_meta( $post ) { if ( ! ( $post instanceof WP_Post ) ) { return; } if ( et_pb_is_pagebuilder_used( $post->ID ) ) { return; } delete_post_meta( $post->ID, ET_BUILDER_WC_PRODUCT_PAGE_CONTENT_STATUS_META_KEY ); } /** * Adds the Preview class to the wrapper. * * @param string $maybe_class_string Classnames string. * @return string */ function et_builder_wc_add_preview_wrap_class( $maybe_class_string ) { if ( ! is_string( $maybe_class_string ) ) { return $maybe_class_string; } $classes = explode( ' ', $maybe_class_string ); $classes[] = 'product'; return implode( ' ', $classes ); } /** * Entry point for the woocommerce-modules.php file. * * @since 3.29 */ function et_builder_wc_init() { // global $post won't be available with `after_setup_theme` hook and hence `wp` hook is used. add_action( 'wp', 'et_builder_wc_override_default_layout' ); // Add WooCommerce class names on non-`product` CPT which uses builder. add_filter( 'body_class', 'et_builder_wc_add_body_class' ); add_filter( 'et_builder_inner_content_class', 'et_builder_wc_add_inner_content_class' ); add_filter( 'et_pb_preview_wrap_class', 'et_builder_wc_add_preview_wrap_class' ); add_filter( 'et_builder_outer_content_class', 'et_builder_wc_add_outer_content_class' ); // Load WooCommerce related scripts. add_action( 'wp_enqueue_scripts', 'et_builder_wc_load_scripts', 15 ); add_filter( 'et_builder_skip_content_activation', 'et_builder_wc_skip_initial_content', 10, 2 ); // Show Product Content dropdown settings under // Divi Theme Options ⟶ Builder ⟶ Post TYpe Integration. add_filter( 'et_builder_settings_definitions', 'et_builder_wc_add_settings' ); /** * Adds the metabox only to Product post type. * * This is achieved using the post type hook - add_meta_boxes_{post_type}. * * @see https://codex.wordpress.org/Plugin_API/Action_Reference/add_meta_boxes * * @since 3.29 */ add_action( 'add_meta_boxes_product', 'et_builder_wc_long_description_metabox_register' ); // Saves the long description metabox data. // Since `et_pb_metabox_settings_save_details()` already uses `save_post` hook // to save `_et_pb_old_content` post meta, // we use this additional hook `et_pb_old_content_updated`. add_action( 'et_pb_old_content_updated', 'et_builder_wc_long_description_metabox_save', 10, 3 ); /* * 01. Sets the initial Content when `Use Divi Builder` button is clicked * in the Admin dashboard. * 02. Sets the initial Content when `Enable Visual Builder` is clicked. */ add_filter( 'et_fb_load_raw_post_content', 'et_builder_wc_set_prefilled_page_content', 10, 2 ); add_action( 'et_save_post', 'et_builder_set_product_page_layout_meta' ); /* * Set the Product modified status as modified upon save to make sure default layout is not * loaded more than one time. * * @see https://github.com/elegantthemes/Divi/issues/16420 */ add_action( 'et_update_post', 'et_builder_wc_set_page_content_status' ); /* * Handle get Woocommerce tabs AJAX call initiated by Tabs checkbox in settings modal. */ add_action( 'wp_ajax_et_builder_get_woocommerce_tabs', 'et_builder_get_woocommerce_tabs' ); /* * Fix Woo Extra Product Options addon compatibility. * @see https://github.com/elegantthemes/Divi/issues/17909 */ add_filter( 'thwepof_hook_name_before_single_product', 'et_builder_trigger_extra_product_options' ); /* * Fix nested parsing on non-builder product pages w/ shortcode content. * @see https://github.com/elegantthemes/Divi/issues/18682 */ add_filter( 'the_content', 'et_builder_avoid_nested_shortcode_parsing' ); add_filter( 'et_builder_wc_description', 'et_builder_wc_parse_description' ); add_filter( 'template_redirect', 'et_builder_wc_template_redirect', 9 ); /* * Delete `_et_pb_woo_page_content_status` post meta when Divi Builder is off * when using GB editor. * * The latest value of `_et_pb_use_builder` post meta is only available in * `rest_after_insert_page` and NOT in `rest_insert_page` hook. * * This action is documented in * wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */ add_action( 'rest_after_insert_page', 'et_builder_wc_delete_post_meta' ); add_filter( 'woocommerce_checkout_redirect_empty_cart', 'et_builder_stop_cart_redirect_while_enabling_builder' ); /* * `wp_loaded` is used intentionally because * `get_cart()` should not be called before wp_loaded hook. */ add_action( 'wp_loaded', 'et_builder_handle_shipping_calculator_update_btn_click' ); /* * In the case of dynamic module framework's shortcode manager * we need to fire this hook on its own, */ if ( ! et_builder_should_load_all_module_data() ) { add_action( 'et_builder_module_lazy_shortcodes_registered', [ 'ET_Builder_Module_Woocommerce_Cart_Notice', 'disable_default_notice', ] ); add_action( 'et_builder_module_lazy_shortcodes_registered', [ 'ET_Builder_Module_Woocommerce_Checkout_Additional_Info', 'maybe_invoke_woocommerce_hooks', ] ); } // Relocate WC single product summary hooks to any suitable modules. add_action( 'et_builder_ready', 'et_builder_wc_relocate_single_product_summary' ); } et_builder_wc_init();