php – Change product_base programmatically

Question

I’m building a plugin that will be introducing and managing/handling a new product type (like Simple, Variable, etc), and I want to also change the product_base permalink from product to that new product type, ie. property.

But in the sense of building a whole plugin to handle all that, I also want to change the default product_base array key stored in woocommerce_permalinks.

The problem is I’m not sure what’s the best place to hook my code to… If I hook it in init it’ll be executed on every page load, so that’s a total waste of resources… What’s the best place to hook it? My code isn’t something exotic, just a simple:

 if( $permalinks = get_option( 'woocommerce_permalinks' ) ) {
    $permalinks['product_base'] = 'property';
    update_option( 'woocommerce_permalinks', $permalinks );
    flush_rewrite_rules();
 }

0
vancoder 2 months 2022-06-08T16:57:37-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse