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
Ask for the condition you want in plain English
Get the code generated and install it on your (staging first) site
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.
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:
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