Title: How to import rules via function / api
Last modified: April 28, 2022

---

# How to import rules via function / api

 *  Resolved [bobezac](https://wordpress.org/support/users/bobezac/)
 * (@bobezac)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/how-to-import-rules-via-function-api/)
 * Hi,
 * Is there an easy way to programmatically adjust / edit the rules?
 * My site manages prices automatically from an external database and I need to 
   link the bulk discount rules to this, any suggestions?
 * I have found previous mentions of these:
 *     ```
       WDP_Importer::import_rules
       //which appears to be calling
       return \ADP\Factory::callStaticMethod('Admin_Importer', 'importRules', $data, $resetRules);
       ```
   
 * I can’t get either of these functions to accept rule json, they both throw critical
   errors no matter what I pass in, any idea what I’m doing wrong?
 * Kind Regards,
    Bob

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [algol.plus](https://wordpress.org/support/users/algolplus/)
 * (@algolplus)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/how-to-import-rules-via-function-api/#post-15600834)
 * hi
 * try
 *     ```
       use ADP\BaseVersion\Includes\ImportExport\Importer;
       //$data - json , you see it at tab Tools 
       //$resetRules - boolean, set true to reimport all rules
       Importer::importRules($data, $resetRules);
       ```
   
 *  Thread Starter [bobezac](https://wordpress.org/support/users/bobezac/)
 * (@bobezac)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/how-to-import-rules-via-function-api/#post-15602259)
 * Hi, thanks that works to call the function correctly, however I can’t get it 
   to import the rules from the JSON, the JSON I’m parsing works in the “import 
   tool” if I paste it in there, but not when I call it myself in PHP, any ideas
   what I’m doing wrong, does the json need to be decoded before being parsed in
   any way?
 *     ```
       use ADP\BaseVersion\Includes\ImportExport\Importer;
       function test_function_shortcode() {
       	$data = 'the json from exporter';
       	return var_dump(Importer::importRules($data, true));
       }
       ```
   
 *  Thread Starter [bobezac](https://wordpress.org/support/users/bobezac/)
 * (@bobezac)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/how-to-import-rules-via-function-api/#post-15602321)
 * I think I’ve figured it out by reading what the importer is doing, this seems
   to work:
 *     ```
       use ADP\BaseVersion\Includes\ImportExport\Importer;
       function test_function_shortcode() {
       	$data = 'the json from exporter';
       	$data = json_decode(str_replace('\\', '', wp_unslash($data)), true);
       	return var_dump(Importer::importRules($data, true));
       }
       ```
   
 *  Plugin Support [thisisirene](https://wordpress.org/support/users/thisisirene/)
 * (@thisisirene)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/how-to-import-rules-via-function-api/#post-15602505)
 * Hello!
    This code must work fine!
 *  Thread Starter [bobezac](https://wordpress.org/support/users/bobezac/)
 * (@bobezac)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/how-to-import-rules-via-function-api/#post-15603151)
 * Hi, one more question, I believe product only rules have a cache that needs to
   be regenerated? is there a way to call this cache update from php?
 *  Plugin Support [thisisirene](https://wordpress.org/support/users/thisisirene/)
 * (@thisisirene)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/how-to-import-rules-via-function-api/#post-15603188)
 * It is possible, but has some difficulties. Could you [create a ticket via our helpdesk](https://algolplus.freshdesk.com/support/tickets/new),
   and we can help you find a better solution after the holidays?

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘How to import rules via function / api’ is closed to new replies.

 * ![](https://ps.w.org/advanced-dynamic-pricing-for-woocommerce/assets/icon-256x256.
   png?rev=1984204)
 * [Advanced Dynamic Pricing and Discount Rules for WooCommerce](https://wordpress.org/plugins/advanced-dynamic-pricing-for-woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/advanced-dynamic-pricing-for-woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/advanced-dynamic-pricing-for-woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/advanced-dynamic-pricing-for-woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/advanced-dynamic-pricing-for-woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/advanced-dynamic-pricing-for-woocommerce/reviews/)

 * 6 replies
 * 3 participants
 * Last reply from: [thisisirene](https://wordpress.org/support/users/thisisirene/)
 * Last activity: [4 years, 1 month ago](https://wordpress.org/support/topic/how-to-import-rules-via-function-api/#post-15603188)
 * Status: resolved