Advertisement
Guest User

Conditional logic not working for nested items in repeating group

a guest
Sep 22nd, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.80 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Single product fields define
  4.  *
  5.  * @param array $meta_boxes metaboxes.
  6.  */
  7. function my_product_fields( $meta_boxes ) {
  8.     $fields = array(
  9.         array(
  10.             'name'    => __( 'Section' ),
  11.             'id'      => 'section',
  12.             'type'    => 'select',
  13.  
  14.             'options' => array(
  15.                 'select'       => __( 'Select' ),
  16.                 'product_info' => __( 'Product Info' ),
  17.                 'pricing'      => __( 'Pricing' ),
  18.             ),
  19.         ),
  20.     );
  21.  
  22.     $fields[] = array(
  23.         'id'      => 'product_info',
  24.         'type'    => 'group',
  25.  
  26.         'visible' => array( 'section', '=', 'product_info' ),
  27.  
  28.         'fields'  => array(
  29.             array(
  30.                 'id'          => 'infos',
  31.                 'type'        => 'group',
  32.                 'clone'       => true,
  33.                 'sort_clone'  => true,
  34.                 'collapsible' => true,
  35.                 'save_state'  => true,
  36.                 'group_title' => __( 'Item' ) . ' - {title}',
  37.                 'add_button'  => __( 'Add Item' ),
  38.  
  39.                 'fields'      => array(
  40.                     array(
  41.                         'name' => __( 'Title' ),
  42.                         'id'   => 'title',
  43.                         'type' => 'text',
  44.  
  45.                         'size' => 60,
  46.                     ),
  47.                     array(
  48.                         'name' => __( 'Description' ),
  49.                         'id'   => 'desc',
  50.                         'type' => 'text',
  51.  
  52.                         'size' => 100,
  53.                     ),
  54.                 ),
  55.             ),
  56.         ),
  57.     );
  58.  
  59.     $fields[] = array(
  60.         'id'      => 'pricing',
  61.         'type'    => 'group',
  62.  
  63.         'visible' => array( 'section', '=', 'pricing' ),
  64.  
  65.         'fields'  => array(
  66.             array(
  67.                 'name'    => __( 'Type' ),
  68.                 'id'      => 'pricing_type',
  69.                 'type'    => 'select',
  70.  
  71.                 'options' => array(
  72.                     'simple' => __( 'Simple' ),
  73.                     'table'  => __( 'Table' ),
  74.                 ),
  75.             ),
  76.             array(
  77.                 'name'    => __( 'Enable Icons' ),
  78.                 'id'      => 'pricing_enable_icons',
  79.                 'type'    => 'switch',
  80.  
  81.                 'visible' => array( 'pricing_type', '=', 'table' ),
  82.             ),
  83.             array(
  84.                 'name' => __( 'Title' ),
  85.                 'id'   => 'title',
  86.                 'type' => 'text',
  87.  
  88.                 'size' => 60,
  89.             ),
  90.             array(
  91.                 'name' => __( 'Description' ),
  92.                 'id'   => 'desc',
  93.                 'type' => 'text',
  94.  
  95.                 'size' => 80,
  96.             ),
  97.             array(
  98.                 'name' => __( 'Enable separate pricing' ),
  99.                 'id'   => 'seperate_pricing',
  100.                 'type' => 'switch',
  101.             ),
  102.             array(
  103.                 'name'   => __( 'Price suffix' ),
  104.                 'id'     => 'price_suffix',
  105.                 'type'   => 'text',
  106.  
  107.                 'hidden' => array( 'seperate_pricing', true ),
  108.             ),
  109.             array(
  110.                 'name'    => __( 'Price Monthly suffix' ),
  111.                 'id'      => 'price_monthly_suffix',
  112.                 'type'    => 'text',
  113.  
  114.                 'columns' => 3,
  115.                 'visible' => array( 'seperate_pricing', true ),
  116.             ),
  117.             array(
  118.                 'name'    => __( 'Price Yearly suffix' ),
  119.                 'id'      => 'price_yearly_suffix',
  120.                 'type'    => 'text',
  121.  
  122.                 'columns' => 3,
  123.                 'visible' => array( 'seperate_pricing', true ),
  124.             ),
  125.             array(
  126.                 'name'        => __( 'Plan Features' ),
  127.                 'id'          => 'plan_features',
  128.                 'type'        => 'group',
  129.  
  130.                 'clone'       => true,
  131.                 'sort_clone'  => true,
  132.                 'collapsible' => true,
  133.                 'save_state'  => true,
  134.                 'group_title' => '{#}. ' . __( 'Feature' ) . ' - {name}',
  135.                 'add_button'  => __( 'Add Feature' ),
  136.  
  137.                 'hidden'      => array( 'pricing_type', '=', 'simple' ),
  138.  
  139.                 'fields'      => array(
  140.                     array(
  141.                         'name'     => __( 'Name' ),
  142.                         'id'       => 'name',
  143.                         'type'     => 'text',
  144.  
  145.                         'size'     => 80,
  146.  
  147.                         'required' => true,
  148.                     ),
  149.                     array(
  150.                         'name'    => __( 'Icons' ),
  151.                         'id'      => 'icons',
  152.                         'type'    => 'image_advanced',
  153.  
  154.                         'visible' => array( 'pricing_enable_icons', true ),
  155.                     ),
  156.                     array(
  157.                         'name' => __( 'Sub features' ),
  158.                         'id'   => 'sub_features',
  159.                         'type' => 'image_advanced',
  160.                     ),
  161.                 ),
  162.             ),
  163.             array(
  164.                 'name'        => __( 'Plans' ),
  165.                 'id'          => 'plans',
  166.                 'type'        => 'group',
  167.  
  168.                 'clone'       => true,
  169.                 'sort_clone'  => true,
  170.                 'collapsible' => true,
  171.                 'save_state'  => true,
  172.                 'group_title' => __( 'Plan' ) . ' - {title}',
  173.                 'add_button'  => __( 'Add Plan' ),
  174.  
  175.                 'fields'      => array(
  176.                     array(
  177.                         'name' => __( 'Title' ),
  178.                         'id'   => 'title',
  179.                         'type' => 'text',
  180.  
  181.                         'size' => 40,
  182.                     ),
  183.                     array(
  184.                         'name'    => __( 'Price prefix' ),
  185.                         'id'      => 'price_prefix',
  186.                         'type'    => 'text',
  187.  
  188.                         'columns' => 3,
  189.                     ),
  190.                     array(
  191.                         'name'     => __( 'Price' ),
  192.                         'id'       => 'price',
  193.                         'type'     => 'number',
  194.  
  195.                         'step'     => 0.01,
  196.  
  197.                         'required' => true,
  198.                         'columns'  => 3,
  199.                         'hidden'   => array( 'seperate_pricing', true ),
  200.                     ),
  201.                     array(
  202.                         'name'     => __( 'Price monthly' ),
  203.                         'id'       => 'price_monthly',
  204.                         'type'     => 'number',
  205.  
  206.                         'step'     => 0.01,
  207.  
  208.                         'required' => true,
  209.                         'columns'  => 3,
  210.                         'visible'  => array( 'seperate_pricing', true ),
  211.                     ),
  212.                     array(
  213.                         'name'     => __( 'Price yearly' ),
  214.                         'id'       => 'price_yearly',
  215.                         'type'     => 'number',
  216.  
  217.                         'step'     => 0.01,
  218.  
  219.                         'required' => true,
  220.                         'columns'  => 3,
  221.                         'visible'  => array( 'seperate_pricing', true ),
  222.                     ),
  223.                     array(
  224.                         'id'      => 'btn',
  225.                         'type'    => 'group',
  226.  
  227.                         'visible' => array( 'pricing_type', '=', 'simple' ),
  228.  
  229.                         'fields'  => array(
  230.                             array(
  231.                                 'name' => __( 'Label' ),
  232.                                 'id'   => 'label',
  233.                                 'type' => 'text',
  234.                             ),
  235.                             array(
  236.                                 'name' => __( 'URL' ),
  237.                                 'id'   => 'url',
  238.                                 'type' => 'text',
  239.                             ),
  240.                         ),
  241.                     ),
  242.                     array(
  243.                         'id'          => 'features',
  244.                         'type'        => 'group',
  245.  
  246.                         'clone'       => true,
  247.                         'sort_clone'  => true,
  248.                         'collapsible' => true,
  249.                         'save_state'  => true,
  250.                         'group_title' => '{#}. ' . __( 'Feature' ),
  251.                         'add_button'  => __( 'Add Feature' ),
  252.  
  253.                         'visible'     => array( 'pricing_type', '=', 'table' ),
  254.  
  255.                         'fields'      => array(
  256.                             array(
  257.                                 'name'    => __( 'Checked' ),
  258.                                 'id'      => 'checked',
  259.                                 'type'    => 'switch',
  260.  
  261.                                 'visible' => array( 'pricing_enable_icons', true ),
  262.                             ),
  263.                             array(
  264.                                 'name' => __( 'Description' ),
  265.                                 'id'   => 'desc',
  266.                                 'type' => 'text',
  267.  
  268.                                 'size' => 60,
  269.                             ),
  270.                             array(
  271.                                 'id'          => 'sub_features',
  272.                                 'type'        => 'group',
  273.  
  274.                                 'clone'       => true,
  275.                                 'sort_clone'  => true,
  276.                                 'collapsible' => true,
  277.                                 'save_state'  => true,
  278.                                 'group_title' => __( 'Sub Feature' ),
  279.                                 'add_button'  => __( 'Add Sub Feature' ),
  280.  
  281.                                 'visible'     => array( 'pricing_enable_icons', true ),
  282.  
  283.                                 'fields'      => array(
  284.                                     array(
  285.                                         'name' => __( 'Checked' ),
  286.                                         'id'   => 'checked',
  287.                                         'type' => 'switch',
  288.                                     ),
  289.                                 ),
  290.                             ),
  291.                         ),
  292.                     ),
  293.                 ),
  294.             ),
  295.             array(
  296.                 'id'          => 'btn_compare',
  297.                 'type'        => 'group',
  298.  
  299.                 'collapsible' => true,
  300.                 'group_title' => __( 'Compare Link' ),
  301.  
  302.                 'visible'     => array( 'pricing_type', '=', 'simple' ),
  303.  
  304.                 'fields'      => array(
  305.                     array(
  306.                         'name' => __( 'Label' ),
  307.                         'id'   => 'label',
  308.                         'type' => 'text',
  309.                     ),
  310.                     array(
  311.                         'name' => __( 'URL' ),
  312.                         'id'   => 'url',
  313.                         'type' => 'text',
  314.                     ),
  315.                 ),
  316.             ),
  317.         ),
  318.     );
  319.  
  320.     // Section.
  321.     $meta_boxes[] = array(
  322.         'id'         => 'box_product_sections',
  323.         'title'      => __( 'Sections' ),
  324.         'post_types' => array( 'product' ),
  325.         'context'    => 'after_editor',
  326.         'priority'   => 'high',
  327.         'style'      => 'seamless',
  328.         'fields'     => array(
  329.             array(
  330.                 'id'          => 'sections',
  331.                 'type'        => 'group',
  332.  
  333.                 'clone'       => true,
  334.                 'sort_clone'  => true,
  335.                 'collapsible' => true,
  336.                 'save_state'  => true,
  337.                 'group_title' => __( 'Section' ) . ' - {section}',
  338.                 'add_button'  => __( 'Add Section' ),
  339.  
  340.                 'fields'      => $fields,
  341.             ),
  342.         ),
  343.     );
  344.  
  345.     return $meta_boxes;
  346. }
  347. add_filter( 'rwmb_meta_boxes', 'my_product_fields' );
  348.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement