Title: Rules from database
Last modified: November 24, 2020

---

# Rules from database

 *  Resolved [turnerdyr](https://wordpress.org/support/users/turnerdyr/)
 * (@turnerdyr)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/rules-from-database/)
 * Hello, it’s possible to insert rules from mySQL in wp_wdp_rules?
 * Actually works, but throw some warnings like
 * Warning: reset() expects parameter 1 to be array,
    Parameter must be an array
   or an object that implements Countable and Invalid argument supplied for foreach

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

 *  [missundaztood](https://wordpress.org/support/users/missundaztood/)
 * (@missundaztood)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/rules-from-database/#post-13705775)
 * Hi, turnerdyr,
 * Can you describe in more detail what you want to do and how you do it?
 *  Thread Starter [turnerdyr](https://wordpress.org/support/users/turnerdyr/)
 * (@turnerdyr)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/rules-from-database/#post-13718072)
 * Hello, what I did was simplify the interface because it is not entirely friendly
   and I only need a few options. So what I did was copy the sql queries from the
   database (wdp_rules) and insert them again with the corresponding modifications.
 * For example a random sql bulk
 * INSERT INTO `wp_wdp_rules`(`deleted`, `enabled`, `exclusive`, `type`, `title`,`
   priority`, `options`, `additional`, `conditions`, `filters`, `limits`, `product_adjustments`,`
   sortable_blocks_priority`, `bulk_adjustments`, `role_discounts`, `cart_adjustments`,`
   get_products`) VALUES (0, 1, 0, ‘package’, ‘test’, 0, ‘a:2:{s:6:\”repeat\”;s:
   2:\”-1\”;s:8:\”apply_to\”;s:9:\”expensive\”;}’, ‘a:4:{s:12:\”replace_name\”;s:
   0:\”\”;s:19:\”sortable_apply_mode\”;s:12:\”consistently\”;s:26:\”free_products_replace_name\”;
   s:0:\”\”;s:23:\”conditions_relationship\”;s:3:\”and\”;}’, ‘a:0:{}’, ‘a:0:{}’,‘
   a:0:{}’, ‘a:2:{s:5:\”total\”;a:2:{s:4:\”type\”;s:16:\”discount__amount\”;s:5:\”
   value\”;s:0:\”\”;}s:16:\”max_discount_sum\”;s:0:\”\”;}’, ‘a:2:{i:0;s:5:\”roles\”;
   i:1;s:16:\”bulk-adjustments\”;}’, ‘a:2:{s:4:\”type\”;s:4:\”bulk\”;s:13:\”table_message\”;
   s:0:\”\”;}’, ‘a:0:{}’, ‘a:0:{}’, ‘a:2:{s:6:\”repeat\”;s:2:\”-1\”;s:15:\”repeat_subtotal\”;
   s:0:\”\”;}’);
 * my sql query:
 *  $deleted = 0;
    $enabled = 1; $exclusive = 0; $type = ‘package’; $title = $nombredelapromocion;
   $priority = $prioridad; $options = ‘a:2:{s:6:”repeat”;s:2:”-1″;s:8:”apply_to”;
   s:9:”expensive”;}’; $additional = ‘a:4:{s:12:”replace_name”;s:0:””;s:19:”sortable_apply_mode”;
   s:12:”consistently”;s:26:”free_products_replace_name”;s:0:””;s:23:”conditions_relationship”;
   s:3:”and”;}’; $conditions = ‘a:0:{}’; $filters = ‘a:1:{i:0;a:5:{s:3:”qty”;s:1:”
   1″;s:4:”type”;s:8:”products”;s:10:”limitation”;s:4:”none”;s:6:”method”;s:7:”in_list”;
   s:5:”value”;a:1:{i:0;s:4:”‘.$idproducto.'”;}}}’; $limits = ‘a:0:{}’; $product_adjustments
   = ‘a:3:{s:5:”total”;a:2:{s:4:”type”;s:16:”discount__amount”;s:5:”value”;s:0:””;}
   s:5:”split”;a:1:{i:0;a:2:{s:4:”type”;s:16:”discount__amount”;s:5:”value”;s:0:””;}}
   s:16:”max_discount_sum”;s:0:””;}’; $sortable_blocks_priority = ‘a:2:{i:0;s:5:”
   roles”;i:1;s:16:”bulk-adjustments”;}’; $bulk_adjustments = ‘a:5:{s:4:”type”;s:
   4:”bulk”;s:9:”qty_based”;s:3:”all”;s:13:”discount_type”;s:20:”discount__percentage”;
   s:6:”ranges”;a:1:{i:0;a:3:{s:4:”from”;s:1:”‘.$cantidadminimadelapromocion.'”;
   s:2:”to”;s:5:”10000″;s:5:”value”;s:2:”‘.$descuentodelapromocion.'”;}}s:13:”table_message”;
   s:0:””;}’; $role_discounts = ‘a:0:{}’; $cart_adjustments = ‘a:0:{}’; $get_products
   = ‘a:2:{s:6:”repeat”;s:2:”-1″;s:15:”repeat_subtotal”;s:0:””;}’;
 *  $sql = “INSERT INTO `wp_wdp_rules`(`deleted`, `enabled`, `exclusive`, `type`,`
   title`, `priority`, `options`, `additional`, `conditions`, `filters`, `limits`,`
   product_adjustments`, `sortable_blocks_priority`, `bulk_adjustments`, `role_discounts`,`
   cart_adjustments`, `get_products`) VALUES ($deleted, $enabled, $exclusive, ‘$
   type’, ‘$title’, $priority, ‘$options’, ‘$additional’, ‘$conditions’, ‘$filters’,‘
   $limits’, ‘$product_adjustments’, ‘$sortable_blocks_priority’, ‘$bulk_adjustments’,‘
   $role_discounts’, ‘$cart_adjustments’, ‘$get_products’)”;
    mysqli_query($conn,
   $sql);
 * With this I get the same query but for some reason it doesn’t work
 *  Thread Starter [turnerdyr](https://wordpress.org/support/users/turnerdyr/)
 * (@turnerdyr)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/rules-from-database/#post-13718170)
 * i think i figured out, in bulk adjusment:
 * a:2:{i:0;s:5:”roles”;i:1;s:16:”bulk-adjustments”;}’;
    $bulk_adjustments = ‘a:
   5:{s:4:”type”;s:4:”bulk”;s:9:”qty_based”;s:3:”all”;s:13:”discount_type”;s:20:”
   discount__percentage”;s:6:”ranges”;a:1:{i:0;a:3:{s:4:”from”;**s:1**:”‘.$cantidadminimadelapromocion.'”;
   s:2:”to”;s:5:”10000″;s:5:”value”;s:2:”‘.$descuentodelapromocion.'”;}}s:13:”table_message”;
   s:0:””;}
 * s:1 it’s not working but if i change for s:2 it does. ¿why?¿this number changes?
 *  Thread Starter [turnerdyr](https://wordpress.org/support/users/turnerdyr/)
 * (@turnerdyr)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/rules-from-database/#post-13718353)
 * Yes, i figured out.
 * from s:1 is the str len of minium qty
    s:5 the same str len of maximum qty s:
   2 str len of %
 * (You have to modify that parameters in the sql query too)
    Thanks.
    -  This reply was modified 5 years, 4 months ago by [turnerdyr](https://wordpress.org/support/users/turnerdyr/).
 *  Plugin Author [algol.plus](https://wordpress.org/support/users/algolplus/)
 * (@algolplus)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/rules-from-database/#post-13719054)
 * Hello
 * You should use PHP function **serialize**
 * open file /BaseVersion/Includes/Common/Datavase.php and review **ajax_save_rule()**
 * thanks, Alex

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

The topic ‘Rules from database’ 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/)

 * 5 replies
 * 3 participants
 * Last reply from: [algol.plus](https://wordpress.org/support/users/algolplus/)
 * Last activity: [5 years, 4 months ago](https://wordpress.org/support/topic/rules-from-database/#post-13719054)
 * Status: resolved