'disable', 'global_checkout' => '', ) ); $common = Cartflows_Helper::get_admin_settings_option( '_cartflows_common', false, true ); self::$common = wp_parse_args( $common, $common_default ); } return self::$common; } /** * Get Checkout field. * * @param string $key Field key. * @param int $post_id Post id. * @return array. */ static public function get_checkout_fields( $key, $post_id ) { $saved_fields = get_post_meta( $post_id, 'wcf_fields_' . $key, true ); if ( ! $saved_fields ) { $saved_fields = array(); } $fields = array_filter( $saved_fields ); if ( empty( $fields ) ) { if ( 'billing' === $key || 'shipping' === $key ) { $fields = WC()->countries->get_address_fields( WC()->countries->get_base_country(), $key . '_' ); update_post_meta( $post_id, 'wcf_fields_' . $key, $fields ); } } return $fields; } /** * Add Checkout field. * * @param string $type Field type. * @param string $field_key Field key. * @param array $field_data Field data. * @param int $post_id Post id. * @return boolean. */ static public function add_checkout_field( $type, $field_key, $field_data = array(), $post_id ) { $fields = self::get_checkout_fields( $type, $post_id ); $fields[ $field_key ] = $field_data; update_post_meta( $post_id, 'wcf_fields_' . $type, $fields ); return true; } /** * Get checkout fields settings. * * @param string $type Field type. * @param string $field_key Field key. * @param int $post_id Post id. * @return array. */ static public function delete_checkout_field( $type, $field_key, $post_id ) { $fields = self::get_checkout_fields( $type, $post_id ); if ( isset( $fields[ $field_key ] ) ) { unset( $fields[ $field_key ] ); } update_post_meta( $post_id, 'wcf_fields_' . $type, $fields ); return true; } /** * Get checkout fields settings. * * @return array. */ static public function get_checkout_fields_settings() { if ( null === self::$checkout_fields ) { $checkout_fields_default = array( 'enable_customization' => 'disable', 'enable_billing_fields' => 'disable', ); $billing_fields = self::get_checkout_fields( 'billing' ); if ( is_array( $billing_fields ) && ! empty( $billing_fields ) ) { foreach ( $billing_fields as $key => $value ) { $checkout_fields_default[ $key ] = 'enable'; } } $checkout_fields = Cartflows_Helper::get_admin_settings_option( '_wcf_checkout_fields', false, true ); self::$checkout_fields = wp_parse_args( $checkout_fields, $checkout_fields_default ); } return self::$checkout_fields; } /** * Get meta options * * @since 1.0.0 * @param int $post_id Product ID. * @param string $key Meta Key. * @param string $default Default value. * @return string Meta Value. */ static public function get_meta_option( $post_id, $key, $default = '' ) { $value = get_post_meta( $post_id, $key, true ); if ( ! $value ) { $value = $default; } return $value; } /** * Save meta option * * @since 1.0.0 * @param int $post_id Product ID. * @param array $args Arguments array. */ static public function save_meta_option( $post_id, $args = array() ) { if ( is_array( $args ) && ! empty( $args ) ) { foreach ( $args as $key => $value ) { update_post_meta( $post_id, $key, $value ); } } } /** * Check if Elementor page builder is installed * * @since 1.0.0 * * @access public */ static public function _is_elementor_installed() { $path = 'elementor/elementor.php'; $plugins = get_plugins(); return isset( $plugins[ $path ] ); } /** * Check if Step has product assigned. * * @since 1.0.0 * @param int $step_id step ID. * * @access public */ static public function has_product_assigned( $step_id ) { $step_type = get_post_meta( $step_id, 'wcf-step-type', true ); if ( 'checkout' == $step_type ) { $product = get_post_meta( $step_id, 'wcf-checkout-products', true ); } else { $product = get_post_meta( $step_id, 'wcf-offer-product', true ); } if ( ! empty( $product ) ) { return true; } return false; } /** * Get attributes for cartflows wrap. * * @since x.x.x * * @access public */ static public function get_cartflows_container_atts() { $attributes = apply_filters( 'cartflows_container_atts', array() ); $atts_string = ''; foreach ( $attributes as $key => $value ) { if ( ! $value ) { continue; } if ( true === $value ) { $atts_string .= esc_html( $key ) . ' '; } else { $atts_string .= sprintf( '%s="%s" ', esc_html( $key ), esc_attr( $value ) ); } } return $atts_string; } }