args = isset( $_POST['model']['params'] ) ? wp_unslash( $_POST['model']['params'] ) : []; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$html = $this->generate_element_content();
echo wp_json_encode( $html );
wp_die();
}
/**
* Gets the default values.
*
* @static
* @access public
* @since 2.0.0
* @return array
*/
public static function get_element_defaults() {
$fusion_settings = awb_get_fusion_settings();
return [
// Element margin.
'margin_top' => '',
'margin_right' => '',
'margin_bottom' => '',
'margin_left' => '',
'hide_on_mobile' => fusion_builder_default_visibility( 'string' ),
'class' => '',
'id' => '',
// Fields.
'field_bg_color' => $fusion_settings->get( 'form_bg_color' ),
'field_text_color' => $fusion_settings->get( 'form_text_color' ),
'field_border_color' => $fusion_settings->get( 'form_border_color' ),
'field_border_focus_color' => $fusion_settings->get( 'form_focus_border_color' ),
// Animation.
'animation_direction' => 'left',
'animation_offset' => $fusion_settings->get( 'animation_offset' ),
'animation_speed' => '',
'animation_delay' => '',
'animation_type' => '',
'animation_color' => '',
];
}
/**
* Render the shortcode.
*
* @access public
* @since 3.3
* @param array $args Shortcode parameters.
* @param string $content Content between shortcode.
* @return string HTML output
*/
public function render( $args, $content = '' ) {
if ( ! is_object( WC()->cart ) || ( WC()->cart->is_empty() && ! fusion_is_preview_frame() ) ) {
return;
}
$this->defaults = self::get_element_defaults();
$this->args = FusionBuilder::set_shortcode_defaults( self::get_element_defaults(), $args, 'fusion_tb_woo_cart_totals' );
ob_start();
?>
on_render();
$this->counter++;
return apply_filters( 'fusion_element_cart_shipping_content', $html, $args );
}
/**
* Generates element content
*
* @return string
*/
public function generate_element_content() {
ob_start();
?>
is_default( 'field_text_color' ) ) {
$custom_vars['placeholder_color'] = Fusion_Color::new_color( $this->args['field_text_color'] )->get_new( 'alpha', '0.5' )->to_css_var_or_rgba();
}
if ( ! $this->is_default( 'field_border_focus_color' ) ) {
$custom_vars['hover_color'] = Fusion_Color::new_color( $this->args['field_border_focus_color'] )->get_new( 'alpha', '0.5' )->to_css_var_or_rgba();
}
$css_vars_options = [
'field_bg_color' => [ 'callback' => [ 'Fusion_Sanitize', 'color' ] ],
'field_text_color' => [ 'callback' => [ 'Fusion_Sanitize', 'color' ] ],
'field_border_color' => [ 'callback' => [ 'Fusion_Sanitize', 'color' ] ],
'field_border_focus_color' => [ 'callback' => [ 'Fusion_Sanitize', 'color' ] ],
'margin_top' => [ 'callback' => [ 'Fusion_Sanitize', 'get_value_with_unit' ] ],
'margin_right' => [ 'callback' => [ 'Fusion_Sanitize', 'get_value_with_unit' ] ],
'margin_bottom' => [ 'callback' => [ 'Fusion_Sanitize', 'get_value_with_unit' ] ],
'margin_left' => [ 'callback' => [ 'Fusion_Sanitize', 'get_value_with_unit' ] ],
];
$styles = $this->get_css_vars_for_options( $css_vars_options ) . $this->get_custom_css_vars( $custom_vars );
return $styles;
}
/**
* Used to set any other variables for use on front-end editor template.
*
* @static
* @access public
* @since 2.0.0
* @return array
*/
public static function get_element_extras() {
$fusion_settings = awb_get_fusion_settings();
return [
'content_break_point' => $fusion_settings->get( 'content_break_point' ),
];
}
/**
* Builds the attributes array.
*
* @access public
* @since 1.0
* @return array
*/
public function attr() {
$attr = fusion_builder_visibility_atts(
$this->args['hide_on_mobile'],
[
'class' => 'woocommerce-shipping-calculator fusion-woocommerce-shipping-calculator fusion-woocommerce-shipping-calculator-' . $this->counter,
'style' => '',
]
);
$is_builder = ( function_exists( 'fusion_is_preview_frame' ) && fusion_is_preview_frame() ) || ( function_exists( 'fusion_is_builder_frame' ) && fusion_is_builder_frame() );
if ( $this->args['class'] ) {
$attr['class'] .= ' ' . $this->args['class'];
}
if ( $is_builder ) {
$attr['class'] .= ' awb-live';
}
if ( $this->args['animation_type'] ) {
$attr = Fusion_Builder_Animation_Helper::add_animation_attributes( $this->args, $attr );
}
$attr['style'] .= $this->get_style_variables();
if ( $this->args['id'] ) {
$attr['id'] = $this->args['id'];
}
return $attr;
}
/**
* Load base CSS.
*
* @access public
* @since 3.0
* @return void
*/
public function add_css_files() {
FusionBuilder()->add_element_css( FUSION_BUILDER_PLUGIN_DIR . 'assets/css/shortcodes/woo-cart-shipping.min.css' );
}
}
}
new FusionSC_WooCartShipping();
}
/**
* Map shortcode to Avada Builder.
*/
function fusion_element_woo_cart_shipping() {
$fusion_settings = awb_get_fusion_settings();
if ( class_exists( 'WooCommerce' ) ) {
fusion_builder_map(
fusion_builder_frontend_data(
'FusionSC_WooCartShipping',
[
'name' => esc_attr__( 'Woo Cart Shipping', 'fusion-builder' ),
'shortcode' => 'fusion_woo_cart_shipping',
'icon' => 'fusiona-cart-shipping',
'help_url' => '',
'inline_editor' => true,
'params' => [
[
'type' => 'dimension',
'remove_from_atts' => true,
'heading' => esc_attr__( 'Margin', 'fusion-builder' ),
'description' => esc_attr__( 'In pixels or percentage, ex: 10px or 10%.', 'fusion-builder' ),
'param_name' => 'margin',
'callback' => [
'function' => 'fusion_style_block',
'args' => [
'dimension' => true,
],
],
'value' => [
'margin_top' => '',
'margin_right' => '',
'margin_bottom' => '',
'margin_left' => '',
],
],
[
'type' => 'colorpickeralpha',
'heading' => esc_attr__( 'Form Field Background Color', 'fusion-builder' ),
'description' => esc_attr__( 'Controls the background color of the form input fields.', 'fusion-builder' ),
'param_name' => 'field_bg_color',
'value' => '',
'default' => $fusion_settings->get( 'form_bg_color' ),
'group' => esc_attr__( 'Design', 'fusion-builder' ),
'callback' => [
'function' => 'fusion_style_block',
],
],
[
'type' => 'colorpickeralpha',
'heading' => esc_attr__( 'Form Field Text Color', 'fusion-builder' ),
'description' => esc_attr__( 'Controls the text color of the form input fields.', 'fusion-builder' ),
'param_name' => 'field_text_color',
'value' => '',
'default' => $fusion_settings->get( 'form_text_color' ),
'group' => esc_attr__( 'Design', 'fusion-builder' ),
'callback' => [
'function' => 'fusion_style_block',
],
],
[
'type' => 'colorpickeralpha',
'heading' => esc_attr__( 'Field Border Color', 'fusion-builder' ),
'description' => esc_attr__( 'Controls the border color of the form input fields.', 'fusion-builder' ),
'param_name' => 'field_border_color',
'value' => '',
'default' => $fusion_settings->get( 'form_border_color' ),
'group' => esc_attr__( 'Design', 'fusion-builder' ),
'callback' => [
'function' => 'fusion_style_block',
],
],
[
'type' => 'colorpickeralpha',
'heading' => esc_attr__( 'Field Border Color On Focus', 'fusion-builder' ),
'description' => esc_attr__( 'Controls the border color of the form input fields on focus.', 'fusion-builder' ),
'param_name' => 'field_border_focus_color',
'value' => '',
'default' => $fusion_settings->get( 'form_focus_border_color' ),
'group' => esc_attr__( 'Design', 'fusion-builder' ),
'callback' => [
'function' => 'fusion_style_block',
],
],
'fusion_animation_placeholder' => [
'preview_selector' => '.fusion-woocommerce-shipping-calculator',
],
[
'type' => 'checkbox_button_set',
'heading' => esc_attr__( 'Element Visibility', 'fusion-builder' ),
'param_name' => 'hide_on_mobile',
'value' => fusion_builder_visibility_options( 'full' ),
'default' => fusion_builder_default_visibility( 'array' ),
'description' => esc_attr__( 'Choose to show or hide the element on small, medium or large screens. You can choose more than one at a time.', 'fusion-builder' ),
],
[
'type' => 'textfield',
'heading' => esc_attr__( 'CSS Class', 'fusion-builder' ),
'description' => esc_attr__( 'Add a class to the wrapping HTML element.', 'fusion-builder' ),
'param_name' => 'class',
'value' => '',
],
[
'type' => 'textfield',
'heading' => esc_attr__( 'CSS ID', 'fusion-builder' ),
'description' => esc_attr__( 'Add an ID to the wrapping HTML element.', 'fusion-builder' ),
'param_name' => 'id',
'value' => '',
],
],
'callback' => [
'function' => 'fusion_ajax',
'action' => 'fusion_get_woo_cart_shipping',
'ajax' => true,
],
]
)
);
}
}
add_action( 'fusion_builder_wp_loaded', 'fusion_element_woo_cart_shipping' );