<?php
/* Increase cart item prices based on payment method in WooCommerce BEGIN */
add_action( 'woocommerce_cart_calculate_fees','ts_add_discount', 20, 1 );
function ts_add_discount( $cart_object ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
$label_text=__("");
$service_charge=0;
// Mention the payment method e.g. cod, bacs, cheque or paypal
$cart_total = $cart_object->subtotal_ex_tax;
$chosen_payment_method = WC()->session->get('chosen_payment_method'); //Get the selected payment method
if( $chosen_payment_method == "paypal" ){
$label_text = __( "PayPal Service Charge" );
// The service charge to apply
$service_charge=200;
}
else if( $chosen_payment_method == "cod"){
$label_text = __( "Credit Card Service Charge" );
// The service charge to apply
/* $service_charge=3.5; */
$service_charge = (($cart_total / .965) - $cart_total); /* This is dividing to get a 3.5 percent of the price as a fee */
}
else if( $chosen_payment_method == "bacs"){
$label_text = __( "Direct Bank Transfer Service Charge" );
$service_charge=100;
}
else if( $chosen_payment_method == "cheque"){
$label_text = __( "Cheque Payment Service Charge" );
$service_charge=150;
}
else {
$label_text = __( "Credit Card Fee" );
$service_charge=0;
}
// Adding the service charge
$cart_object->add_fee( $label_text, $service_charge, false );
}
add_action( 'woocommerce_review_order_before_payment', 'ts_refresh_payment_method' );
function ts_refresh_payment_method(){
// jQuery
?>
<script type="text/javascript">
(function($){
$( 'form.checkout' ).on( 'change', 'input[name^="payment_method"]', function() {
$('body').trigger('update_checkout');
});
})(jQuery);
</script>
<?php
}
/* Increase cart item prices based on payment method in WooCommerce END */
Home
A full service web design company.
Portfolio
Responsive mobile ready web designs.
Pricing
Budget ranges for a website design.
Hosting
Recommended web host companies.
Reviews
Real Reviews from real clients.
Services
Website design services.
The Process
The web design process according to Divi Guy.
About
Who is the Divi Guy?
Logo Design
Logos I've made over the years.
Contact
Contact the Divi Guy now.
0 Comments