SHOW:
|
|
- or go back to the newest paste.
| 1 | - | function pm_set_custom_permalink($post_id, $post, $update) {
|
| 1 | + | function pm_set_custom_permalink($product_id) {
|
| 2 | global $permalink_manager_uris; | |
| 3 | ||
| 4 | - | // Do not trigger when the post is updated |
| 4 | + | if(!empty($permalink_manager_uris) && empty($permalink_manager_uris[$product_id])) {
|
| 5 | - | if($update) { return; }
|
| 5 | + | $default_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($product_id); |
| 6 | ||
| 7 | - | // Do not do anything if post is autosaved |
| 7 | + | if($default_uri) {
|
| 8 | - | if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; }
|
| 8 | + | Permalink_Manager_URI_Functions::save_single_uri($product_id, $default_uri, false, true); |
| 9 | } | |
| 10 | - | // Ignore auto-drafts & removed posts |
| 10 | + | |
| 11 | - | if(in_array($post->post_status, array('auto-draft', 'trash'))) { return; }
|
| 11 | + | |
| 12 | add_action('woocommerce_api_create_product', 'pm_set_custom_permalink', 100); |