'content', 'title' => esc_html__( 'Advanced Woo Labels', 'advanced-woo-labels' ), ); return $control_groups; } /* * Add new controls for woocommerce-products element */ public function bricks_controls( $controls ) { $controls['awl_disable'] = array( 'tab' => 'content', 'group' => 'awl', 'label' => esc_html__( 'Disable labels', 'advanced-woo-labels' ), 'type' => 'checkbox' ); return $controls; } public function bricks_html_after_begin( $html_after_begin, $bricks_data ) { $this->data['show_labels'] = true; if ( $bricks_data ) { foreach ( $bricks_data as $element_data ) { if ( isset( $element_data['name'] ) && $element_data['name'] === 'woocommerce-products' ) { $this->data['is_bricks'] = true; if ( isset( $element_data['settings'] ) && isset( $element_data['settings']['awl_disable'] ) && $element_data['settings']['awl_disable'] ) { $this->data['show_labels'] = false; } break; } } } return $html_after_begin; } public function bricks_html_before_end( $html_before_end, $bricks_data ) { $this->data['show_labels'] = true; if ( $bricks_data ) { foreach ( $bricks_data as $element_data ) { if ( isset( $element_data['name'] ) && $element_data['name'] === 'woocommerce-products' ) { $this->data['is_bricks'] = false; break; } } } return $html_before_end; } /* * Add new label conditions for admin */ public function label_rules( $options ) { $options['Special'][] = array( "name" => __( "Bricks: Is WooCommerce block", "advanced-woo-labels" ), "id" => "awl_is_bricks", "type" => "bool", "operators" => "equals", ); return $options; } /* * Add custom condition rule method */ public function condition_rules( $rules ) { $rules['awl_is_bricks'] = array( $this, 'awl_is_bricks' ); return $rules; } /* * Condition: Is Bricks WooCommerce products element */ public function awl_is_bricks( $condition_rule ) { global $product; $match = false; $operator = $condition_rule['operator']; $value = $condition_rule['value']; $compare_value = 'false'; if ( isset( $this->data['is_bricks'] ) && $this->data['is_bricks'] ) { $compare_value = 'true'; } if ( 'equal' == $operator ) { $match = ($compare_value == $value); } elseif ( 'not_equal' == $operator ) { $match = ($compare_value != $value); } return $match; } /* * Enable or not products labels */ public function disable_labels( $disable, $product ) { if ( isset( $this->data['show_labels'] ) && ! $this->data['show_labels'] ) { $disable = true; } return $disable; } } endif; AWL_Bricks::instance();