Skip to content

Commit

Permalink
fix: divi custom header, footer template does not work in dokan store…
Browse files Browse the repository at this point in the history
… page is fixed #838 (#839)
  • Loading branch information
saimonh3 authored Jun 2, 2020
1 parent cf38d98 commit ef47218
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions includes/Rewrites.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ function store_query_filter( $query ) {
$store_info = dokan_get_store_info( $seller_info->data->ID );
$post_per_page = isset( $store_info['store_ppp'] ) && ! empty( $store_info['store_ppp'] ) ? $store_info['store_ppp'] : 12;

do_action( 'dokan_store_page_query_filter', $query, $store_info );
set_query_var( 'posts_per_page', $post_per_page );

$query->set( 'post_type', 'product' );
Expand Down
34 changes: 34 additions & 0 deletions includes/ThemeSupport/Divi.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace WeDevs\Dokan\ThemeSupport;

use stdClass;

/**
* Divi Theme Support
*
Expand All @@ -18,6 +20,7 @@ function __construct() {
add_action( 'template_redirect', [ $this, 'remove_sidebar'] );
add_filter( 'body_class', [ $this, 'full_width_page'] );
add_action( 'wp_enqueue_scripts', [ $this, 'style_reset' ] );
add_action( 'dokan_store_page_query_filter', [ $this, 'set_current_page' ], 10, 2 );
}

/**
Expand Down Expand Up @@ -65,4 +68,35 @@ public function full_width_page( $classes ) {

return $classes;
}

/**
* Set current page for the query
*
* @since DOKAN_LITE_SINCE
*
* @see https://github.com/weDevsOfficial/dokan/issues/838
*
* @param \WP_Query $query
* @param array $store_info
*
* @return void
*/
public function set_current_page( $query, $store_info ) {
/**
* Divi is tightly coupled with singular page data in general and dokan store page is not a regular WordPress page
* But created with custom rewrite rules. So we'll trick Divi builder to assume dokan store page is really `page` post_type.
* So lets create a fake page object, and set it to `WP_Query->queried_object` and make the page `is_singular`.
*/
$page = new stdClass;
$page->ID = get_option( 'woocommerce_shop_page_id' ); // So it's created by admin, vendor can't see the edit page menu on navbar
$page->post_type = 'page';

$query->is_singular = true;
$query->queried_object = $page;
$query->queried_object_id = $page->ID;

add_filter( 'pre_get_document_title', function() use ( $store_info ) {
return ! empty( $store_info['store_name'] ) ? $store_info['store_name'] : __( 'No Name', 'dokan-lite' );
} );
}
}

0 comments on commit ef47218

Please sign in to comment.