Skip to content

Instantly share code, notes, and snippets.

@hmowais
Created August 7, 2020 14:27
Show Gist options
  • Save hmowais/39451778aa04396aaf25c8a4dcf739a8 to your computer and use it in GitHub Desktop.
Save hmowais/39451778aa04396aaf25c8a4dcf739a8 to your computer and use it in GitHub Desktop.
Gravity Form + Modal Popup (Natural Website)
<?php
function theme_enqueue_styles() {
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'avada-stylesheet' ) );
wp_enqueue_style( 'custom-style', get_stylesheet_directory_uri() . '/assets/css/custom.css', array() );
wp_enqueue_style( 'responsive-style', get_stylesheet_directory_uri() . '/assets/css/responsive.css', array() );
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function avada_lang_setup() {
$lang = get_stylesheet_directory() . '/languages';
load_child_theme_textdomain( 'Avada', $lang );
}
add_action( 'after_setup_theme', 'avada_lang_setup' );
add_filter( 'gform_currencies', 'currency_symbol' );
function currency_symbol( $currencies ) {
if ( is_page( '156' ) ) {
$currencies['USD'] = array(
'name' => __( 'U.S. Dollar', 'gravityforms' ),
'symbol_left' => '$ ',
'symbol_right' => ' MXN',
'symbol_padding' => '',
'thousand_separator' => ',',
'decimal_separator' => '.',
'decimals' => 2
);
return $currencies;
}
if ( is_page( '181' ) ) {
$currencies['USD'] = array(
'name' => __( 'U.S. Dollar', 'gravityforms' ),
'symbol_left' => 'R$ ',
'symbol_right' => '',
'symbol_padding' => '',
'thousand_separator' => ',',
'decimal_separator' => '.',
'decimals' => 2
);
return $currencies;
}
if ( is_page( '167' ) ) {
$currencies['USD'] = array(
'name' => __( 'U.S. Dollar', 'gravityforms' ),
'symbol_left' => '$ ',
'symbol_right' => '',
'symbol_padding' => '',
'thousand_separator' => ',',
'decimal_separator' => '.',
'decimals' => 2
);
return $currencies;
}
if ( is_page( '169' ) ) {
$currencies['USD'] = array(
'name' => __( 'U.S. Dollar', 'gravityforms' ),
'symbol_left' => '£ ',
'symbol_right' => '',
'symbol_padding' => '',
'thousand_separator' => ',',
'decimal_separator' => '.',
'decimals' => 2
);
return $currencies;
}
if ( is_page( '171' ) ) {
$currencies['USD'] = array(
'name' => __( 'U.S. Dollar', 'gravityforms' ),
'symbol_left' => '$ ',
'symbol_right' => ' AUD',
'symbol_padding' => '',
'thousand_separator' => ',',
'decimal_separator' => '.',
'decimals' => 2
);
return $currencies;
}
if ( is_page( '173' ) ) {
$currencies['USD'] = array(
'name' => __( 'U.S. Dollar', 'gravityforms' ),
'symbol_left' => '',
'symbol_right' => ' CA $',
'symbol_padding' => '',
'thousand_separator' => ',',
'decimal_separator' => '.',
'decimals' => 2
);
return $currencies;
}
if ( is_page( '175' ) ) {
$currencies['USD'] = array(
'name' => __( 'U.S. Dollar', 'gravityforms' ),
'symbol_left' => '$ ',
'symbol_right' => ' NZD',
'symbol_padding' => '',
'thousand_separator' => ',',
'decimal_separator' => '.',
'decimals' => 2
);
return $currencies;
}
if ( is_page( '177' ) ) {
$currencies['USD'] = array(
'name' => __( 'U.S. Dollar', 'gravityforms' ),
'symbol_left' => '€ ',
'symbol_right' => '',
'symbol_padding' => '',
'thousand_separator' => ',',
'decimal_separator' => '.',
'decimals' => 2
);
return $currencies;
}
if ( is_page( '179' ) ) {
$currencies['USD'] = array(
'name' => __( 'U.S. Dollar', 'gravityforms' ),
'symbol_left' => '$ ',
'symbol_right' => ' COP',
'symbol_padding' => '',
'thousand_separator' => ',',
'decimal_separator' => '.',
'decimals' => 2
);
return $currencies;
}
$currencies['USD'] = array(
'name' => __( 'U.S. Dollar', 'gravityforms' ),
'symbol_left' => '$ ',
'symbol_right' => '',
'symbol_padding' => '',
'thousand_separator' => ',',
'decimal_separator' => '.',
'decimals' => 2
);
return $currencies;
}
function remove_1st_letter() { ?>
<script>
jQuery( window ).load(function() {
jQuery(".gform_wrapper .ginput_price").each(function() {
var text = jQuery(this).text();
text = text.replace("+", "");
jQuery(this).text(text);
});
//jQuery('.ginput_price').html(jQuery('.ginput_price').html().substring(3));
});
jQuery( document ).ready(function() {
jQuery(".gfield_checkbox li label").click(function(){
jQuery(".gform_wrapper .ginput_price").each(function() {
var text = jQuery(this).text();
text = text.replace(" +", "");
jQuery(this).text(text);
});
});
});
</script>
<?php }
add_action('wp_footer','remove_1st_letter');
/*
* Creating a function to create our CPT
*/
function cpt_gravity_popup() {
$labels = array(
'name' => _x( 'Gravity Popups', 'post type general name' ),
'singular_name' => _x( 'Popup', 'post type singular name' ),
'name_admin_bar' => _x( 'Popup', 'Add New on Toolbar' ),
'add_new' => _x( 'Add New', 'Popup' ),
'add_new_item' => __( 'Add New Popup' ),
'edit_item' => __( 'Edit Popup' ),
'new_item' => __( 'New Popup' ),
'update_item' => __( 'Update Popup' ),
'all_items' => __( 'All Popups' ),
'view_item' => __( 'View Popup' ),
'search_items' => __( 'Search Popups' ),
'not_found' => __( 'No popups found' ),
'not_found_in_trash' => __( 'No popups found in the Trash' ),
'parent_item_colon' => ’,
'menu_name' => 'Gravity Popups'
);
$args = array(
'labels' => $labels,
'menu_icon' => 'dashicons-pressthis',
'description' => 'Holds Gravity Forms Popup specific data',
'public' => true,
'menu_position' => 5,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
'has_archive' => true,
);
register_post_type( 'popup', $args );
}
add_action( 'init', 'cpt_gravity_popup' );
function taxonomies_popup() {
$labels = array(
'name' => _x( 'Popup Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Popup Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Popup Categories' ),
'all_items' => __( 'All Popup Categories' ),
'parent_item' => __( 'Parent Popup Category' ),
'parent_item_colon' => __( 'Parent Popup Category:' ),
'edit_item' => __( 'Edit Popup Category' ),
'update_item' => __( 'Update Popup Category' ),
'add_new_item' => __( 'Add New Popup Category' ),
'new_item_name' => __( 'New Popup Category' ),
'menu_name' => __( 'Popup Categories' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
);
register_taxonomy( 'popup_category', 'popup', $args );
}
add_action( 'init', 'taxonomies_popup', 0 );
function show_cpt_on_page() {
global $post;
$terms = get_field('popup_categories');
$taxonomy_name = 'popup_category';
$cpt_term = get_term($terms, $taxonomy);
$cpt_category = $cpt_term->name;
$args = array(
'post_type' => 'popup',
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => 'popup_category',
'field' => 'slug',
'terms' => $cpt_category,
)
)
);
$cpt = new WP_Query( $args );
if( $cpt->have_posts() ) :
?>
<div class="container">
<?php
while( $cpt->have_posts() ) :
$cpt->the_post();
//$the_ID = the_ID();
?>
<div id="MyPopup<?php echo the_ID(); ?>" class="modal fade MyPopup<?php echo the_ID(); ?>" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<h2><?php the_title(); ?></h2>
<p><?php the_content(); ?></p>
</div>
</div>
</div>
</div>
<?php
endwhile;
wp_reset_postdata();
?>
</div>
<?php
endif;
}
add_action('avada_before_main_container','show_cpt_on_page');
function modal_popup() { ?>
<script>
jQuery(document).ready(function($){
$('.gfield_checkbox li').on('click', this, function(e){
var str = $(this).find("input[type='checkbox']").val();
var res = str.split("|");
var final_val = res[0];
//console.log(final_val);
if(e.target.checked){
$('#'+final_val).modal("show");
}
});
});
</script>
<?php }
add_action('wp_footer','modal_popup');
add_filter( 'manage_posts_columns', 'revealid_add_id_column', 5 );
add_action( 'manage_posts_custom_column', 'revealid_id_column_content', 5, 2 );
function revealid_add_id_column( $columns ) {
$columns['revealid_id'] = 'ID';
return $columns;
}
function revealid_id_column_content( $column, $id ) {
if( 'revealid_id' == $column ) {
echo $id;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment