Skip to content

Instantly share code, notes, and snippets.

@yeriepiscesa
Last active July 5, 2020 02:28
Show Gist options
  • Save yeriepiscesa/4485148b7bea2e0e60daaa942a79d8b8 to your computer and use it in GitHub Desktop.
Save yeriepiscesa/4485148b7bea2e0e60daaa942a79d8b8 to your computer and use it in GitHub Desktop.
Simple Point of Sale using WooCommerce & Contact Form 7 with CF7SendWA (https://solusipress.com/sistem-kasir-sederhana-dengan-woocommerce-dan-contact-form-7/)
woo_checkout_first_name: your-name
woo_checkout_phone: whatsapp
woo_checkout_order_note: order-note
[text your-name id:your-name "Guest"]
<table width="100%">
<tr>
<td>No&nbsp;WA</td>
<td>[tel* whatsapp id:whatsapp-number placeholder "Nomor WA Customer"]</td>
</tr>
<tr>
<td colspan="2">
[textarea order-note placeholder "Catatan"]
</td>
</tr>
<tr>
<td>Uang&nbsp;Dibayar</td>
<td>[number* total_paid id:paid-bill class:money "0"]</td>
</tr>
<tr>
<td>Uang&nbsp;Kembali</td>
<td>[number paid_change id:change-bill class:money "0"]</td>
<tr>
</table>
[submit "Bayar Sekarang"]
Toko UKM Sehat
Jl. Untung No 19. Jakarta
WA 08123456790
[woo-orderdetail]
Note:
[order-note]
<?php
add_action( 'wp_enqueue_scripts', 'solusipress_load_pos_lite_scripts', 999 );
function solusipress_load_pos_lite_scripts(){
if( is_page( 'pos-lite' ) ) {
wp_enqueue_script( 'sticky' );
}
}
add_action( 'woocommerce_email', function( $email_class ){
if( isset( $_POST['total_paid'] ) ) {
remove_action( 'woocommerce_order_status_pending_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
remove_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) );
}
} );
add_filter( 'cf7sendwa_disable_woocommerce_email', function( $bool ){
if( isset( $_POST['total_paid'] ) ) {
$bool = true;
}
return $bool;
} );
add_filter( 'wpcf7_form_elements', function( $content ){
$str_pos = strpos( $content, 'name="total_paid"' );
if( $str_pos ){
$content = substr_replace( $content, ' data-bind="textInput: pos_bill_paid" ', $str_pos, 0 );
}
$str_pos = strpos( $content, 'name="paid_change"' );
if( $str_pos ) {
$content = substr_replace( $content, ' data-bind="value: pos_bill_change" ', $str_pos, 0 );
}
return $content;
} );
function solusipress_set_cash_payment( $order, $cf7data ){
if( isset( $_POST['total_paid'] ) ) {
$order->set_payment_method( 'cash' );
$order->set_payment_method_title( 'Cash in Store' );
$order->set_status( 'completed', '', true );
}
}
add_action( 'cf7sendwa_before_woo_order_save', 'solusipress_set_cash_payment', 10, 2 );
add_action( 'wp_footer', 'solusipress_pos_module', 9999 );
function solusipress_pos_module(){
if( is_page( 'pos-lite' ) ) {
?>
<style type="text/css">
.wpcf7-form-control { margin-bottom:5px; width: 100%; color: #000; }
.cf7sendwa-quickshop-checkout { max-height: 50vh; }
.cf7sendwa-quickshop-checkout-container textarea {
min-height:0px;
height: 100px;
}
#paid-bill, #change-bill { text-align: right; }
#your-name { display:none!important; }
</style>
<script type="text/javascript">
var pos_vm = Woo_QuickShop_Cart.getVM();
Woo_QuickShop_Cart.prototype.pos_bill_paid = ko.observable(0);
Woo_QuickShop_Cart.prototype.pos_bill_change = ko.pureComputed( function(){
return this.pos_bill_paid() - this.total();
}, pos_vm );
if( cf7sendwa.is_mobile == '1' ) {
cf7sendwa_qsreview.sticky = "no";
}
(function($){
$(document).ready( function(){
$( '#whatsapp-number' ).val( '<?php echo get_option( 'cf7sendwa_number', '' ); ?>' );
$( '#form-pos-lite' ).sticky({topSpacing:20});
$( '#change-bill' ).attr('readonly', true);
$( '.money' ).focus( function(){
$(this).select();
} );
$( '#whatsapp-number' ).click( function(){
var input = this;
input.focus();
input.setSelectionRange(0,999);
} );
Hooks.add_filter( 'cf7sendwa_checkout_order_item', function( txt, options ){
var paid_bill = $.number( pos_vm.pos_bill_paid(), cf7sendwa.decimals, cf7sendwa.decimal_separator, cf7sendwa.thousand_separator );
var bill_change = $.number( pos_vm.pos_bill_change(), cf7sendwa.decimals, cf7sendwa.decimal_separator, cf7sendwa.thousand_separator );
var additionals = 'Bayar : Rp ' + paid_bill + "\n" +
'Kembali : Rp ' + bill_change;
txt = txt + "\n" + additionals;
return txt;
} );
$( '.wpcf7-submit' ).click( function( evt ){
if( pos_vm.pos_bill_change() < 0 ) {
alert("Pembayaran kurang");
evt.preventDefault();
}
} );
} );
})(jQuery);
</script><?php
}
}
<div class="grid-60">
<input type="text" id="cf7sendwa_woo_text_filter"
style="width:100%; margin-bottom: 25px;"
placeholder="type to search">
[cf7sendwa-quickshop]
</div>
<div class="grid-40">
[cf7sendwa-checkout sticky="yes" top="50" bottom="400"]
[contact-form-7-wa id="366" title="POS Lite"]
[/cf7sendwa-checkout]
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment