Advertisement
webexpert

Berocket Filter

Sep 21st, 2021
1,814
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.66 KB | None | 0 0
  1. <?php
  2. require_once "wp-load.php";
  3. if ( ! function_exists( 'post_exists' ) ) {
  4.     require_once( ABSPATH . 'wp-admin/includes/post.php' );
  5. }
  6.  
  7. function create_new_br_product_filter($post_title,$args=[]) {
  8.     $defaults=array (
  9.         'data' =>
  10.             array (
  11.             ),
  12.         'br_wp_footer' => '',
  13.         'widget_type' => 'filter',
  14.         'reset_hide' => '',
  15.         'title' => '',
  16.         'filter_type' => 'attribute',
  17.         'attribute' => '',
  18.         'custom_taxonomy' => '',
  19.         'type' => '',
  20.         'select_first_element_text' => '',
  21.         'operator' => 'OR',
  22.         'order_values_by' => '',
  23.         'order_values_type' => 'asc',
  24.         'text_before_price' => '',
  25.         'text_after_price' => '',
  26.         'enable_slider_inputs' => '',
  27.         'parent_product_cat' => '',
  28.         'depth_count' => '',
  29.         'widget_collapse_enable' => '',
  30.         'widget_is_hide' => '',
  31.         'show_product_count_per_attr' => '',
  32.         'hide_child_attributes' => '',
  33.         'hide_collapse_arrow' => '',
  34.         'use_value_with_color' => '',
  35.         'values_per_row' => '',
  36.         'icon_before_title' => '',
  37.         'icon_after_title' => '',
  38.         'icon_before_value' => '',
  39.         'icon_after_value' => '',
  40.         'price_values' => '',
  41.         'description' => '',
  42.         'css_class' => '',
  43.         'use_min_price' => '',
  44.         'min_price' => '',
  45.         'use_max_price' => '',
  46.         'max_price' => '',
  47.         'height' => 'auto',
  48.         'scroll_theme' => 'dark',
  49.         'selected_area_show' => '',
  50.         'hide_selected_arrow' => '',
  51.         'selected_is_hide' => '',
  52.         'slider_default' => '',
  53.         'number_style' => '',
  54.         'number_style_thousand_separate' => '',
  55.         'number_style_decimal_separate' => '.',
  56.         'number_style_decimal_number' => '2',
  57.         'is_hide_mobile' => '',
  58.         'user_can_see' => '',
  59.         'cat_propagation' => '',
  60.         'product_cat' => '',
  61.         'parent_product_cat_current' => '',
  62.         'attribute_count' => '',
  63.         'child_parent' => '',
  64.         'child_parent_depth' => '',
  65.         'child_parent_no_values' => '',
  66.         'child_parent_previous' => '',
  67.         'child_parent_no_products' => '',
  68.         'child_onew_count' => '',
  69.         'child_onew_childs' =>
  70.             array (
  71.                 1 =>
  72.                     array (
  73.                         'title' => '',
  74.                         'no_product' => '',
  75.                         'no_values' => '',
  76.                         'previous' => '',
  77.                     ),
  78.                 2 =>
  79.                     array (
  80.                         'title' => '',
  81.                         'no_product' => '',
  82.                         'no_values' => '',
  83.                         'previous' => '',
  84.                     ),
  85.                 3 =>
  86.                     array (
  87.                         'title' => '',
  88.                         'no_product' => '',
  89.                         'no_values' => '',
  90.                         'previous' => '',
  91.                     ),
  92.                 4 =>
  93.                     array (
  94.                         'title' => '',
  95.                         'no_product' => '',
  96.                         'no_values' => '',
  97.                         'previous' => '',
  98.                     ),
  99.                 5 =>
  100.                     array (
  101.                         'title' => '',
  102.                         'no_product' => '',
  103.                         'no_values' => '',
  104.                         'previous' => '',
  105.                     ),
  106.                 6 =>
  107.                     array (
  108.                         'title' => '',
  109.                         'no_product' => '',
  110.                         'no_values' => '',
  111.                         'previous' => '',
  112.                     ),
  113.                 7 =>
  114.                     array (
  115.                         'title' => '',
  116.                         'no_product' => '',
  117.                         'no_values' => '',
  118.                         'previous' => '',
  119.                     ),
  120.                 8 =>
  121.                     array (
  122.                         'title' => '',
  123.                         'no_product' => '',
  124.                         'no_values' => '',
  125.                         'previous' => '',
  126.                     ),
  127.                 9 =>
  128.                     array (
  129.                         'title' => '',
  130.                         'no_product' => '',
  131.                         'no_values' => '',
  132.                         'previous' => '',
  133.                     ),
  134.                 10 =>
  135.                     array (
  136.                         'title' => '',
  137.                         'no_product' => '',
  138.                         'no_values' => '',
  139.                         'previous' => '',
  140.                     ),
  141.             ),
  142.         'search_box_link_type' => '',
  143.         'search_box_url' => '',
  144.         'search_box_category' => '',
  145.         'search_box_count' => '',
  146.         'search_box_attributes' =>
  147.             array (
  148.                 1 =>
  149.                     array (
  150.                         'type' => '',
  151.                         'attribute' => '',
  152.                         'custom_taxonomy' => '',
  153.                         'title' => '',
  154.                         'visual_type' => '',
  155.                     ),
  156.                 2 =>
  157.                     array (
  158.                         'type' => '',
  159.                         'attribute' => '',
  160.                         'custom_taxonomy' => '',
  161.                         'title' => '',
  162.                         'visual_type' => '',
  163.                     ),
  164.                 3 =>
  165.                     array (
  166.                         'type' => '',
  167.                         'attribute' => '',
  168.                         'custom_taxonomy' => '',
  169.                         'title' => '',
  170.                         'visual_type' => '',
  171.                     ),
  172.                 4 =>
  173.                     array (
  174.                         'type' => '',
  175.                         'attribute' => '',
  176.                         'custom_taxonomy' => '',
  177.                         'title' => '',
  178.                         'visual_type' => '',
  179.                     ),
  180.                 5 =>
  181.                     array (
  182.                         'type' => '',
  183.                         'attribute' => '',
  184.                         'custom_taxonomy' => '',
  185.                         'title' => '',
  186.                         'visual_type' => '',
  187.                     ),
  188.                 6 =>
  189.                     array (
  190.                         'type' => '',
  191.                         'attribute' => '',
  192.                         'custom_taxonomy' => '',
  193.                         'title' => '',
  194.                         'visual_type' => '',
  195.                     ),
  196.                 7 =>
  197.                     array (
  198.                         'type' => '',
  199.                         'attribute' => '',
  200.                         'custom_taxonomy' => '',
  201.                         'title' => '',
  202.                         'visual_type' => '',
  203.                     ),
  204.                 8 =>
  205.                     array (
  206.                         'type' => '',
  207.                         'attribute' => '',
  208.                         'custom_taxonomy' => '',
  209.                         'title' => '',
  210.                         'visual_type' => '',
  211.                     ),
  212.                 9 =>
  213.                     array (
  214.                         'type' => '',
  215.                         'attribute' => '',
  216.                         'custom_taxonomy' => '',
  217.                         'title' => '',
  218.                         'visual_type' => '',
  219.                     ),
  220.                 10 =>
  221.                     array (
  222.                         'type' => '',
  223.                         'attribute' => '',
  224.                         'custom_taxonomy' => '',
  225.                         'title' => '',
  226.                         'visual_type' => '',
  227.                     ),
  228.             ),
  229.         'search_box_style' =>
  230.             array (
  231.                 'position' => '',
  232.                 'search_position' => '',
  233.                 'search_text' => '',
  234.                 'background' => '',
  235.                 'back_opacity' => '',
  236.                 'button_background' => '',
  237.                 'button_background_over' => '',
  238.                 'text_color' => '',
  239.                 'text_color_over' => '',
  240.             ),
  241.         'ranges' =>
  242.             array (
  243.                 0 => '',
  244.                 1 => '',
  245.             ),
  246.         'hide_first_last_ranges' => '',
  247.         'include_exclude_select' => '',
  248.         'include_exclude_list' =>
  249.             array (
  250.             ),
  251.         'version' => '1.0',
  252.         'filter_title' => $post_title,
  253.         'cat_value_limit' => '',
  254.         'style' => 'divi_checkbox',
  255.         'widget_collapse' => '',
  256.         'attribute_count_show_hide' => '',
  257.         'custom_price_ranges_text' => '',
  258.     );
  259.  
  260.     $args=array_merge($defaults,$args);
  261.     $fount_post = post_exists( $post_title,'','','br_product_filter');
  262.  
  263.     if ($fount_post===0) {
  264.         $post_id = wp_insert_post(array(
  265.             'post_title'    => $post_title,
  266.             'post_content'  => '',
  267.             'post_type'     => 'br_product_filter',
  268.             'post_status'   => 'publish'
  269.         ));
  270.  
  271.         if (!is_wp_error($post_id)) {
  272.             update_post_meta($post_id,'br_product_filter',$args);
  273.         }
  274.     }else {
  275.         echo "Filter $post_title exists";
  276.         $post_id=$fount_post;
  277.     }
  278.  
  279.     return $post_id;
  280. }
  281.  
  282. // create filter
  283. $br_filter_id=create_new_br_product_filter('Test filter',[
  284.     'filter_type' => 'attribute',
  285.     'attribute' => 'pa_test',
  286. ]);
  287.  
  288. // assign filter to existing group
  289. $br_filters_group_id=385;
  290. $br_filters_group_meta=get_post_meta($br_filters_group_id,'br_filters_group',true);
  291.  
  292. if (!in_array($br_filter_id,$br_filters_group_meta['filters'])) {
  293.     array_push($br_filters_group_meta['filters'],$br_filter_id);
  294. }
  295. update_post_meta($br_filters_group_id,'br_filters_group',$br_filters_group_meta);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement