Support » Plugin: Permalink Manager Lite » Creating product with dokan, ends to unruled URI

  • Resolved dvdufo

    (@dvdufo)


    Hi and really thank you for this superb plugin.

    My website setting is configured to show as follow:
    http://www.mywebsite.com/main-category/sub-category/product-name

    It is OK with adding product from woocommerce.
    But when adding a new product from dokan, urls become as:
    http://www.mywebsite.com/product-name

    Changing category and updating product doesn’t correct the issue.
    I changed dokan user role to administrator too, ut still no difference.

    Can anyone please help me.
    I’m going to give permission to some people to add product from dokan dashboard.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter dvdufo

    (@dvdufo)

    Or is it possible to make the plugin check and fix only newly added product URIs within for example every 3 hour intervals instead of 24hrs?
    in settings, there’s an item “Automatically fix broken URIs” that has “bulk fix all URIs, once a day”. I need smaller interval and only to process products added within recent hours.

    Plugin Author Maciej Bis

    (@mbis)

    Hi @dvdufo,

    According to what you have mentioned, the function used by my plugin to generate the custom permalink appears to be executed just before the product categories are assigned to the product. As a result, the product categories are not included in the URL created. To resolve this issue, you may use one of Dokan’s hooks to have Permalink Manager update the URL when the categories are provided.

    Could you try to paste the below snippet into functions.php in child theme directory? If you are not certain how to use it, please check this article:
    https://permalinkmanager.pro/blog/how-to-add-php-snippet-to-wordpress-3-methods/#2-how-to-insert-php-code-in-wordpress-without-plugin

    function pm_dokan_generate_product_permalink($product_id) {
    	if(class_exists('Permalink_Manager_URI_Functions_Post')) {
    		$new_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($post);
    		Permalink_Manager_URI_Functions::save_single_uri($post_id, $new_uri, false, true);
    	}
    }
    add_action('dokan_new_product_added', 'pm_dokan_generate_product_permalink', 100);

    Best regards,
    Maciej

    Thread Starter dvdufo

    (@dvdufo)

    Thanks for your quick answer and pardon me for late reply. I was checking different things to make it done but to be honest, the code didn’t change the result for me after I entered it in function.php
    I even deactivated all my plugins except woocommerce, elementor, dokan and permalink manager to avoid any plugin conflict but still I end with the previous result.
    Anyway, at last I used another permalink plugin and it worked for me with dokan.
    It has not all the functions that your plugin has, but for now it is enough for me.
    Thanks a lot.
    Have a great day.

    Plugin Author Maciej Bis

    (@mbis)

    Hi again @dvdufo,

    I just double-checked the snippet I gave you and identified the issue. Could you try to replace it with the new version?

    function pm_dokan_generate_product_permalink($product_id) {
    	if(class_exists('Permalink_Manager_URI_Functions_Post')) {
    		$new_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($product_id);
    
    		Permalink_Manager_URI_Functions::save_single_uri($product_id, $new_uri, false, true);
    	}
    }
    add_action('dokan_new_product_added', 'pm_dokan_generate_product_permalink', 100);
    Thread Starter dvdufo

    (@dvdufo)

    Hi dear @mbis

    I reverted everything to previous condition and checked your given code.

    with your new code: when I create a product with dokan, it becomes OK (URI is as expected). but with changing category of the product and updating changes, URI stays as it was (URI don’t change to new category)

    without your code: Creating a product with dokan or changing category and updating changes, both are the same and URI is always as following: http://www.mywebsite.com/product-name

    Anyway, I appreciate your efforts. Don’t bother yourself more, I have solved my issue with other plugin and codes. Thank you so much.

    Plugin Author Maciej Bis

    (@mbis)

    Hi @dvdufo,

    There is no problem at all. You can use the hook triggered after the product category is set (or changed again) to make Permalink Manager regenerate the custom permalink again:

    function pm_update_post_terms($object_id, $terms, $tt_ids, $taxonomy) {
      // Trigger only for selected taxonomies
      if(!in_array($taxonomy, array('product_cat'))) { return; }
    
    	$new_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($object_id);
    	Permalink_Manager_URI_Functions::save_single_uri($object_id, $new_uri, false, true);
    }
    add_action('set_object_terms', 'pm_update_post_terms', 9, 4);

    Best regards,
    Maciej

    Thread Starter dvdufo

    (@dvdufo)

    Hi and thank you the great savior @mbis

    This code worked like a charm.
    Your plugin is not comparable to similar permalink plugins for sure. Great functions and greater support.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.