The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Foxyshop add ability to change "with_front" for custom post type and taxonomies

Hello,

We have a client that wants to make changes to their permalink structure. However, Foxyshop does not give you the ability to alter the with_front setting for WordPress when registering a custom post type or taxonomy. Because of this, changing the permalink would also change the permalink for all Foxyshop products and for Foxyshop taxonomies

Comments
  • In the interim, I believe I found a workaround by adding the following code to my functions.php

    /**
    * Set 'with_front' to false for the 'experts' post type.
    */
    add_filter( 'register_post_type_args', function( $args, $post_type )
    {
    if( 'foxyshop_product' === $post_type && is_array( $args ) )
    $args['rewrite']['with_front'] = false;

    return $args;
    }, 99, 2 );

    add_filter( 'register_taxonomy_args', function( $args, $taxonomy )
    {
    if( ('foxyshop_categories' === $taxonomy || 'foxyshop_tags' === $taxonomy ) && is_array( $args ) )
    $args['rewrite']['with_front'] = false;
    return $args;
    }, 99, 2 );
  • I had to make an update, the following gets everything covered for reference if there's anyone else looking to do this:

    /**
    * Set 'with_front' to false for the 'experts' post type.
    */
    add_filter( 'register_post_type_args', function( $args, $post_type )
    {
    if( 'foxyshop_product' === $post_type && is_array( $args ) )
    $args['rewrite']['with_front'] = false;

    return $args;
    }, 99, 2 );

    add_filter( 'register_taxonomy_args', function( $args, $taxonomy )
    {
    if( ('foxyshop_categories' === $taxonomy || 'foxyshop_tags' === $taxonomy || 'project_region' === $taxonomy) && is_array( $args ) )
    $args['rewrite']['with_front'] = false;
    return $args;
    }, 99, 2 );
  • fc_adamfc_adam FoxyCart Team
    @mdavoli,

    Thanks for posting - and for sharing the solution you came up with!

    There's a similar, but slightly more FoxyShop-native approach you can take, which would look like this added to your functions.php file:
    add_filter('foxyshop_register_post_type', 'updateFoxyShopRewrite', 10, 1);
    add_filter('foxyshop_product_cat_taxonomy_setup', 'updateFoxyShopRewrite', 10, 1);
    add_filter('foxyshop_product_tag_taxonomy_setup', 'updateFoxyShopRewrite', 10, 1);

    function updateFoxyShopRewrite($args) {
    $args['rewrite']['with_front'] = false;
    return $args;
    }
    It's still reliant on adding some custom code into your functions.php, but I thought I'd share it in case it's helpful at all.
  • @fc_adam I tried this out and staging and while it Worked for some of the "rewrites" it did not work for project_region. My modified version worked for everything.
  • fc_adamfc_adam FoxyCart Team
    @mdavoli,

    Sorry for the confusion, that's correct. The code I posted would just update the FoxyShop specific aspects, so if you have any custom aspects for your site, like "project_region", that would need to be handled separately.
Sign In or Register to comment.