Guest User

Untitled

a guest
Jul 16th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. /**
  2. * Beaver Themer: WooCommeece Module:
  3. * Single category archive page template for WooCommerce
  4. *
  5. * You get a checkbox saying autoselect parent,
  6. * when it's set to true, the parent_id field gets hidden
  7. * and the parent_id will be automatically set, when it's false the user can enter a parent_id
  8. */
  9.  
  10. add_filter('fl_builder_before_render_module', function($module) {
  11. if ('woocommerce' === $module->slug && 'categories' === $module->settings->layout && 'true' === $module->settings->autoparent) {
  12. $term_id = get_queried_object_id();
  13. $module->settings->parent_cat_id = $term_id;
  14. }
  15. }, 10, 2);
  16.  
  17. add_filter('fl_builder_register_settings_form', function($form, $slug) {
  18. if ( 'woocommerce' === $slug ) {
  19. $form['general']['sections']['general']['fields']['autoparent'] = [
  20. 'type' => 'select',
  21. 'label' => __('Autoselect Parent', 'wpd'),
  22. 'default' => 'true',
  23. 'options' => array(
  24. 'true' => __('true', 'wpd'),
  25. 'false' => __('false', 'wpd')
  26. ),
  27. 'toggle' => [
  28. 'false' => [
  29. 'fields' => ['parent_cat_id']
  30. ]
  31. ]
  32. ];
  33. $form['general']['sections']['general']['fields']['layout']['toggle']['categories']['fields'] = array( 'parent_cat_id', 'cat_columns', 'autoparent' );
  34. }
  35.  
  36. return $form;
  37. }, 10, 2);
Add Comment
Please, Sign In to add comment