Commit c96ba560 by Pham Huy

update custom fee checkout

parent 80efc9ea
@import url('http://fonts.googleapis.com/css?family=Raleway');
.woocommerce_page_wps-ext-cst-option p{
font-family: raleway;
}
.wps-afoc-main-wrap p{
font-family: raleway;
}
.wps-afoc-main-wrap p a{
text-decoration: none;
}
.wps-afoc-main-wrap .error{
font-family: raleway;
color: #dd0d0d;
font-size: 12px;
font-style: italic;
letter-spacing: 1px;
}
.wps-afoc-main-wrap .error a{
text-decoration: none;
}
.wps-afoc-main-wrap .wps-ext-cst-fees h3{
width: 100%;
border-bottom: 1px solid #DDD;
font-family: raleway;
font-weight: 200;
padding-bottom: 5px;
}
.wps-afoc-main-wrap h2{
border-bottom: 1px solid #DDD;
padding: 8px;
font-size: 22px;
font-family: raleway;
font-weight: 200;
margin-right: 20px;
}
.wps-afoc-main-wrap table tr th{
font-family: raleway;
letter-spacing: 1px;
}
.wps-afoc-main-wrap input[type="text"], select, input[type="number"] {
height: 34px !important;
width: 99% !important;
max-width: 99% !important;
border-radius: 3px;
border: 1px solid #DDD !important;
float: left;
}
.wps-afoc-mainwraper{
width: 100%;
text-align: center;
display: block ruby;
margin-top: 30px;
}
.wps-afoc-main-wrap{
background: white;
padding: 15px;
margin: 15px;
position:relative;
width: 70%;
height: auto;
position:relative;
-webkit-box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset;
-moz-box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset;
box-shadow:0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset;
}
.wps-afoc-main-wrap:before, .wps-afoc-main-wrap:after
{
content:"";
position:absolute;
z-index:-1;
-webkit-box-shadow:0 0 20px rgba(0,0,0,0.8);
-moz-box-shadow:0 0 20px rgba(0,0,0,0.8);
box-shadow:0 0 20px rgba(0,0,0,0.8);
top:10px;
bottom:10px;
left:0;
right:0;
-moz-border-radius:100px / 10px;
border-radius:100px / 10px;
}
.wps-afoc-main-wrap:after
{
right:10px;
left:auto;
-webkit-transform:skew(8deg) rotate(3deg);
-moz-transform:skew(8deg) rotate(3deg);
-ms-transform:skew(8deg) rotate(3deg);
-o-transform:skew(8deg) rotate(3deg);
transform:skew(8deg) rotate(3deg);
}
.cndtn_mode label, .wps-ext-cst-fees label{
display: block;
}
\ No newline at end of file
.form-style-2{
max-width: 500px;
padding: 20px 12px 10px 20px;
font: 13px Arial, Helvetica, sans-serif;
}
.form-style-2-heading{
font-weight: bold;
font-style: italic;
border-bottom: 2px solid #ddd;
margin-bottom: 20px;
font-size: 15px;
padding-bottom: 3px;
}
.form-style-2-heading2{
font-weight: bold;
border-bottom: 2px solid #ddd;
margin-bottom: 20px;
font-size: 15px;
padding-bottom: 3px;
width: 170px;
}
.form-style-2 label{
display: block;
margin: 0px 0px 15px 0px;
}
.form-style-2 label > span{
width: 100px;
font-weight: bold;
float: left;
padding-top: 8px;
padding-right: 5px;
}
.form-style-2 span.required{
color:red;
}
.form-style-2 .tel-number-field{
width: 40px;
text-align: center;
}
.form-style-2 input.input-field{
width: 48%;
}
.form-style-2 input.input-field,
.form-style-2 .tel-number-field,
.form-style-2 .textarea-field,
.form-style-2 .select-field{
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
border: 1px solid #C2C2C2;
box-shadow: 1px 1px 4px #EBEBEB;
-moz-box-shadow: 1px 1px 4px #EBEBEB;
-webkit-box-shadow: 1px 1px 4px #EBEBEB;
border-radius: 3px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
padding: 7px;
outline: none;
}
.form-style-2 .input-field:focus,
.form-style-2 .tel-number-field:focus,
.form-style-2 .textarea-field:focus,
.form-style-2 .select-field:focus{
border: 1px solid #0C0;
}
.form-style-2 .textarea-field{
height:100px;
width: 55%;
}
.form-style-2 input[type=submit],.form-style-2 input[type=reset],
.form-style-2 input[type=button]{
border: none;
padding: 8px 15px 8px 15px;
background: #FF8500;
color: #fff;
box-shadow: 1px 1px 4px #DADADA;
-moz-box-shadow: 1px 1px 4px #DADADA;
-webkit-box-shadow: 1px 1px 4px #DADADA;
border-radius: 3px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
}
.form-style-2 input[type=submit]:hover,
.form-style-2 input[type=button]:hover{
background: #EA7B00;
color: #fff;
}
.required { /* Marker for required fields */
color: red;
}
.errorMsg { /* for error messages */
color: red;
padding-left: 100px;
}
.errorBox { /* for the error input text fields */
border: 2px solid red;
}
.failure {
border: 1px solid #f00;
border-radius: 6px;
font: 17px Arial, Helvetica, sans-serif;
height: 68px;
margin-top: 14px;
padding-left: 10px;
padding-top: 4px;
width: 100%;
}
.success {
border: 1px solid rgb(0,255,0);
border-radius: 6px;
font: 17px Arial, Helvetica, sans-serif;
height: 67px;
margin-top: 14px;
padding-left: 10px;
padding-top: 4px;
width: 100%;
}
#auth_recurring_details table td{
padding: 0px !important;
}
#WP_PYMNT_display_pay_submit_metabox{
width: 100%;
height: 1000px;
}
#WP_PYMNT_display_pay_submit_metabox .payDetails h3{
float: left;
width:80%;
border-bottom: 1px solid grey;
font-family: Raleway;
font-weight: 100;
margin-left: 36px;
}
#WP_PYMNT_display_pay_submit_metabox .payDetails p{
float: left;
width:100%;
margin-left:20px;
padding: 10px;
text-align: center;
font-family: Raleway;
}
#WP_PYMNT_display_pay_submit_metabox .payDetails .left{
float: left;
font-style: italic;
font-weight: 600;
margin: 5px;
}
#WP_PYMNT_display_pay_submit_metabox .payDetails .text{
font-size: 20px;
}
#bootstrap #failure_message{
color: white;
background-color: #FF0000;
border-color: #800000;
}
var $ =jQuery.noConflict();
$(document).ready(function() {
show_hide_cndtn()
});
function show_hide_cndtn(){
$(".cndtn_mode").hide();
var id = $('#ext_cst_apply_cndtn').val();
$("#"+id).show();
}
\ No newline at end of file
<?php
class WPS_EXT_CST_Admin_Settings
{
public static function register_admin_settings(){
add_settings_section("wps-ext-cst-option-section", "Additionnal Fees Settings", null, "wps-ext-cst-options");
register_setting("wps-ext-cst-option-section", "ext_cst_status");
register_setting("wps-ext-cst-option-section", "ext_cst_label");
register_setting("wps-ext-cst-option-section", "ext_cst_label_billing");
register_setting("wps-ext-cst-option-section", "ext_cst_amount_type");
register_setting("wps-ext-cst-option-section", "ext_cst_amount");
register_setting("wps-ext-cst-option-section", "ext_cst_label_css");
register_setting("wps-ext-cst-option-section", "ext_cst_auto_checked");
register_setting("wps-ext-cst-option-section", "ext_cst_apply_cndtn");
}
public static function admin_settings(){
?>
<div class="wps-afoc-mainwraper">
<div class="wps-afoc-main-wrap">
<form method="post" action="options.php">
<?php
settings_fields("wps-ext-cst-option-section");
do_settings_sections("wps-ext-cst-options");
$ext_cst_status = (get_option('ext_cst_status')) ? get_option('ext_cst_status') : 'enable';
$ext_cst_label = (get_option('ext_cst_label')) ? get_option('ext_cst_label') : '';
$ext_cst_label_billing = (get_option('ext_cst_label_billing')) ? get_option('ext_cst_label_billing'): '';
$ext_cst_amount_type = (get_option('ext_cst_amount_type')) ? get_option('ext_cst_amount_type') : 'fixed';
$ext_cst_amount = (get_option('ext_cst_amount')) ? get_option('ext_cst_amount') : 1;
$ext_cst_label_css = (get_option('ext_cst_label_css')) ? get_option('ext_cst_label_css') : '';
$ext_cst_auto_checked = (get_option('ext_cst_auto_checked')) ? get_option('ext_cst_auto_checked') : 'disable';
?>
<p>Before start, please check <a href="https://www.wpsuperiors.com/woo-additional-fees-on-checkout/" target="_blank"> the <i>user guide.</i></a></p>
<?php settings_errors(); ?>
<table class="form-table">
<tbody>
<tr>
<th scope="row"><label><?php _e( 'Status'); ?><label></th>
<td>
<select name="ext_cst_status" id="ext_cst_status">
<option value="enable" <?php if($ext_cst_status=='enable'){echo 'selected';} ?>>Enable</option>
<option value="disable" <?php if($ext_cst_status=='disable'){echo 'selected';} ?>>Disable</option>
</select>
</td>
</tr>
<tr>
<th scope="row"><label><?php _e( 'Label'); ?></label></th>
<td>
<input type="text" class="regular-text code" id="ext_cst_label" name="ext_cst_label" value="<?= $ext_cst_label?>" />
</td>
</tr>
<tr>
<th scope="row"><label><?php _e( 'Label for Billing'); ?></label></th>
<td>
<input type="text" class="regular-text code" id="ext_cst_label_billing" name="ext_cst_label_billing" value="<?= $ext_cst_label_billing?>"/>
</td>
</tr>
<tr>
<th scope="row"><label><?php _e( 'Type'); ?></label></th>
<td>
<select name="ext_cst_amount_type" id="ext_cst_amount_type">
<option value="fixed" <?php if($ext_cst_amount_type=='fixed'){echo 'selected';} ?>>Fixed</option>
<option value="percent" <?php if($ext_cst_amount_type=='percent'){echo 'selected';} ?>>Percentage</option>
</select>
</td>
</tr>
<tr>
<th scope="row"><label><?php _e( 'Amount'); ?></label></th>
<td>
<input type="number" step="any" name="ext_cst_amount" class="regular-text code" id="ext_cst_amount" value="<?php echo $ext_cst_amount; ?>"/>
</td>
</tr>
<tr>
<th scope="row"><label><?php _e( 'Auto-checked / Auto-applied the fees'); ?></label></th>
<td>
<select name="ext_cst_auto_checked" id="ext_cst_auto_checked">
<option value="enable" <?php if($ext_cst_auto_checked=='enable'){echo 'selected';} ?>>Enable</option>
<option value="disable" <?php if($ext_cst_auto_checked=='disable'){echo 'selected';} ?>>Disable</option>
</select>
</td>
</tr>
<tr>
<th scope="row"><label><?php _e( 'Condition'); ?></label></th>
<td>
<select name="ext_cst_apply_cndtn" id="ext_cst_apply_cndtn" onchange="show_hide_cndtn()">
<option value="all" selected>All</option>
<option value="cart_total_amount">Cart Total Amount</option>
<option value="cart_no_product">Number of Product on Cart</option>
<option value="selected_product">Selected Product</option>
</select>
<p class="error">Available with <a target="_blank;" href="https://www.wpsuperiors.com/woo-additional-fees-on-checkout/">premium version</a>.</p>
</td>
</tr>
<tr id="cart_total_amount" class="cndtn_mode">
<th scope="row"><label><?php _e( 'Cart Amount'); ?></label></th>
<td>
<label>Minimum</label>
<input type="number" name="cart_total_amount_min" class="small-text" id="cart_total_amount_min" value="10"/>
<label>Maximum</label>
<input type="number" name="cart_total_amount_max" class="small-text" id="cart_total_amount_max" value="100"/>
<p class="error">Available with <a target="_blank;" href="https://www.wpsuperiors.com/woo-additional-fees-on-checkout/">premium version</a>.</p>
</td>
</tr>
<tr id="cart_no_product" class="cndtn_mode">
<th scope="row"><label><?php _e( 'No. Of Product on Cart'); ?></label></th>
<td>
<label>Minimum</label>
<input type="number" name="cart_no_product_min" class="small-text" id="cart_no_product_min" value="2"/>
<label>Maximum</label>
<input type="number" name="cart_no_product_max" class="small-text" id="cart_no_product_max" value="5"/>
<p class="error">Available with <a target="_blank;" href="https://www.wpsuperiors.com/woo-additional-fees-on-checkout/">premium version</a>.</p>
</td>
</tr>
<tr id="selected_product" class="cndtn_mode">
<th scope="row"><label><?php _e( 'Selected Product'); ?></label></th>
<td>
<select name="selected_product_id" id="selected_product_id">
<option value="selected_product" selected>Selected Product</option>
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => -1
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();?>
<option value="<?php echo get_the_ID(); ?>"><?php echo get_the_title(); ?></option>
<?php
endwhile;
} else {
echo '<option>No products found</option>';
}
wp_reset_postdata();
?>
</select>
<p class="error">Available with <a target="_blank;" href="https://www.wpsuperiors.com/woo-additional-fees-on-checkout/">premium version</a>.</p>
</td>
</tr>
<tr>
<th scope="row"><label><?php _e( 'Required Field'); ?></label></th>
<td>
<select name="ext_cst_is_required" id="ext_cst_is_required">
<option value="no">No</option>
<option value="yes">Yes</option>
</select>
<p class="error">Available with <a target="_blank;" href="https://www.wpsuperiors.com/woo-additional-fees-on-checkout/">premium version</a>.</p>
</td>
</tr>
<tr>
<th scope="row"><label><?php _e( 'Custom CSS'); ?></label></th>
<td>
<textarea class="large-text code" name="ext_cst_label_css" id="ext_cst_label_css" placeholder=""></textarea>
</td>
</tr>
</tbody>
</table>
<div id="wps_custom_fees_add_more">
<input type="hidden" id="current_number_fees" value="1" />
</div>
<div class="wafoc-bottom-line" style="width: 100%; height: 50px;">
<div class="wafoc-bottom-line-button" style="float: left;">
<?php
submit_button();
?>
</div>
<div class="wafoc-bottom-line-add-new" style="float: right; margin-top: 30px; margin-right: 20px;">
<a href="javascript:void(0);" class="button button-secondary" style="font-family: raleway;">Add More New Fees</a>
</div>
</div>
</form>
</div>
</div>
<!-- <p style="margin-top:30px; font-size:12px; text-align: center; width: 100%;">Confused? Need our help? Feel free to write on us at <a style="text-decoration:none;" href="mailto:support@wpsuperiors.com">support@wpsuperiors.com</a> OR submit your query through <a style="text-decoration:none;" href="http://www.wpsuperiors.com/contact-us/" target="_blank">Contact Us</a></p>
<p style="text-align: center; width: 100%;">Like this plugin? Leave a
<span style="font-size:200%;color:yellow;">&starf;</span>
<span style="font-size:200%;color:yellow;">&starf;</span>
<span style="font-size:200%;color:yellow;">&starf;</span>
<span style="font-size:200%;color:yellow;">&starf;</span>
<span style="font-size:200%;color:yellow;">&starf;</span> rating at <a style=" font-style: italic; text-decoration: none;" href="https://wordpress.org/support/plugin/woo-additional-fees-on-checkout-wordpress/reviews/#new-post" target="_blank;">WordPress</a>
</p> -->
<script type="text/javascript">
jQuery(".wafoc-bottom-line-add-new a").click(function(){
var numberCount = $('#current_number_fees').val();
var data = {
'action': 'wps_generate_new_fees',
'dataType': "html",
'number': numberCount
};
$(".wafoc-bottom-line-add-new a").html('Generating...');
jQuery.post(ajaxurl, data, function(response) {
$("#wps_custom_fees_add_more").append(response);
$(".wafoc-bottom-line-add-new a").html('Add More New Fees');
numberCount = parseInt(numberCount)+1
$('#current_number_fees').val(numberCount);
show_hide_cndtn_extra(numberCount);
});
});
function show_hide_cndtn_extra(s_id){
$(".cndtn_mode_extra"+s_id).hide();
var id = $('#ext_cst_apply_cndtn_extra'+s_id).val();
$("#"+id+s_id).show();
}
function remove_fees( id ){
var numberCount = $('#current_number_fees').val();
var r = confirm("Are you want to delete?");
if (r == true) {
$.when($("#fees"+id).fadeOut('slow') ).done(function() {
$("#fees"+id).remove();
numberCount = parseInt(numberCount)-1;
$('#current_number_fees').val(numberCount)
var flagCount = 2;
$('#current_number_fees').val(numberCount);
alert("Successfully deleted.")
});
}
}
</script>
<?php
}
}new WPS_EXT_CST_Admin_Settings();
?>
\ No newline at end of file
<?php
class WPS_EXT_CST_Admin
{
public static function init(){
add_action( 'admin_menu', array( 'WPS_EXT_CST_Admin', 'add_menu_extra_fee_option' ) );
add_action( "admin_init", array('WPS_EXT_CST_Admin_Settings',"register_admin_settings"));
add_action( 'wp_ajax_wps_generate_new_fees', array('WPS_EXT_CST_Admin','wps_generate_new_fees' ));
add_action( 'admin_enqueue_scripts', array('WPS_EXT_CST_Admin','selectively_enqueue_admin_script' ));
}
public static function add_menu_extra_fee_option() {
$setting_menu_create = add_submenu_page( 'woocommerce' , __( 'Additional Fees'), __( 'Additional Fees' ), 'manage_options', 'wps-ext-cst-option', array(
'WPS_EXT_CST_Admin_Settings','admin_settings'));
}
public static function selectively_enqueue_admin_script(){
wp_register_style( 'WPS_EXT_CST_ADMIN_CSS', WPS_EXT_CST_CSS . '/admin-style.css', false, '1.0.0' );
wp_enqueue_style( 'WPS_EXT_CST_ADMIN_CSS' );
}
public static function wps_generate_new_fees(){
?>
<div class="wps-ext-cst-fees" id="fees<?php echo $_POST['number'];?>">
<h3>
<span class="fees-title">Unlabelled Fees</span>
<span style="float:right; color:red; cursor: pointer;" class="dashicons dashicons-trash" onclick="remove_fees(<?php echo $_POST['number'];?>)"></span>
</h3>
<p class="error">Available with <a target="_blank;" href="https://www.wpsuperiors.com/woo-additional-fees-on-checkout/">premium version</a>.</p>
<table class="form-table">
<tbody>
<tr>
<th scope="row"><label><?php _e( 'Status'); ?><label></th>
<td>
<select id="ext_cst_status_extra">
<option value="enable">Enable</option>
<option value="disable">Disable</option>
</select>
</td>
</tr>
<tr>
<th scope="row"><label><?php _e( 'Label'); ?></labe></td>
<td>
<input type="text" class="regular-text code" id="ext_cst_label_extra" value="<?php echo 'Unlabelled Fees #'.$_POST['number'];?>"/>
</td>
</tr>
<tr>
<th scope="row"><label><?php _e( 'Label for Billing'); ?></labe></td>
<td>
<input type="text" class="regular-text code" id="ext_cst_label_billing_extra" value="Unlabelled Fees #<?php echo $_POST['number'];?>"/>
</td>
</tr>
<tr>
<th scope="row"><label><?php _e( 'Type'); ?><label></th>
<td>
<select id="ext_cst_amount_type_extra">
<option value="fixed">Fixed</option>
<option value="percent">Percentage</option>
</select>
</td>
</tr>
<tr>
<th scope="row"><label><?php _e( 'Auto-checked / Auto-applied the fees'); ?><label></th>
<td>
<select id="ext_cst_auto_checked_extra">
<option value="enable">Enable</option>
<option value="disable">Disable</option>
</select>
</td>
</tr>
<tr>
<th scope="row"><label><?php _e( 'Amount'); ?></labe></td>
<td>
<input type="number" name="ext_cst_extra[<?php echo $_POST['number'];?>][amount]" class="fees_amount regular-text code" id="ext_cst_amount_extra<?php echo $_POST['number'];?>" value="1"/>
</td>
</tr>
<tr>
<th scope="row"><label><?php _e( 'Condition'); ?><label></th>
<td>
<select data-id="<?php echo $_POST['number'];?>" id="ext_cst_apply_cndtn_extra<?php echo $_POST['number'];?>" class="ext_cst_cndtn_dropdown" onchange="show_hide_cndtn_extra(<?php echo $_POST['number'];?>)">
<option value="all">All</option>
<option value="cart_total_amount">Cart Total Amount</option>
<option value="cart_no_product">Number of Product on Cart</option>
<option value="selected_product">Selected Product</option>
</select>
</td>
</tr>
<tr id="cart_total_amount<?php echo $_POST['number'];?>" class="cndtn_mode_extra<?php echo $_POST['number'];?>" style="display: none;">
<th scope="row"><label><?php _e( 'Cart Amount'); ?></labe></td>
<td>
<label>Minimum</label>
<input type="number" class="small-text" id="cart_total_amount_min_extra" value=""/>
<label>Maximum</label>
<input type="number" class="small-text" id="cart_total_amount_max_extra" value=""/>
</td>
</tr>
<tr id="cart_no_product<?php echo $_POST['number'];?>" class="cndtn_mode_extra<?php echo $_POST['number'];?>" style="display: none;">
<th scope="row"><label><?php _e( 'No. Of Product on Cart'); ?></labe></td>
<td>
<label>Minimum</label>
<input type="number" class="small-text" id="cart_no_product_min_extra" value=""/>
<label>Maximum</label>
<input type="number" class="small-text" id="cart_no_product_max_extra" value=""/>
</td>
</tr>
<tr id="selected_product<?php echo $_POST['number'];?>" class="cndtn_mode_extra<?php echo $_POST['number'];?>" style="display: none;">
<th scope="row"><label><?php _e( 'Selected Product'); ?><label></th>
<td>
<select id="selected_product_id_extra">
<option value="selected_product">Selected Product</option>
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => -1
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();?>
<option value="<?php echo get_the_ID(); ?>"><?php echo get_the_title(); ?></option>
<?php
endwhile;
} else {
echo '<option>No products found</option>';
}
wp_reset_postdata();
?>
</select>
</td>
</tr>
<tr>
<th scope="row"><label><?php _e( 'Required Field'); ?></labe></td>
<td>
<select name="ext_cst_is_required" id="ext_cst_is_required">
<option value="no" <?php if($ext_cst_is_required=='no'){ echo 'selected';} ?>>No</option>
<option value="yes" <?php if($ext_cst_is_required=='yes'){ echo 'selected';} ?>>Yes</option>
</select>
</td>
</tr>
</tbody>
</table>
</div>
<?php
die;
}
}new WPS_EXT_CST_Admin();
?>
\ No newline at end of file
<?php
class WPS_EXT_CST_Frontend
{
public function __construct()
{
$ext_cst_status = (get_option('ext_cst_status')) ? get_option('ext_cst_status') : 'enable';
if($ext_cst_status == 'enable' && !is_admin()){
add_action( 'woocommerce_after_order_notes', array($this,'add_option_to_checkout' ));
add_action( 'wp_footer', array($this,'add_script_on_checkout' ));
add_action( 'woocommerce_cart_calculate_fees', array($this,'calculate_cost' ));
}
}
public static function get_condition( $cndtn ){
switch ($cndtn) {
case 'all':
return true;
break;
default:
return true;
break;
}
}
public static function add_option_to_checkout( $checkout ){
global $woocommerce;
$ext_cst_apply_cndtn = 'all';
$get_cndtn = WPS_EXT_CST_Frontend::get_condition($ext_cst_apply_cndtn);
if($get_cndtn){
$ext_cst_label = get_option('ext_cst_label') ? get_option('ext_cst_label') : 'Phụ phí';
echo '<div id="wp_ext_cst_field">';
woocommerce_form_field( 'wps_ext_cst_label', array(
'type' => 'checkbox',
'class' => array('wps_ext_cst_label form-row-wide'),
'label' => $ext_cst_label,
'placeholder' => __(''),
), $checkout->get_value( 'wps_ext_cst_label' ));
echo '</div>';
}
}
public static function add_script_on_checkout(){
if (is_checkout()) {
$ext_cst_label_css = (get_option('ext_cst_label_css')) ? get_option('ext_cst_label_css') : '';
$ext_cst_auto_checked = (get_option('ext_cst_auto_checked')) ? get_option('ext_cst_auto_checked') : 'disable';
?>
<script type="text/javascript">
jQuery( document ).ready(function( $ ) {
$('#wps_ext_cst_label').click(function(){
jQuery('body').trigger('update_checkout');
});
});
</script>
<style>
<?php echo $ext_cst_label_css; ?>
</style>
<?php
}
if( $ext_cst_auto_checked == 'enable' ){
?>
<script type="text/javascript">jQuery('#wps_ext_cst_label').trigger('click');</script>
<?php
}
}
public static function calculate_cost( $cart ){
$ext_cst_label_billing = (get_option('ext_cst_label_billing')) ? get_option('ext_cst_label_billing') :'Phụ phí';
$ext_cst_amount_type = (get_option('ext_cst_amount_type')) ? get_option('ext_cst_amount_type') : 'fixed';
$ext_cst_amount = (get_option('ext_cst_amount')) ? get_option('ext_cst_amount') : 1;
if ( ! $_POST || ( is_admin() && ! is_ajax() ) ) {
return;
}
if ( isset( $_POST['post_data'] ) ) {
parse_str( $_POST['post_data'], $post_data );
} else {
$post_data = $_POST;
}
if (isset($post_data['wps_ext_cst_label'])) {
global $woocommerce;
switch ($ext_cst_amount_type) {
case 'fixed':
$extracost = $ext_cst_amount;
break;
case 'percent':
$extracost = $woocommerce->cart->cart_contents_total * $ext_cst_amount;
$extracost = $extracost/100;
break;
default:
$extracost = $ext_cst_amount;
break;
}
WC()->cart->add_fee( $ext_cst_label_billing, $extracost );
}
}
}new WPS_EXT_CST_Frontend();
?>
\ No newline at end of file
<?php
class WPS_EXT_CST_Main
{
public function __construct()
{
add_action('woocommerce_init', array('WPS_EXT_CST_Admin', 'init'));
add_action('admin_init',array($this, 'reg_script'));
}
public static function reg_script(){
wp_register_script('WPS_EXT_CST_ADMIN_JS', WPS_EXT_CST_JS.'/wps-ext-cst.js', array('jquery'),'1.1', true);
wp_enqueue_script('WPS_EXT_CST_ADMIN_JS');
}
}new WPS_EXT_CST_Main();
?>
\ No newline at end of file
=== WooCommerce Additional Fees On Checkout (Free) ===
Contributors: WPSuperiors
Donate link: http://www.wpsuperiors.com/donate/
Tags: woocommerce extra cost, woocommerce additional cost, woocommerce checkout cost, gift cost, woocommerce surcharge, additional fees, checkout fees.
Requires at least: 3.0.1
Tested up to: 5.3
Stable tag: 5.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Create required or non-required multiple fields on checkout page to apply an extra fixed or percentage cost uport cart total, based on individual Product, Cart total amount and etc.
== Description ==
= Introduction =
The ecommerce users are frequently need to give their purchased product as a gift to their near and dear ones, and at the same time the store owner wants to earn some extra money.
In one words, Woo Additional Fees plugin makes it very simple.
Woo Additional Fees plugin built to integrate seamlessly with WordPress, that gives store owners complete control to adjust Labels, amount, percentage or fixed price calculation etc.
Compatible with 90% of all leading woocommerce theme layouts including OceanWP, Astra, Zoa, Tesseractand many more.
Play the settings from, WooCommerce > Additional Fees.
= DEMO =
[Frontend Checkout Page](https://trydemo.wpsuperiors.com/wafc/checkout/?add-to-cart=167&quantity=10)
[Backend Settings Page](https://trydemo.wpsuperiors.com/wafc/wp-admin/)
= Free Version Features =
- Enable/Disable the fees/cost.
- Applicable amount type
-- Fixed
-- Percentage.
- Add amount.( support decimal amount )
- Auto check / Auto applied fees.
- Add CSS.
- Easy to use, just active and start.
- User manual / Guide available.
= Premium Version Features =
- = NEW = Set each additional fee fields as Required or Non-required.
- Add unlimited number of fees for checkout page. [Check Case Studies](https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout-case-study/)
- All the Free Version features.
- Custom label for the option in checkout page.
- Custom label on order billing details.
- Conditions to apply amount.
-- Each individual Product basis.
-- Based on Cart Total Amount Basis(Max/Min).
-- Based on Number of Product available in Cart(Max/Min).
- One Time Cost.
- Use for Unlimited Site.
- Priority Technical Support 24*7 hours for Lifetime.
To Know more please visit [WooCommerce Additional Fees On Checkout PREMIUM Page](https://www.wpsuperiors.com/product/woo-additional-fees-on-checkout/)
Keep in mind, the amount you set is always effected only on cart totals.
The option will be displayed as checkbox, on check the amount will be added or deleted.
If any one check this, and checkout then you can see the option in backend on that particular order details.
Also the frontend user can also see that imformation on their order details.
<strong>N.B:</strong> Please activate WooCommerce before you activate Woo Additional Fees plugin, and both Free and Premium version not activate at the same time. Please deactivate one version before you going to activate another version.
Let's check it out.
Felling confused? Getting errors/bugs?
We are happy to hear from you. Let's email us on <strong>support@wpsuperiors.com</strong>
== Installation ==
= Minimum Requirements =
* WooCommerce 2.6 requires WordPress 4.4+
= Automatic installation =
Automatic installation is the easiest option as WordPress handles the file transfers itself and you don’t need to leave your web browser. To do an automatic install of WooCommerce, log in to your WordPress dashboard, navigate to the Plugins menu and click Add New.
In the search field type “WooCommerce Additional Fees On Checkout” and click Search Plugins. Once you’ve found our plugin.You can install it by simply clicking “Install Now”.
And activate it.
*Keep In Mind, Before activating “WooCommerce Additional Fees On Checkout” activate “WooCommerce”
= Manual installation =
The manual installation method involves downloading our plugin and uploading it to your webserver via your favourite FTP application. The WordPress codex contains [instructions on how to do this here](https://wordpress.org/support/article/managing-plugins/).
1. Upload the plugin files to the `/wp-content/plugins/` directory, or install the plugin through the WordPress plugins screen directly.
2. Activate the plugin through the 'Plugins' screen in WordPress
3. Goto WooCommerce->Additional Fees, and play with settings.
== Frequently Asked Questions ==
= Where can I find documentation and user guides? =
For help setting up and configuring please refer to [WooCommerce Additional Fees On Checkout User Guide](http://www.wpsuperiors.com/woo-additional-fees-on-checkout/)
= Where can I find more knowdge on this? =
Please check it out
[WooCommerce Additional Fees On Checkout KB](http://www.wpsuperiors.com/knowledge-base/woo-additional-fees-on-checkout/)
= Where can I get support or talk to other users? =
If you get stuck, you can ask for help in the [WP Suport Forum](http://wordpress.org/support/plugin/woo-additional-fees-on-checkout-wordpress).
Or You can email us support@wpsuperiors.com
= Where can I can find case studies? =
Please go through [Check Case Studies](https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout-case-study/)
= Where can I request new features? =
You can email us support@wpsuperiors.com
== Screenshots ==
1. screenshot-1, SingleFees Settings
2. screenshot-2, SingleFees Validation CheckoutPage
3. screenshot-3, SingleFees Admin Order
4. screenshot-4, SingleFess Checkout Complete
5. screenshot-5, SingleFess MyAccount OrderDetails
6. screenshot-6, MultipleFees Settings
7. screenshot-7, MultipleFees Validation CheckoutPage
8. scrrenshot-8, MultipleFees Admin Order
9. screenshot-9, MultipleFess MyAccount OrderDetails
== Changelog ==
= 1.0.0 - 16/06/2017 =
*First Upload*
= 1.0.3 - 12/08/2017 =
*Comaptability with Wordpress,4.8.1*
= 1.0.4 - 10/09/2017 =
*https problem solved*
= 1.0.7 - 16/06/2018 =
*Different bugs resolved*
*One premium feature introdced*
*Admin setting design changed*
= 1.0.9 - 11/8/2018 =
*Responsive issue solved*
*Unnecessary banner removed*
*User experience upgradation*
= 1.1.0 - 19/8/2018 =
*Tested with WooCommerce 3.4.4*
= 1.1.1 - 11/11/2018 =
*Multiple fees development*
*CSS correction*
*Logic correction*
*Tested with WooCommerce 3.5.1*
= 1.1.2 - 18/11/2018 =
*Support decimal amount*
= 1.1.5 - 25/1/2019 =
*Fixed checkout page CSS issue and tested with multiple woocommerce themes*
= 1.1.6 - 23/2/2019 =
*Compatible with WordPress 5.1 and "Required Field" feature released.*
= 1.1.7 - 10/3/2019 =
*Tested with WooCommerce 3.5.6*
= 1.1.8 - 21/3/2019 =
*Tested with WooCommerce 3.5.7*
= 1.1.9 - 20/4/2019 =
*Tested with WooCommerce 3.6.1*
= 1.2.0 - 11/5/2019 =
*Update for WooCommerce 3.6.2 and WordPress 5.2*
= 1.2.1 - 07/06/2019 =
*Auto Check / Auto applied feature released*
*Compatibility test with WooCommerce 3.6.5*
= 1.2.2 - 15/08/2019 =
*Comaptiabilty test with WooCommerce 3.7.0*
*Minor bug fixation*
= 1.2.3 - 13/10/2019 =
*WooCommerce 3.7.1 compatiability update*
= 1.2.4 - 17/11/2019 =
*Compatibility test with WordPress 5.3 and WooCommerce 3.8.0*
= 1.2.5 - 25/12/2019 =
* UI enhancement, auto-checked option solved, WooCommerce compatibility check *
= 1.2.6 - 29/12/2019 =
* CSS fixation for admin *
= 1.2.7 - 02/02/2020 =
* WooCommerce 3.9.1 compatibility issue fixed *
* Auto-checked issue fixed *
\ No newline at end of file
<?php
/*
Plugin Name: WooCommerce Additional Fees On Checkout (Free)
Plugin URI: http://www.wpsuperiors.com/product/woo-additional-fees-on-checkout/
Description: Create an field on checkout page to apply an extra cost. *Do not activate FREE and PREMIUM at the same time.*
Version: 1.2.7
Author: WPSuperiors
Author URI: http://wpsuperiors.com/
* WC requires at least: 3.5.0
* WC tested up to: 3.9.1
*/
if ( ! defined( 'ABSPATH' ) ) {
wp_die('Please Go Back');
exit;
}
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
add_action( 'admin_init', 'active_check' );
function active_check() {
if ( is_admin() && current_user_can( 'activate_plugins' ) && !is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
add_action( 'admin_notices', 'active_failed_notice' );
deactivate_plugins( plugin_basename( __FILE__ ) );
if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}
}
}
function active_failed_notice(){
?><div class="error"><p>Please Activate <b>WooCommerce</b> Plugin, Before You Proceed To Activate <b>WooCommerce Additional Fees On Checkout (Free)</b> Plugin.</p></div><?php
}
define('WPS_EXT_CST', 'Woo Extra Cost/Fees');
define( 'WPS_EXT_CST_BASE', plugin_basename( __FILE__ ) );
define( 'WPS_EXT_CST_DIR', plugin_dir_path( __FILE__ ) );
define( 'WPS_EXT_CST_URL', plugin_dir_url( __FILE__ ) );
define( 'WPS_EXT_CST_AST', plugin_dir_url( __FILE__ ).'assets/' );
define( 'WPS_EXT_CST_JS', plugin_dir_url( __FILE__ ).'assets/js' );
define( 'WPS_EXT_CST_CSS', plugin_dir_url( __FILE__ ).'assets/CSS' );
require 'classes/wps-ext-cst-main.php';
require 'classes/wps-ext-cst-admin.php';
require 'classes/wps-ext-cst-admin-settings.php';
require 'classes/wps-ext-cst-frontend.php';
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wps_wafc_action_links_free' );
function wps_wafc_action_links_free($links)
{
$plugin_links = array(
'<a href="' . admin_url( 'admin.php?page=wps-ext-cst-option' ) . '">' . __( 'Settings') . '</a>',
'<a href="https://www.wpsuperiors.com/contact-us/">' . __( 'Get Support') . '</a>',
'<a href="https://www.wpsuperiors.com/woocommerce-additional-fees-on-checkout/">' . __( 'Get Premium') . '</a>'
);
return array_merge( $plugin_links, $links );
}
add_action(
'wp_footer'
, function() {
?>
<script>
jQuery( document ).ready(function( $ ) {
jQuery('body').trigger('update_checkout');
});
</script>
<?php
}
, 21
);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment