1

For some purpose, we want to apply a change to the Wordpress flow that affect's WooCommerce product page being displayed.

When a product page is displayed (e.g. www.mysite.com/?product=my-product), traditionally, it displays the post of "my-product", we want to intercept that and do the following:

1) Display a predefined page instead of the "my-product" page (modify current $post to be something constant, e.g. page with ID=1 or by slug name).

2) Maintain the $product setup so the current product being referred to is still "my-product", in other words, does not interfere with WooCommerce setup.

I'm trying the following

public function pre_get_posts_custom($wc_query) {

    if ( !$wc_query->is_main_query() /* || is_product_page() */ ) {
        return;
    }

    $wc_query-> set( 'page_id' , 1);
    $wc_query-> set( 'pagename' , 'pageslug');
    $wc_query-> set( 'post_type' , 'page');

    return;
}
add_action('pre_get_posts', 'pre_get_posts_custom', 999);

But that's not working, it is referring me to: www.mysite.com/?product=my-product&page_id=1 which ends up showing a not found page.

Ideas?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.