Thursday, June 9, 2022
HomeWordPress Developmentphp - Change product_base programmatically

php – Change product_base programmatically


I am constructing a plugin that will likely be introducing and managing/dealing with a brand new product kind (like Easy, Variable, and so on), and I wish to additionally change the product_base permalink from product to that new product kind, ie. property.

However within the sense of constructing an entire plugin to deal with all that, I additionally wish to change the default product_base array key saved in woocommerce_permalinks.

The issue is I am undecided what’s the most effective place to hook my code to… If I hook it in init it will be executed on each web page load, in order that’s a complete waste of sources… What’s the most effective place to hook it? My code is not one thing unique, only a easy:

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

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments