CodeWP

Introducing The Oxygen Builder Conditions Mode for CodeWP

By James LePage, CodeWP Founder
November 27, 2022
Contents

We're excited to announce a new mode, now available for public alpha testing: Oxygen Builder Conditions.

Oxygen Builder is a powerful page builder for WordPress. One of its features is conditional visibility - depending on specific conditions "ie, if the user is logged in", you can show/hide content. This is great for creating highly dynamic websites.

With CodeWP, you can now prompt for a custom Oxygen Builder Condition generation. This mode will generate a code snippet (using Oxygen's Conditions API) that adds a custom condition to the Oxygen Builder

  1. Ask for the condition you want in plain English
  2. Get the code generated and install it on your (staging first) site
  3. Use the new, custom condition WITHOUT needing to code anything

This platform is in it's alpha testing phase. You can access it free for the duration of the testing period by: 1) signing up, 2) clicking 5 day free trial, 3) entering code isotropic_alpha.

Already Logged In? Click Here To Launch Oxygen Conditions Mode

Please note: You MUST trigger the Conditions PHP at init. Including it in a custom plugin or snippet management tool without hooking into init won't work.

This mode is ever-improving and learns from your generation rankings. To benefit everybody, please rate generations:

Learn about why this is important

Oxygen Builder Conditions Mode Prompt Examples

Let's take a look at some real world Oxygen Builder Conditions, generated by CodeWP.

Be sure that you've switched into the "Oxygen Conditions" mode, as the general modes will not produce accurate results.

Prompt: check if post has specific heading type in content

if( function_exists('oxygen_vsb_register_condition') ) { oxygen_vsb_register_condition('Heading Type', array('options'=>array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'), 'custom'=>false), array('==', '!='), 'ex_condition_heading_type_callback', 'Post'); function ex_condition_heading_type_callback($value, $operator) { global $post; $content = $post->post_content; $pattern = '/<'.$value.'[^>]*>/'; preg_match_all($pattern, $content, $matches); if($operator == '==') { return (count($matches[0]) > 0); } else { return (count($matches[0]) == 0); } } } Generation ID:cmpl-6GYsWQgsL637gMUSZmtCdLWyzLluI

This snippet checks if the content of a post contains a specific type of heading, ie H2 or H5. This was generated for this blog and is used to show/hide the table of contents to the left, if the post doesn't contain a H2 element.

Prompt: total weight of all WooCommerce products in cart

if ( function_exists( 'oxygen_vsb_register_condition' ) ) { global $oxy_condition_operators; oxygen_vsb_register_condition( // Condition Name 'Total Weight of Products in Cart', // Values: The array of pre-set values the user can choose from. // Set the custom key's value to true to allow users to input custom values. array( 'options' => array(), 'custom' => true ), // Operators $oxy_condition_operators['int'], // Callback Function: Name of function that will be used to handle the condition 'cwpai_condition_total_weight_callback', // Condition Category: Default ones are Archive, Author, Other, Post, User 'WooCommerce' ); } /** * Callback function to handle the condition. * @param mixed $value Input value - in this case, weight of a product entered by the user. * @param string $operator Comparison operator selected by the user. * * @return boolean true or false. */ function cwpai_condition_total_weight_callback( $value, $operator ) { $total_weight = 0; if ( ! empty( WC()->cart->get_cart() ) ) { foreach ( WC()->cart->get_cart() as $cart_item ) { $total_weight += $cart_item['data']->get_weight() * $cart_item['quantity']; } } // return the integer value of $value $value = intval( $value ); return oxy_condition_eval_int( $total_weight, $value, $operator ); } Generation ID:cmpl-6Ga3AYPGslPz6JYaLgph3KnUSwaj6

When playing around with the WooCommerce generation capabilities of CodeWP.ai's Oxygen Conditions Mode, I wanted to conditionally display a message if the total weight of all products in a WooCommerce cart exceeded a set number.

Using Oxygen Builder Conditions CodeWP Generations

Using the generation is easy. First, let's export it. Do that by clicking the export button in the generator. (Learn more about the export feature here)

Then, install it on a testing website by importing the snippet to a code snippet management plugin. (Learn more about testing snippets - DO NOT SKIP THIS STEP or you may break your production site)

Finally, head into the Oxygen Conditions builder, choose your new condition, and check the front end to see if it works.

This new feature, and dozens more
php
PHP, JS or jQuery
select_all
AI models trained for WordPress & popular plugins
switch_access_shortcut
Unlimited generations
card_giftcard
100% free trial
Start For Free
link