Edit File by line
/home/barbar84/www/wp-conte.../themes/Divi/includes/builder/compat
File: woocommerce.php
<?php
[0] Fix | Delete
$GLOBALS['et_builder_used_in_wc_shop'] = false;
[1] Fix | Delete
[2] Fix | Delete
/**
[3] Fix | Delete
* Determines if current page is WooCommerce's shop page + uses builder.
[4] Fix | Delete
* NOTE: This has to be used after pre_get_post (et_builder_wc_pre_get_posts).
[5] Fix | Delete
*
[6] Fix | Delete
* @return bool
[7] Fix | Delete
*/
[8] Fix | Delete
function et_builder_used_in_wc_shop() {
[9] Fix | Delete
global $et_builder_used_in_wc_shop;
[10] Fix | Delete
[11] Fix | Delete
return apply_filters(
[12] Fix | Delete
'et_builder_used_in_wc_shop',
[13] Fix | Delete
$et_builder_used_in_wc_shop
[14] Fix | Delete
);
[15] Fix | Delete
}
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* Use page.php as template for a page which uses builder & being set as shop page
[19] Fix | Delete
*
[20] Fix | Delete
* @param string path to template
[21] Fix | Delete
* @return string modified path to template
[22] Fix | Delete
*/
[23] Fix | Delete
function et_builder_wc_template_include( $template ) {
[24] Fix | Delete
// Detemine whether current page uses builder and set as
[25] Fix | Delete
if ( et_builder_used_in_wc_shop() && '' !== locate_template( 'page.php' ) ) {
[26] Fix | Delete
$template = locate_template( 'page.php' );
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
return $template;
[30] Fix | Delete
}
[31] Fix | Delete
add_filter( 'template_include', 'et_builder_wc_template_include', 20 );
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Overwrite WooCommerce's custom query in shop page if the page uses builder.
[35] Fix | Delete
* After proper shop page setup (page selection + permalink flushed), the original
[36] Fix | Delete
* page permalink will be recognized as is_post_type_archive by WordPress' rewrite
[37] Fix | Delete
* URL when it is being parsed. This causes is_page() detection fails and no way
[38] Fix | Delete
* to get actual page ID on pre_get_posts hook, unless by doing reverse detection:
[39] Fix | Delete
*
[40] Fix | Delete
* 1. Check if current page is product archive page. Most page will fail on this.
[41] Fix | Delete
* 2. Afterward, if wc_get_page_id( 'shop' ) returns a page ID, it means that
[42] Fix | Delete
* current page is shop page (product post type archive) which is configured
[43] Fix | Delete
* in custom page. Next, check whether Divi Builder is used on this page or not.
[44] Fix | Delete
*
[45] Fix | Delete
* @param object query object
[46] Fix | Delete
* @param void
[47] Fix | Delete
*/
[48] Fix | Delete
function et_builder_wc_pre_get_posts( $query ) {
[49] Fix | Delete
global $et_builder_used_in_wc_shop;
[50] Fix | Delete
[51] Fix | Delete
if ( is_admin() ) {
[52] Fix | Delete
return;
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
if ( ! $query->is_main_query() ) {
[56] Fix | Delete
return;
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
if ( $query->is_search() ) {
[60] Fix | Delete
return;
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
if ( ! class_exists( 'WooCommerce' ) ) {
[64] Fix | Delete
return;
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
if ( ! function_exists( 'wc_get_page_id' ) ) {
[68] Fix | Delete
return;
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
// Check if current page is product archive page. Most page will fail on this.
[72] Fix | Delete
// initially used is_shop(), but is_shop()'s is_page() check throws error at
[73] Fix | Delete
// this early hook on homepage if shop page !== page_on_front
[74] Fix | Delete
if ( ! is_post_type_archive( 'product' ) ) {
[75] Fix | Delete
return;
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
// Note that the following check is only performed on product archive page.
[79] Fix | Delete
$shop_page_id = wc_get_page_id( 'shop' );
[80] Fix | Delete
$shop_page_object = get_post( $shop_page_id );
[81] Fix | Delete
$is_shop_page_exist = isset( $shop_page_object->post_type ) && 'page' === $shop_page_object->post_type;
[82] Fix | Delete
[83] Fix | Delete
if ( ! $is_shop_page_exist ) {
[84] Fix | Delete
return;
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
if ( ! et_pb_is_pagebuilder_used( $shop_page_id ) ) {
[88] Fix | Delete
return;
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
// Set et_builder_used_in_wc_shop() global to true
[92] Fix | Delete
$et_builder_used_in_wc_shop = true;
[93] Fix | Delete
[94] Fix | Delete
// Overwrite page query. This overwrite enables is_page() and other standard
[95] Fix | Delete
// page-related function to work normally after pre_get_posts hook
[96] Fix | Delete
$query->set( 'page_id', $shop_page_id );
[97] Fix | Delete
$query->set( 'post_type', 'page' );
[98] Fix | Delete
$query->set( 'posts_per_page', 1 );
[99] Fix | Delete
$query->set( 'wc_query', null );
[100] Fix | Delete
$query->set( 'meta_query', array() );
[101] Fix | Delete
[102] Fix | Delete
$query->is_singular = true;
[103] Fix | Delete
$query->is_page = true;
[104] Fix | Delete
$query->is_post_type_archive = false;
[105] Fix | Delete
$query->is_archive = false;
[106] Fix | Delete
[107] Fix | Delete
// Avoid unwanted <p> at the beginning of the rendered builder
[108] Fix | Delete
remove_filter( 'the_content', 'wpautop' );
[109] Fix | Delete
}
[110] Fix | Delete
add_action( 'pre_get_posts', 'et_builder_wc_pre_get_posts' );
[111] Fix | Delete
[112] Fix | Delete
/**
[113] Fix | Delete
* Remove woocommerce body classes if current shop page uses builder.
[114] Fix | Delete
* woocommerce-page body class causes builder's shop column styling to be irrelevant.
[115] Fix | Delete
*
[116] Fix | Delete
* @param array body classes
[117] Fix | Delete
* @return array modified body classes
[118] Fix | Delete
*/
[119] Fix | Delete
function et_builder_wc_body_class( $classes ) {
[120] Fix | Delete
if ( et_builder_used_in_wc_shop() ) {
[121] Fix | Delete
$classes = array_diff( $classes, array( 'woocommerce', 'woocommerce-page' ) );
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
return $classes;
[125] Fix | Delete
}
[126] Fix | Delete
add_filter( 'body_class', 'et_builder_wc_body_class' );
[127] Fix | Delete
[128] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function