Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../themes/Divi/includes/builder/feature
File: woocommerce-modules.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* All WooCommerce modules specific functions.php stuff goes here
[2] Fix | Delete
*
[3] Fix | Delete
* @package Divi
[4] Fix | Delete
* @subpackage Builder
[5] Fix | Delete
* @since 3.29
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Define required constants.
[10] Fix | Delete
*/
[11] Fix | Delete
if ( ! defined( 'ET_BUILDER_WC_PRODUCT_LONG_DESC_META_KEY' ) ) {
[12] Fix | Delete
// Post meta key to retrieve/save Long description metabox content.
[13] Fix | Delete
define( 'ET_BUILDER_WC_PRODUCT_LONG_DESC_META_KEY', '_et_pb_old_content' );
[14] Fix | Delete
}
[15] Fix | Delete
[16] Fix | Delete
if ( ! defined( 'ET_BUILDER_WC_PRODUCT_PAGE_LAYOUT_META_KEY' ) ) {
[17] Fix | Delete
// Post meta key to retrieve/save Long description metabox content.
[18] Fix | Delete
define( 'ET_BUILDER_WC_PRODUCT_PAGE_LAYOUT_META_KEY', '_et_pb_product_page_layout' );
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
if ( ! defined( 'ET_BUILDER_WC_PRODUCT_PAGE_CONTENT_STATUS_META_KEY' ) ) {
[22] Fix | Delete
// Post meta key to track Product page content status changes.
[23] Fix | Delete
define( 'ET_BUILDER_WC_PRODUCT_PAGE_CONTENT_STATUS_META_KEY', '_et_pb_woo_page_content_status' );
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* Returning <img> string for default image placeholder
[28] Fix | Delete
*
[29] Fix | Delete
* @since 4.0.10
[30] Fix | Delete
*
[31] Fix | Delete
* @return string
[32] Fix | Delete
*/
[33] Fix | Delete
function et_builder_wc_placeholder_img() {
[34] Fix | Delete
return sprintf(
[35] Fix | Delete
'<img src="%1$s" alt="2$s" />',
[36] Fix | Delete
et_core_esc_attr( 'placeholder', ET_BUILDER_PLACEHOLDER_LANDSCAPE_IMAGE_DATA ),
[37] Fix | Delete
esc_attr__( 'Product image', 'et_builder' )
[38] Fix | Delete
);
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* Gets the Product Content options.
[43] Fix | Delete
*
[44] Fix | Delete
* This array is used in Divi Page Settings metabox and in Divi Theme Options ⟶ Builder ⟶ Post Type integration.
[45] Fix | Delete
*
[46] Fix | Delete
* @since 3.29
[47] Fix | Delete
*
[48] Fix | Delete
* @param string $translation_context Translation Context to indicate if translation origins from Divi Theme or
[49] Fix | Delete
* from the Builder. Optional. Default 'et_builder'.
[50] Fix | Delete
*
[51] Fix | Delete
* @return array
[52] Fix | Delete
*/
[53] Fix | Delete
function et_builder_wc_get_page_layouts( $translation_context = 'et_builder' ) {
[54] Fix | Delete
switch ( $translation_context ) {
[55] Fix | Delete
case 'Divi':
[56] Fix | Delete
$product_page_layouts = array(
[57] Fix | Delete
'et_build_from_scratch' => esc_html__( 'Build From Scratch', 'Divi' ),
[58] Fix | Delete
'et_default_layout' => esc_html__( 'Default', 'Divi' ),
[59] Fix | Delete
);
[60] Fix | Delete
break;
[61] Fix | Delete
default:
[62] Fix | Delete
$product_page_layouts = array(
[63] Fix | Delete
'et_build_from_scratch' => esc_html__( 'Build From Scratch', 'et_builder' ),
[64] Fix | Delete
'et_default_layout' => et_builder_i18n( 'Default' ),
[65] Fix | Delete
);
[66] Fix | Delete
break;
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
return $product_page_layouts;
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
/**
[73] Fix | Delete
* Adds WooCommerce Module settings to the Builder settings.
[74] Fix | Delete
*
[75] Fix | Delete
* Adding in the Builder Settings tab will ensure that the field is available in Extra Theme and
[76] Fix | Delete
* Divi Builder Plugin.
[77] Fix | Delete
*
[78] Fix | Delete
* @since 4.0.3 Hide Product Content layout settings Divi Builder Plugin options.
[79] Fix | Delete
* @since 3.29
[80] Fix | Delete
*
[81] Fix | Delete
* @param array $builder_settings_fields
[82] Fix | Delete
*
[83] Fix | Delete
* @return array
[84] Fix | Delete
*/
[85] Fix | Delete
function et_builder_wc_add_settings( $builder_settings_fields ) {
[86] Fix | Delete
// Bail early to hide WooCommerce Settings tab under the Builder tab.
[87] Fix | Delete
// If $fields['tab_slug'] is not equal to the tab slug (i.e. woocommerce_page_layout) then WooCommerce settings tab won't be displayed.
[88] Fix | Delete
// {@see ET_Builder_Settings::_get_builder_settings_in_epanel_format}
[89] Fix | Delete
if ( ! et_is_woocommerce_plugin_active() ) {
[90] Fix | Delete
return $builder_settings_fields;
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
$fields = array(
[94] Fix | Delete
'et_pb_woocommerce_product_layout' => array(
[95] Fix | Delete
'type' => 'select',
[96] Fix | Delete
'id' => 'et_pb_woocommerce_product_layout',
[97] Fix | Delete
'index' => - 1,
[98] Fix | Delete
'label' => esc_html__( 'Product Layout', 'et_builder' ),
[99] Fix | Delete
'description' => esc_html__( 'Here you can choose Product Page Layout for WooCommerce.', 'et_builder' ),
[100] Fix | Delete
'options' => array(
[101] Fix | Delete
'et_right_sidebar' => esc_html__( 'Right Sidebar', 'et_builder' ),
[102] Fix | Delete
'et_left_sidebar' => esc_html__( 'Left Sidebar', 'et_builder' ),
[103] Fix | Delete
'et_no_sidebar' => esc_html__( 'No Sidebar', 'et_builder' ),
[104] Fix | Delete
'et_full_width_page' => esc_html__( 'Fullwidth', 'et_builder' ),
[105] Fix | Delete
),
[106] Fix | Delete
'default' => 'et_right_sidebar',
[107] Fix | Delete
'validation_type' => 'simple_text',
[108] Fix | Delete
'et_save_values' => true,
[109] Fix | Delete
'tab_slug' => 'post_type_integration',
[110] Fix | Delete
'toggle_slug' => 'performance',
[111] Fix | Delete
),
[112] Fix | Delete
'et_pb_woocommerce_page_layout' => array(
[113] Fix | Delete
'type' => 'select',
[114] Fix | Delete
'id' => 'et_pb_woocommerce_product_page_layout',
[115] Fix | Delete
'index' => -1,
[116] Fix | Delete
'label' => esc_html__( 'Product Content', 'et_builder' ),
[117] Fix | Delete
'description' => esc_html__( '"Build From Scratch" loads a pre-built WooCommerce page layout, with which you build on when the Divi Builder is enabled. "Default" option lets you use default WooCommerce page layout.', 'et_builder' ),
[118] Fix | Delete
'options' => et_builder_wc_get_page_layouts(),
[119] Fix | Delete
'default' => 'et_build_from_scratch',
[120] Fix | Delete
'validation_type' => 'simple_text',
[121] Fix | Delete
'et_save_values' => true,
[122] Fix | Delete
'tab_slug' => 'post_type_integration',
[123] Fix | Delete
'toggle_slug' => 'performance',
[124] Fix | Delete
),
[125] Fix | Delete
);
[126] Fix | Delete
[127] Fix | Delete
// Hide setting in DBP : https://github.com/elegantthemes/Divi/issues/17378
[128] Fix | Delete
if ( et_is_builder_plugin_active() ) {
[129] Fix | Delete
unset( $fields['et_pb_woocommerce_product_layout'] );
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
return array_merge( $builder_settings_fields, $fields );
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
/**
[136] Fix | Delete
* Gets the pre-built layout for WooCommerce product pages.
[137] Fix | Delete
*
[138] Fix | Delete
* @since 3.29
[139] Fix | Delete
*
[140] Fix | Delete
* @param array $args {
[141] Fix | Delete
* Additional args.
[142] Fix | Delete
*
[143] Fix | Delete
* @type string $existing_shortcode Existing builder shortcode.
[144] Fix | Delete
* }
[145] Fix | Delete
*
[146] Fix | Delete
* @return string
[147] Fix | Delete
*/
[148] Fix | Delete
function et_builder_wc_get_initial_content( $args = array() ) {
[149] Fix | Delete
/**
[150] Fix | Delete
* Filters the Top section Background in the default WooCommerce Modules layout.
[151] Fix | Delete
*
[152] Fix | Delete
* @param string $color Default empty.
[153] Fix | Delete
*/
[154] Fix | Delete
$et_builder_wc_initial_top_section_bg = apply_filters( 'et_builder_wc_initial_top_section_bg', '' );
[155] Fix | Delete
[156] Fix | Delete
$content = '
[157] Fix | Delete
[et_pb_section custom_padding="0px||||false|false" background_color="' . esc_attr( $et_builder_wc_initial_top_section_bg ) . '"]
[158] Fix | Delete
[et_pb_row width="100%" custom_padding="0px||0px||false|false"]
[159] Fix | Delete
[et_pb_column type="4_4"]
[160] Fix | Delete
[et_pb_wc_breadcrumb][/et_pb_wc_breadcrumb]
[161] Fix | Delete
[et_pb_wc_cart_notice][/et_pb_wc_cart_notice]
[162] Fix | Delete
[/et_pb_column]
[163] Fix | Delete
[/et_pb_row]
[164] Fix | Delete
[et_pb_row custom_padding="0px||||false|false" width="100%"]
[165] Fix | Delete
[et_pb_column type="1_2"]
[166] Fix | Delete
[et_pb_wc_images][/et_pb_wc_images]
[167] Fix | Delete
[/et_pb_column]
[168] Fix | Delete
[et_pb_column type="1_2"]
[169] Fix | Delete
[et_pb_wc_title][/et_pb_wc_title]
[170] Fix | Delete
[et_pb_wc_rating][/et_pb_wc_rating]
[171] Fix | Delete
[et_pb_wc_price][/et_pb_wc_price]
[172] Fix | Delete
[et_pb_wc_description][/et_pb_wc_description]
[173] Fix | Delete
[et_pb_wc_add_to_cart form_field_text_align="center"][/et_pb_wc_add_to_cart]
[174] Fix | Delete
[et_pb_wc_meta][/et_pb_wc_meta]
[175] Fix | Delete
[/et_pb_column]
[176] Fix | Delete
[/et_pb_row]
[177] Fix | Delete
[et_pb_row width="100%"]
[178] Fix | Delete
[et_pb_column type="4_4"]
[179] Fix | Delete
[et_pb_wc_tabs]
[180] Fix | Delete
[/et_pb_wc_tabs]
[181] Fix | Delete
[et_pb_wc_upsells columns_number="3"][/et_pb_wc_upsells]
[182] Fix | Delete
[et_pb_wc_related_products columns_number="3"][/et_pb_wc_related_products]
[183] Fix | Delete
[/et_pb_column]
[184] Fix | Delete
[/et_pb_row]
[185] Fix | Delete
[/et_pb_section]';
[186] Fix | Delete
[187] Fix | Delete
if ( ! empty( $args['existing_shortcode'] ) ) {
[188] Fix | Delete
return $content . $args['existing_shortcode'];
[189] Fix | Delete
}
[190] Fix | Delete
[191] Fix | Delete
return $content;
[192] Fix | Delete
}
[193] Fix | Delete
[194] Fix | Delete
/**
[195] Fix | Delete
* Gets the Product layout for a given Post ID.
[196] Fix | Delete
*
[197] Fix | Delete
* @since 3.29
[198] Fix | Delete
*
[199] Fix | Delete
* @param int $post_id Post Id.
[200] Fix | Delete
*
[201] Fix | Delete
* @return string The return value will be one of the values from
[202] Fix | Delete
* {@see et_builder_wc_get_page_layouts()} when the Post ID is valid.
[203] Fix | Delete
* Empty string otherwise.
[204] Fix | Delete
*/
[205] Fix | Delete
function et_builder_wc_get_product_layout( $post_id ) {
[206] Fix | Delete
$post = get_post( $post_id );
[207] Fix | Delete
[208] Fix | Delete
if ( ! $post ) {
[209] Fix | Delete
return false;
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
return get_post_meta( $post_id, ET_BUILDER_WC_PRODUCT_PAGE_LAYOUT_META_KEY, true );
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
/**
[216] Fix | Delete
* Sets the pre-built layout for WooCommerce product pages.
[217] Fix | Delete
*
[218] Fix | Delete
* @param string $maybe_shortcode_content
[219] Fix | Delete
* @param int $post_id
[220] Fix | Delete
* @param string $content Default null. Post content.
[221] Fix | Delete
*
[222] Fix | Delete
* @return string
[223] Fix | Delete
*/
[224] Fix | Delete
function et_builder_wc_set_initial_content( $maybe_shortcode_content, $post_id ) {
[225] Fix | Delete
$post = get_post( absint( $post_id ) );
[226] Fix | Delete
$args = array();
[227] Fix | Delete
[228] Fix | Delete
if ( ! ( $post instanceof WP_Post ) || 'product' !== $post->post_type ) {
[229] Fix | Delete
return $maybe_shortcode_content;
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
// $post_id is a valid Product ID by now.
[233] Fix | Delete
$product_page_layout = et_builder_wc_get_product_layout( $post_id );
[234] Fix | Delete
[235] Fix | Delete
/*
[236] Fix | Delete
* When FALSE, this means the Product doesn't use Builder at all;
[237] Fix | Delete
* Or the Product has been using the Builder before WooCommerce Modules QF launched.
[238] Fix | Delete
*/
[239] Fix | Delete
if ( ! $product_page_layout ) {
[240] Fix | Delete
$product_page_layout = et_get_option(
[241] Fix | Delete
'et_pb_woocommerce_page_layout',
[242] Fix | Delete
'et_build_from_scratch'
[243] Fix | Delete
);
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
$is_product_content_modified = 'modified' === get_post_meta( $post_id,
[247] Fix | Delete
ET_BUILDER_WC_PRODUCT_PAGE_CONTENT_STATUS_META_KEY, true );
[248] Fix | Delete
[249] Fix | Delete
// Content was already saved or default content should be loaded.
[250] Fix | Delete
if ( $is_product_content_modified || 'et_default_layout' === $product_page_layout ) {
[251] Fix | Delete
return $maybe_shortcode_content;
[252] Fix | Delete
}
[253] Fix | Delete
[254] Fix | Delete
if ( has_shortcode( $maybe_shortcode_content, 'et_pb_section' ) &&
[255] Fix | Delete
'et_build_from_scratch' === $product_page_layout &&
[256] Fix | Delete
! empty( $maybe_shortcode_content ) ) {
[257] Fix | Delete
$args['existing_shortcode'] = $maybe_shortcode_content;
[258] Fix | Delete
}
[259] Fix | Delete
[260] Fix | Delete
return et_builder_wc_get_initial_content( $args );
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
/**
[264] Fix | Delete
* Saves the WooCommerce long description metabox content.
[265] Fix | Delete
*
[266] Fix | Delete
* The content is stored as post meta w/ the key `_et_pb_old_content`.
[267] Fix | Delete
*
[268] Fix | Delete
* @since 3.29
[269] Fix | Delete
*
[270] Fix | Delete
* @param int $post_id
[271] Fix | Delete
*/
[272] Fix | Delete
function et_builder_wc_long_description_metabox_save( $post_id, $post, $request ) {
[273] Fix | Delete
if ( ! isset( $request['et_bfb_long_description_nonce'] ) ) {
[274] Fix | Delete
return;
[275] Fix | Delete
}
[276] Fix | Delete
[277] Fix | Delete
if ( current_user_can( 'edit_posts', $post_id ) && et_core_security_check( 'edit_posts', 'et_bfb_long_description_nonce', '_et_bfb_long_description_nonce', '_POST', false )
[278] Fix | Delete
) {
[279] Fix | Delete
return;
[280] Fix | Delete
}
[281] Fix | Delete
[282] Fix | Delete
if ( 'product' !== $post->post_type ) {
[283] Fix | Delete
return;
[284] Fix | Delete
}
[285] Fix | Delete
[286] Fix | Delete
if ( ! isset( $request['et_builder_wc_product_long_description'] ) ) {
[287] Fix | Delete
return;
[288] Fix | Delete
}
[289] Fix | Delete
[290] Fix | Delete
$long_desc_content = $request['et_builder_wc_product_long_description'];
[291] Fix | Delete
$is_updated = update_post_meta( $post_id, ET_BUILDER_WC_PRODUCT_LONG_DESC_META_KEY, wp_kses_post( $long_desc_content ) );
[292] Fix | Delete
}
[293] Fix | Delete
[294] Fix | Delete
/**
[295] Fix | Delete
* Output Callback for Product long description metabox.
[296] Fix | Delete
*
[297] Fix | Delete
* @since 3.29
[298] Fix | Delete
*
[299] Fix | Delete
* @param WP_Post $post
[300] Fix | Delete
*/
[301] Fix | Delete
function et_builder_wc_long_description_metabox_render( $post ) {
[302] Fix | Delete
$settings = array(
[303] Fix | Delete
'textarea_name' => 'et_builder_wc_product_long_description',
[304] Fix | Delete
'quicktags' => array( 'buttons' => 'em,strong,link' ),
[305] Fix | Delete
'tinymce' => array(
[306] Fix | Delete
'theme_advanced_buttons1' => 'bold,italic,strikethrough,separator,bullist,numlist,separator,blockquote,separator,justifyleft,justifycenter,justifyright,separator,link,unlink,separator,undo,redo,separator',
[307] Fix | Delete
'theme_advanced_buttons2' => '',
[308] Fix | Delete
),
[309] Fix | Delete
'editor_css' => '<style>#wp-et_builder_wc_product_long_description-editor-container .wp-editor-area{height:175px; width:100%;}</style>',
[310] Fix | Delete
);
[311] Fix | Delete
[312] Fix | Delete
// Since we use $post_id in more than one place, use a variable.
[313] Fix | Delete
$post_id = $post->ID;
[314] Fix | Delete
[315] Fix | Delete
// Long description metabox content. Default Empty.
[316] Fix | Delete
$long_desc_content = get_post_meta( $post_id, ET_BUILDER_WC_PRODUCT_LONG_DESC_META_KEY, true );
[317] Fix | Delete
$long_desc_content = ! empty( $long_desc_content ) ? $long_desc_content : '';
[318] Fix | Delete
[319] Fix | Delete
/**
[320] Fix | Delete
* Filters the wp_editor settings used in the Long description metabox.
[321] Fix | Delete
*
[322] Fix | Delete
* @param array $settings WP Editor settings.
[323] Fix | Delete
*
[324] Fix | Delete
* @since 3.29
[325] Fix | Delete
*/
[326] Fix | Delete
$settings = apply_filters( 'et_builder_wc_product_long_description_editor_settings', $settings );
[327] Fix | Delete
[328] Fix | Delete
wp_nonce_field( '_et_bfb_long_description_nonce', 'et_bfb_long_description_nonce' );
[329] Fix | Delete
[330] Fix | Delete
wp_editor(
[331] Fix | Delete
$long_desc_content,
[332] Fix | Delete
'et_builder_wc_product_long_description',
[333] Fix | Delete
$settings
[334] Fix | Delete
);
[335] Fix | Delete
}
[336] Fix | Delete
[337] Fix | Delete
/**
[338] Fix | Delete
* Adds the Long description metabox to Product post type.
[339] Fix | Delete
*
[340] Fix | Delete
* @since 3.29
[341] Fix | Delete
*
[342] Fix | Delete
* @param WP_Post $post WP Post.
[343] Fix | Delete
*/
[344] Fix | Delete
function et_builder_wc_long_description_metabox_register( $post ) {
[345] Fix | Delete
if ( 'on' !== get_post_meta( $post->ID, '_et_pb_use_builder', true ) ) {
[346] Fix | Delete
return;
[347] Fix | Delete
}
[348] Fix | Delete
[349] Fix | Delete
add_meta_box( 'et_builder_wc_product_long_description_metabox',
[350] Fix | Delete
__( 'Product long description', 'et_builder' ),
[351] Fix | Delete
'et_builder_wc_long_description_metabox_render',
[352] Fix | Delete
'product',
[353] Fix | Delete
'normal'
[354] Fix | Delete
);
[355] Fix | Delete
}
[356] Fix | Delete
[357] Fix | Delete
/**
[358] Fix | Delete
* Determine if WooCommerce's $product global need to be overwritten or not.
[359] Fix | Delete
* IMPORTANT: make sure to reset it later
[360] Fix | Delete
*
[361] Fix | Delete
* @since 3.29
[362] Fix | Delete
*
[363] Fix | Delete
* @param string $product_id
[364] Fix | Delete
*
[365] Fix | Delete
* @return bool
[366] Fix | Delete
*/
[367] Fix | Delete
function et_builder_wc_need_overwrite_global( $product_id = 'current' ) {
[368] Fix | Delete
$is_current_product_page = 'current' === $product_id;
[369] Fix | Delete
[370] Fix | Delete
// There are three situation which requires global value overwrite: initial builder
[371] Fix | Delete
// ajax request, computed callback jax request (all ajax request has faulty global variable),
[372] Fix | Delete
// and if `product` attribute is not current page's product id (ie Woo Tabs being used
[373] Fix | Delete
// on non `product` CPT)
[374] Fix | Delete
$need_overwrite_global = ! $is_current_product_page
[375] Fix | Delete
|| et_fb_is_builder_ajax()
[376] Fix | Delete
|| et_fb_is_computed_callback_ajax();
[377] Fix | Delete
[378] Fix | Delete
return $need_overwrite_global;
[379] Fix | Delete
}
[380] Fix | Delete
[381] Fix | Delete
/**
[382] Fix | Delete
* Helper to render module template for module's front end and computed callback output
[383] Fix | Delete
*
[384] Fix | Delete
* @since 3.29
[385] Fix | Delete
*
[386] Fix | Delete
* @param string $function_name
[387] Fix | Delete
* @param array $args
[388] Fix | Delete
* @param array $overwrite
[389] Fix | Delete
*
[390] Fix | Delete
* @return string
[391] Fix | Delete
*/
[392] Fix | Delete
function et_builder_wc_render_module_template( $function_name, $args = array(), $overwrite = array( 'product' ) ) {
[393] Fix | Delete
// Shouldn't be fired in Backend to not break the BB loading.
[394] Fix | Delete
if ( is_admin() && ! wp_doing_ajax() ) {
[395] Fix | Delete
return;
[396] Fix | Delete
}
[397] Fix | Delete
[398] Fix | Delete
// Check if passed function name is allowlisted or not
[399] Fix | Delete
$allowlisted_functions = array(
[400] Fix | Delete
'the_title',
[401] Fix | Delete
'woocommerce_breadcrumb',
[402] Fix | Delete
'woocommerce_template_single_price',
[403] Fix | Delete
'woocommerce_template_single_add_to_cart',
[404] Fix | Delete
'woocommerce_product_additional_information_tab',
[405] Fix | Delete
'woocommerce_template_single_meta',
[406] Fix | Delete
'woocommerce_template_single_rating',
[407] Fix | Delete
'woocommerce_show_product_images',
[408] Fix | Delete
'wc_get_stock_html',
[409] Fix | Delete
'wc_print_notices',
[410] Fix | Delete
'wc_print_notice',
[411] Fix | Delete
'woocommerce_output_related_products',
[412] Fix | Delete
'woocommerce_upsell_display',
[413] Fix | Delete
);
[414] Fix | Delete
[415] Fix | Delete
if ( ! in_array( $function_name, $allowlisted_functions ) ) {
[416] Fix | Delete
return '';
[417] Fix | Delete
}
[418] Fix | Delete
[419] Fix | Delete
global $product, $post, $wp_query;
[420] Fix | Delete
[421] Fix | Delete
$defaults = array(
[422] Fix | Delete
'product' => 'current',
[423] Fix | Delete
);
[424] Fix | Delete
[425] Fix | Delete
$args = wp_parse_args( $args, $defaults );
[426] Fix | Delete
$overwrite_global = et_builder_wc_need_overwrite_global( $args['product'] );
[427] Fix | Delete
$overwrite_product = in_array( 'product', $overwrite );
[428] Fix | Delete
$overwrite_post = in_array( 'post', $overwrite );
[429] Fix | Delete
$overwrite_wp_query = in_array( 'wp_query', $overwrite );
[430] Fix | Delete
$is_tb = et_builder_tb_enabled();
[431] Fix | Delete
[432] Fix | Delete
if ( $is_tb ) {
[433] Fix | Delete
// global object needs to be set before output rendering. This needs to be performed on each
[434] Fix | Delete
// module template rendering instead of once for all module template rendering because some
[435] Fix | Delete
// module's template rendering uses `wp_reset_postdata()` which resets global query
[436] Fix | Delete
et_theme_builder_wc_set_global_objects();
[437] Fix | Delete
} else if ( $overwrite_global ) {
[438] Fix | Delete
$is_latest_product = 'latest' === $args['product'];
[439] Fix | Delete
$is_current_product_page = 'current' === $args['product'];
[440] Fix | Delete
[441] Fix | Delete
if ( $is_latest_product ) {
[442] Fix | Delete
// Dynamic filter's product_id need to be translated into correct id
[443] Fix | Delete
// @todo once `product_filter` has more options, this might change
[444] Fix | Delete
$product_id = ET_Builder_Module_Helper_Woocommerce_Modules::get_product_id( $args['product'] );
[445] Fix | Delete
} elseif ( $is_current_product_page && wp_doing_ajax() && class_exists( 'ET_Builder_Element' ) ) {
[446] Fix | Delete
// $product global doesn't exist in ajax request; thus get the fallback post id
[447] Fix | Delete
// this is likely happen in computed callback ajax request
[448] Fix | Delete
$product_id = ET_Builder_Element::get_current_post_id();
[449] Fix | Delete
} else {
[450] Fix | Delete
// Besides two situation above, $product_id is current $args['product']
[451] Fix | Delete
if ( false !== get_post_status( $args['product'] ) ) {
[452] Fix | Delete
$product_id = $args['product'];
[453] Fix | Delete
} else {
[454] Fix | Delete
// Fallback to Latest product if saved product ID doesn't exist.
[455] Fix | Delete
$product_id = ET_Builder_Module_Helper_Woocommerce_Modules::get_product_id( 'latest' );
[456] Fix | Delete
}
[457] Fix | Delete
}
[458] Fix | Delete
[459] Fix | Delete
if ( 'product' !== get_post_type( $product_id ) ) {
[460] Fix | Delete
// We are in a Theme Builder layout and the current post is not a product - use the latest one instead.
[461] Fix | Delete
$products = new WP_Query( array(
[462] Fix | Delete
'post_type' => 'product',
[463] Fix | Delete
'post_status' => 'publish',
[464] Fix | Delete
'posts_per_page' => 1,
[465] Fix | Delete
'no_found_rows' => true,
[466] Fix | Delete
) );
[467] Fix | Delete
[468] Fix | Delete
if ( ! $products->have_posts() ) {
[469] Fix | Delete
return '';
[470] Fix | Delete
}
[471] Fix | Delete
[472] Fix | Delete
$product_id = $products->posts[0]->ID;
[473] Fix | Delete
}
[474] Fix | Delete
[475] Fix | Delete
// Overwrite product
[476] Fix | Delete
if ( $overwrite_product ) {
[477] Fix | Delete
$original_product = $product;
[478] Fix | Delete
$product = wc_get_product( $product_id );
[479] Fix | Delete
}
[480] Fix | Delete
[481] Fix | Delete
// Overwrite post
[482] Fix | Delete
if ( $overwrite_post ) {
[483] Fix | Delete
$original_post = $post;
[484] Fix | Delete
$post = get_post( $product_id );
[485] Fix | Delete
}
[486] Fix | Delete
[487] Fix | Delete
// Overwrite wp_query
[488] Fix | Delete
if ( $overwrite_wp_query ) {
[489] Fix | Delete
$original_wp_query = $wp_query;
[490] Fix | Delete
$wp_query = new WP_Query( array( 'p' => $product_id ) );
[491] Fix | Delete
}
[492] Fix | Delete
}
[493] Fix | Delete
[494] Fix | Delete
ob_start();
[495] Fix | Delete
[496] Fix | Delete
switch( $function_name ) {
[497] Fix | Delete
case 'woocommerce_breadcrumb':
[498] Fix | Delete
$breadcrumb_separator = et_()->array_get( $args, 'breadcrumb_separator', '' );
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function