$oxy_exist = true;
if ( defined( 'CT_VERSION' ) ) {
$oxy_builder_version = CT_VERSION;
}
}
if ( true === $oxy_exist ) {
$response['found'] = true;
if ( ! version_compare( $oxy_builder_version, $supported_version, '>=' ) ) {
$response['is_old_version'] = 'yes';
$response['version'] = $oxy_builder_version;
$response['error'] = sprintf( __( 'Site has an older version of Oxygen Classic Builder. Templates are supported for v%s or greater.
Please update.', 'woofunnels-aero-checkout' ), $supported_version );
}
}
} elseif ( 'divi' === $builder ) {
$supported_version = '4.1';
$divi_exist = false;
$divi_builder_version = 0;
// Detect Divi Builder Plugin is Active
if ( class_exists( 'ET_Builder_Plugin' ) ) {
$divi_exist = true;
if ( defined( 'ET_BUILDER_PLUGIN_VERSION' ) ) {
$divi_builder_version = ET_BUILDER_PLUGIN_VERSION;
}
} elseif ( function_exists( 'et_setup_theme' ) ) { // Detect Theme Active
$divi_exist = true;
$theme = wp_get_theme();
if ( $theme instanceof WP_Theme ) {
$parent = $theme->parent();
if ( $parent instanceof WP_Theme ) {
$divi_builder_version = $parent->get( 'Version' );
} else {
$divi_builder_version = $theme->get( 'Version' );
}
}
}
// available in Both Theme & Plugin
if ( 0 == $divi_builder_version && defined( 'ET_BUILDER_PRODUCT_VERSION' ) ) {
$divi_builder_version = ET_BUILDER_PRODUCT_VERSION;
}
// ET_Builder_Plugin
if ( true === $divi_exist && class_exists( 'ET_Core_Portability' ) ) {
$response['found'] = true;
$response['version'] = $divi_builder_version;
if ( ! version_compare( $divi_builder_version, $supported_version, '>=' ) ) {
$response['is_old_version'] = 'yes';
$response['error'] = sprintf( __( 'Site has an older version of Divi Builder. Templates are supported for v%s or greater.
Please update.', 'woofunnels-aero-checkout' ), $supported_version );
}
}
}
return $response;
}
final public static function get_list_of_attach_actions( $hook ) {
$output = array();
global $wp_filter;
$object = null;
if ( isset( $wp_filter[ $hook ] ) && ( $wp_filter[ $hook ] instanceof WP_Hook ) ) {
$hooks = $wp_filter[ $hook ]->callbacks;
foreach ( $hooks as $priority => $reference ) {
if ( is_array( $reference ) && count( $reference ) > 0 ) {
foreach ( $reference as $index => $calls ) {
if ( isset( $calls['function'] ) && is_array( $calls['function'] ) && count( $calls['function'] ) > 0 ) {
if ( is_object( $calls['function'][0] ) ) {
$cls_name = get_class( $calls['function'][0] );
$output[] = array(
'type' => 'class',
'class' => $cls_name,
'function' => $calls['function'][1],
'class_path' => WFACP_Common::get_class_path( $cls_name ),
'index' => $index,
'priority' => $priority,
);
} else {
$output[] = array(
'type' => 'static_class',
'class' => $calls['function'][0],
'function' => $calls['function'][1],
'class_path' => WFACP_Common::get_class_path( $calls['function'][0] ),
'index' => $index,
'priority' => $priority,
);
}
} else {
$output[] = array(
'type' => 'function',
'function' => $calls['function'],
'function_path' => WFACP_Common::get_function_path( $calls['function'] ),
'index' => $index,
'priority' => $priority,
);
}
}
}
}
}
return $output;
}
/**
* Maybe insert logs for the conversion API
*
* @param string $content
* @param string $event The CAPI event type this log belongs to (e.g. 'Purchase', 'AddToCart'), so the filter can allow logging per event.
*/
public static function maybe_insert_log( $content, $event = '' ) {
if ( true === apply_filters( 'bwf_conversion_api_checkout_event_logs', false, $event ) && self::is_enabled_log() ) {
wc_get_logger()->log( 'info', $content, array( 'source' => 'bwf_facebook_conversion_api' ) );
}
}
/**
* Check if logs are enabled or not for the conversion API
*
* @return bool
*/
public static function is_enabled_log() {
$admin_general = BWF_Admin_General_Settings::get_instance();
$is_conversion_api_log = $admin_general->get_option( 'is_fb_conversion_api_log' );
if ( is_array( $is_conversion_api_log ) && count( $is_conversion_api_log ) > 0 && 'yes' === $is_conversion_api_log[0] ) {
return true;
}
return false;
}
public static function get_user_email() {
$current_user = wp_get_current_user();
// not logged in
if ( $current_user->ID == 0 ) {
return '';
}
return $current_user->user_email;
}
public static function the_content( $post ) {
if ( is_null( $post ) ) {
return '';
}
$content = get_the_content( null, false, $post );
/**
* Filters the post content.
*
* @param string $content Content of the current post.
*
* @since 0.71
*/
$content = apply_filters( 'the_content', $content );
$content = str_replace( ']]>', ']]>', $content );
echo $content;
}
/**
* check old placeholder present
*
* @param $placeholder
*
* @return Array
*/
public static function get_old_placeholders() {
return array(
'john.doe@example.com',
'john.doe@example.com ',
'John',
'Doe',
'john',
'doe',
'Albany',
'House Number and Street Name',
'12084',
'999-999-9999',
'United States',
'New York',
);
}
public static function live_change_modern_label( $field ) {
$placeholder = $field['placeholder'];
if ( empty( $placeholder ) ) {
return $field;
}
$search = self::get_old_placeholders();
if ( in_array( $placeholder, $search ) ) {
$field['placeholder'] = $field['label'];
}
return $field;
}
public static function modern_label_migrate( $id ) {
$migrate = get_post_meta( $id, '_wfacp_page_modern_label_migrate', true );
if ( 'yes' == $migrate ) {
return;
}
$page_layout = get_post_meta( $id, '_wfacp_page_layout', true );
$page_field_set = get_post_meta( $id, '_wfacp_fieldsets_data', true );
if ( empty( $page_layout ) ) {
return;
}
// Saving backup
update_post_meta( $id, '_wfacp_page_layout_bck', $page_layout );
update_post_meta( $id, '_wfacp_fieldsets_data_bck', $page_field_set );
$search = self::get_old_placeholders();
$page_layout = json_encode( $page_layout );
$page_field_set = json_encode( $page_field_set );
$page_layout = str_replace( $search, '', $page_layout );
$page_field_set = str_replace( $search, '', $page_field_set );
if ( is_null( $page_layout ) || empty( $page_layout ) ) {
// Do not override meta field value if $page_layout is null
return;
}
update_post_meta( $id, '_wfacp_page_layout', json_decode( $page_layout, true ) );
update_post_meta( $id, '_wfacp_fieldsets_data', json_decode( $page_field_set, true ) );
update_post_meta( $id, '_wfacp_page_modern_label_migrate', 'yes' );
}
/**
* Update Label Meta while template import
*
* @param $post_id
* @param $json_data
*
* @return void
*/
public static function update_label_meta( $post_id, $json_data ) {
if ( is_array( $json_data ) ) {
$json_data = json_encode( $json_data );
}
if ( empty( $json_data ) ) {
return;
}
if ( false !== strpos( $json_data, 'wfacp-modern-label' ) ) {
$field_label = 'wfacp-modern-label';
} elseif ( false !== strpos( $json_data, 'wfacp-top' ) ) {
$field_label = 'wfacp-top';
} else {
$field_label = 'wfacp-inside';
}
update_post_meta( $post_id, '_wfacp_field_label_position', $field_label );
}
/**
* Return subscription version if woocommerce payment or Main Subscription
*
* @return string
*/
public static function get_subscription_version() {
if ( class_exists( 'WC_Subscriptions_Core_Plugin' ) ) {
$instance = WC_Subscriptions_Core_Plugin::instance();
return $instance->get_plugin_version();
}
return WC_Subscriptions::$version;
}
/**
* Get Applied coupon of cart
*
* @return array|null
*/
public static function get_coupons() {
if ( is_null( WC()->cart ) ) {
return array();
}
if ( ! is_null( self::$cart_coupons ) ) {
return self::$cart_coupons;
}
self::$cart_coupons = WC()->cart->get_coupons();
return self::$cart_coupons;
}
public static function is_funnel_builder_3() {
return class_exists( 'WFFN_REST_CHECKOUT_API_EndPoint' );
}
public static function find_matched_item_by_product_key( $product_key ) {
// do not add to bump product if same bump present in cart.
if ( is_null( WC()->cart ) ) {
return true;
}
$contents = WC()->cart->get_cart_contents();
$filter_item = array_filter(
$contents,
function ( $content ) use ( $product_key ) {
return ( isset( $content['_wfacp_product_key'] ) && ! empty( $product_key ) && $content['_wfacp_product_key'] == $product_key );
}
);
return empty( $filter_item );
}
/**
* display Value instead of of slug For Radio,Checkbox,Multiselect field at thankyou and email
*
* @param mixed $meta_value The meta value to map
* @param array $field The field configuration array
*
* @return string The mapped value
*/
public static function map_meta_value_for_custom_fields( $meta_value, $field ) {
// Early return if no options available
if ( ! isset( $field['options'] ) || empty( $field['options'] ) ) {
return $meta_value;
}
$options = $field['options'];
// Convert comma-separated string to array for select2/multiselect fields
if ( in_array( $field['type'], array( 'select2', 'multiselect' ), true ) && is_string( $meta_value ) ) {
$meta_value = explode( ',', $meta_value );
}
// Handle array values
if ( is_array( $meta_value ) ) {
$mapped_values = array_map(
function ( $item ) use ( $options ) {
$trimmed_item = trim( $item );
return isset( $options[ $trimmed_item ] ) ? $options[ $trimmed_item ] : $trimmed_item;
},
$meta_value
);
return implode( ', ', $mapped_values );
}
// Handle single value
return isset( $options[ $meta_value ] ) ? $options[ $meta_value ] : $meta_value;
}
public static function update_aero_custom_fields( $order, $posted_data, $force_save = false ) {
$wfacp_id = 0;
if ( isset( $posted_data['wfacp_post_id'] ) ) {
$wfacp_id = $posted_data['wfacp_post_id'];
} elseif ( isset( $posted_data['_wfacp_post_id'] ) ) {
$wfacp_id = $posted_data['_wfacp_post_id'];
} elseif ( $_GET['wfacp_id'] ) {
$wfacp_id = $posted_data['wfacp_id'];
}
$is_numeric = false;
if ( is_numeric( $order ) ) {
$is_numeric = true;
$order = wc_get_order( $order );
}
if ( ! $order instanceof WC_Order ) {
return;
}
$wfacp_id = absint( $wfacp_id );
if ( $wfacp_id < 1 ) {
return;
}
$order->update_meta_data( '_wfacp_post_id', $wfacp_id );
$order->update_meta_data( '_wfacp_source', $posted_data['wfacp_source'] );
$timezone = $posted_data['wfacp_timezone'] ?? ( $_POST['wfacp_timezone'] ?? null );
if ( ! is_null( $timezone ) ) {
$order->update_meta_data( '_wfacp_timezone', wc_clean( $timezone ) );
}
$cfields = WFACP_Common::get_page_custom_fields( $wfacp_id );
$have_custom_field = isset( $cfields['advanced'] ) && ! empty( $cfields['advanced'] );
if ( $have_custom_field ) {
$advancedFields = $cfields['advanced'];
foreach ( $advancedFields as $field_key => $field ) {
if ( isset( $field['type'] ) && ( 'wfacp_html' === $field['type'] || 'wfacp_wysiwyg' === $field['type'] ) ) {
continue;
}
$field_value = $posted_data[ $field_key ] ?? ( $_REQUEST[ $field_key ] ?? null );
if ( is_null( $field_value ) ) {
continue;
}
if ( ! empty( $field_value ) && $field['type'] == 'date' ) {
$field_value = date( 'Y-m-d', strtotime( $field_value ) );
} elseif ( ! empty( $field_value ) && $field['type'] == 'wfacp_dob' ) {
$field_value = ( $posted_data[ $field_key ]['year'] ?? ( $_REQUEST[ $field_key ]['year'] ) ) . '-' . ( $posted_data[ $field_key ]['month'] ?? $_REQUEST[ $field_key ]['month'] ) . '-' . ( $posted_data[ $field_key ]['day'] ?? $_REQUEST[ $field_key ]['day'] );
}
if ( $field['type'] != 'multiselect' && $field['type'] !== 'textarea' ) {
$field_value = wc_clean( $field_value );
}
$order->update_meta_data( $field_key, $field_value );
}
}
if ( $is_numeric || $force_save ) {
$order->save();
}
}
public static function get_optional_checkout_fields( $checkout_id ) {
$checkout_fields = WFACP_Common::get_checkout_fields( $checkout_id );
$optional_fields = array();
if ( isset( $checkout_fields['product'] ) ) {
unset( $checkout_fields['product'] );
}
if ( isset( $checkout_fields['product'] ) ) {
unset( $checkout_fields['product'] );
}
$excluded_types = array( 'wfacp_html', 'product' );
$page_layout = WFACP_Common::get_page_layout( $checkout_id );
if ( ! isset( $page_layout['fieldsets'] ) ) {
return $optional_fields;
}
$exclude_keys = array(
'billing_same_as_shipping',
'shipping_same_as_billing',
'wfacp_divider_shipping',
'wfacp_divider_shipping_end',
'wfacp_divider_billing',
'wfacp_divider_billing_end',
'billing_address_1',
'billing_city',
'billing_postcode',
'billing_country',
'billing_state',
'shipping_address_1',
'shipping_city',
'shipping_postcode',
'shipping_country',
'shipping_state',
'product_switching',
'order_total',
'order_coupon',
'shipping_calculator',
'order_summary',
'bwfan_birthday_date',
);
foreach ( $checkout_fields as $i => $fieldset ) {
foreach ( $fieldset as $key => $fields ) {
if ( ! isset( $fields['type'] ) || in_array( $fields['type'], $excluded_types ) ) {
continue;
}
if ( isset( $fields['required'] ) && true == wc_string_to_bool( $fields['required'] ) ) {
continue;
}
if ( in_array( $key, $exclude_keys ) ) {
continue;
}
$optional_fields[ $key ] = $fields;
$optional_fields[ $key ]['disable'] = true;
}
}
$all_fields = array();
$address_fields = array();
$tmp = array();
if ( isset( $page_layout['address_order'] ) && is_array( $page_layout['address_order'] ) && count( $page_layout['address_order'] ) > 0 ) {
foreach ( $page_layout['address_order'] as $address_key => $fields ) {
if ( ! in_array( $address_key, array( 'shipping-address', 'address' ) ) ) {
continue;
}
$label_key = 'billing_';
$label_prefix = 'Billing';
if ( $address_key == 'shipping-address' ) {
$label_key = 'shipping_';
$label_prefix = 'Shipping';
}
$tmp[] = $address_key;
foreach ( $fields as $adderess_index => $field ) {
if ( ! isset( $field['key'] ) || in_array( $label_key . $field['key'], $exclude_keys ) ) {
continue;
}
if ( isset( $field['required'] ) && true == wc_string_to_bool( $field['required'] ) ) {
continue;
}
$add_field_key = $field['key'];
$field['field_type'] = $address_key;
$address_fields[ $label_key . $add_field_key ] = $field;
if ( isset( $field['status'] ) && true == wc_string_to_bool( $field['status'] ) ) {
$address_fields[ $label_key . $add_field_key ]['disable'] = false;
} else {
$address_fields[ $label_key . $add_field_key ]['disable'] = true;
}
if ( ! isset( $field['label'] ) ) {
continue;
}
$address_fields[ $label_key . $add_field_key ]['label'] = $label_prefix . ' ' . $field['label'];
}
}
}
foreach ( $page_layout['fieldsets'] as $field_step_key => $field_step_val ) {
foreach ( $field_step_val as $i => $fields ) {
if ( ! isset( $fields['fields'] ) ) {
continue;
}
foreach ( $fields['fields'] as $k => $field ) {
if ( ! isset( $field['id'] ) || in_array( $field['id'], $exclude_keys ) || isset( $field['type'] ) && in_array( $field['type'], $excluded_types ) ) {
continue;
}
if ( array_key_exists( $field['id'], $tmp ) ) {
continue;
}
if ( isset( $field['fields_options'] ) && is_array( $field['fields_options'] ) ) {
$label_key = 'billing_';
$label_prefix = 'Billing';
if ( $field['id'] == 'shipping-address' ) {
$label_key = 'shipping_';
$label_prefix = 'Shipping';
}
foreach ( $field['fields_options'] as $address_key => $address_field ) {
if ( ! isset( $field['id'] ) || in_array( $label_key . $address_key, $exclude_keys ) ) {
continue;
}
if ( isset( $address_field['required'] ) && true == wc_string_to_bool( $address_field['required'] ) ) {
continue;
}
$address_field['field_type'] = $field['id'];
$all_fields[ $label_key . $address_key ] = $address_field;
if ( isset( $optional_fields[ $label_key . $address_key ] ) && true == $optional_fields[ $label_key . $address_key ] ) {
$all_fields[ $label_key . $address_key ]['disable'] = false;
} else {
$all_fields[ $label_key . $address_key ]['disable'] = true;
}
if ( isset( $address_field['street_address_2_label'] ) && false !== strpos( $address_key, 'address_2' ) ) {
$all_fields[ $label_key . $address_key ]['label'] = $label_prefix . ' ' . $address_field['street_address_2_label'];
} elseif ( isset( $address_field['address_phone_label'] ) && false !== strpos( $address_key, 'phone' ) ) {
$all_fields[ $label_key . $address_key ]['label'] = $label_prefix . ' ' . $address_field['address_phone_label'];
} else {
$all_fields[ $label_key . $address_key ]['label'] = $label_prefix . ' ' . $address_field[ $address_key . '_label' ];
}
}
} else {
if ( isset( $field['required'] ) && true == wc_string_to_bool( $field['required'] ) ) {
continue;
}
$all_fields[ $field['id'] ] = $field;
if ( isset( $all_fields[ $field['id'] ] ) && true == $all_fields[ $field['id'] ] ) {
$all_fields[ $field['id'] ]['disable'] = false;
} else {
$all_fields[ $field['id'] ]['disable'] = true;
}
}
}
}
}
if ( is_array( $address_fields ) && count( $address_fields ) > 0 ) {
return array_merge( $all_fields, $address_fields );
}
return $all_fields;
}
final public static function locate_template( $template_name, $template_path = '', $default_path = '' ) {
// Set variable to search in funnelkit folder of theme.
if ( ! $template_path ) {
$template_path = 'funnelkit/checkouts/';
}
// Set default plugin templates path.
if ( ! $default_path ) {
$default_path = plugin_dir_path( WFACP_PLUGIN_FILE ) . 'templates/'; // Path to the template folder
}
// Search template file in theme folder.
$template = \locate_template(
array(
$template_path . $template_name,
$template_name,
)
);
// Get default template/
if ( ! $template ) {
$template = $default_path . $template_name;
}
// Return what we found with filtering opportunity.
return apply_filters( 'locate_template', $template, $template_name, $template_path );
}
/**
* Get template.
*
* @param string $template_name Template to load.
* @param array $args Args passed for the template file.
* @param string $template_path Path to templates.
* @param string $default_path Default path to template files.
*/
final public static function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
$template_file = self::locate_template( $template_name, $template_path, $default_path );
if ( ! file_exists( $template_file ) ) {
_doing_it_wrong( __FUNCTION__, sprintf( '%s does not exist.', $template_file ), '1.0.0' );
return;
}
if ( is_array( $args ) && isset( $args ) ) {
extract( $args );
}
include $template_file;
}
/**
* Override WooCommerce Block Checkout and Cart with older respective shortcodes
*
* @return void
*/
public static function override_block_cart_checkout() {
$wc_checkout_page = get_post( wc_get_page_id( 'checkout' ) );
if ( has_block( 'woocommerce/checkout', $wc_checkout_page ) ) {
wp_update_post(
array(
'ID' => $wc_checkout_page->ID,
'post_content' => '',
)
);
}
}
/**
* Re Map The options keys of select,Radio,Checkbox value if keys are UTF8 encoded
*
* @param $args
* @param $key
*
* @return mixed
*/
public static function re_map_field_options_if_utf_encode( $args, $key ) {
if ( ! isset( $args['options'] ) || ! is_array( $args['options'] ) || empty( $args['options'] ) ) {
return $args;
}
$pattern = '/%[0-9A-Fa-f]{2}/';
$new_options = array();
foreach ( $args['options'] as $k => $v ) {
if ( preg_match( $pattern, $k ) ) {
$new_options[ $v ] = $v;
} else {
$new_options[ $k ] = $v;
}
}
if ( ! empty( $new_options ) ) {
$args['options'] = $new_options;
}
return $args;
}
/**
* Conditionally Display Tax Total in Cart/Checkout
* When the WooCommerce tax setting “Display tax totals” is set to “As a single total”, the tax amount should only be displayed on the cart and checkout pages if the total tax amount is greater than zero.
*
* @return bool
*/
public static function display_tax_total() {
$tax_total = WC()->cart->get_taxes_total( true, false );
// Only display tax when tax total is > 0 in case of tax setting is set single total tax
return apply_filters( 'wfacp_display_single_total_tax', $tax_total > 0, WC()->cart );
}
}
}