Last active
May 6, 2021 03:26
-
-
Save yeriepiscesa/50b7aed336c17c7311dabfa4b812de04 to your computer and use it in GitHub Desktop.
Kode dari tutorial https://solusipress.com/mengarahkan-isian-forminator-ke-pesan-whatsapp/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'wp_enqueue_scripts', 'solusipress_jquery_number_wa' ); | |
function solusipress_jquery_number_wa() { | |
if( is_page( 'forminator-test-wa' ) ) { | |
wp_enqueue_script( 'jquery-number', 'https://businessprofile.solusipress.com/wp-content/uploads/custom-css-js/18.js', array('jquery') ); | |
wp_enqueue_script( 'input-spinner', 'https://businessprofile.solusipress.com/wp-content/uploads/custom-css-js/105.js', array('jquery') ); | |
wp_enqueue_script( 'underscore' ); | |
} | |
} | |
add_action( 'wp_footer', 'solusipress_forminator_whatsapp' ); | |
function solusipress_forminator_whatsapp() { | |
if( is_page( 'forminator-test-wa' ) ) { ?> | |
<script type="text/javascript"> | |
( function($){ | |
wrap_spinner( 'forminator-field-number-1' ); | |
$( '#calculation-1-field' ).hide(); | |
$( '#calculation-1-field' ).parent().append( '<div id="total_html" style="font-weight:600;font-size:22px"></div>' ); | |
set_total(); | |
$( '#calculation-1-field' ).on( 'change', function(){ | |
set_total(); | |
} ); | |
function wrap_spinner( id ) { | |
$( '#'+id ).css( 'display','inline-block' ) | |
.css( 'margin-top', '0px' ) | |
.css( 'border', '1px solid #ccc' ); | |
$( '#'+id ).attr( 'step', '1' ) | |
.attr( 'readonly', 'readonly' ); | |
$( '#'+id ).addClass( 'input-text qty text' ); | |
$( '#'+id ).wrap( '<div class="quantity buttons_added"></div>' ); | |
$( '#'+id ).parent().prepend( '<input type="button" value="-" class="minus">' ); | |
$( '#'+id ).parent().append( '<input type="button" value="+" class="plus">' ); | |
} | |
function set_total() { | |
var tot = $('#calculation-1-field').val(); | |
$( '#total_html' ).html( 'Rp' + $.number( tot, 0, ',', '.' ) ); | |
} | |
/* send to WhatsApp */ | |
(function(){ | |
var data = {}; | |
var valueMap = {}; | |
$( '.forminator-radio input, .forminator-checkbox input' ).each( function(idx, elm) { | |
var optionText = $(elm).parent().find( 'span:last-child' ); | |
valueMap[ $(elm).attr('value') ] = optionText.html(); | |
} ); | |
$( 'body' ).on( 'before:forminator:form:submit', function( formData ) { | |
$( '.forminator-input--wrap, .forminator-radio, .forminator-checkbox' ).each( function( idx, elm ) { | |
var the_input = $(elm).find('input:not([type=button])'); | |
var label = $(elm).closest( '.forminator-field' ).find( '.forminator-label' ).contents().get(0).nodeValue; | |
if( the_input.attr('type') == 'radio' || the_input.attr('type') == 'checkbox' ) { | |
if( the_input.prop( 'checked' ) ) { | |
var the_val = valueMap[ the_input.prop('value') ]; | |
if( data[ label ] != undefined && data[ label ] != '' ) { | |
data[ label ] += ', ' + the_val; | |
} else { | |
data[ label ] = the_val; | |
} | |
} | |
} else { | |
data[ label ] = the_input.val(); | |
} | |
} ); | |
data[ 'Total Price' ] = $( '#total_html' ).html(); | |
} ); | |
$( 'body' ).on( 'forminator:form:submit:success', function( formData ) { | |
var the_text = ""; | |
_.each( data, function(value, key, list){ | |
the_text += key + ": " + value + "\n"; | |
} ); | |
the_text = window.encodeURIComponent( the_text ); | |
var the_phone = '6281314997198'; // ganti nomor dengan milik Anda | |
var url = 'https://api.whatsapp.com/send?phone=' + the_phone + '&text=' + the_text; | |
var isSafari = !!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/); | |
var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; | |
if( isSafari && iOS ) { | |
location = url; | |
} else { | |
window.open( url, '_blank' ); | |
} | |
} ); | |
})(); | |
} )( jQuery ); | |
</script><?php | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment