I discovered this piece of funtion right here. It shows exstra product charges on cart web page. I want to know the way may I show it on single product web page, I imply earlier than including it to cart. And it could be good if I may add a discover on single product web page that will say: ” An additional payment for “Service payment” shall be charged out of your account”. I attemped to do following however that did not work in any respect.
$woocommerce->cart->add_fee || WC()->cart->add_fee( 'Ticket Concierge Cost', $spfee, true, 'customary' );
Thanks in recommendation.
complete code block:
// add product charges
perform df_add_ticket_surcharge( $cart_object ) {
world $woocommerce;
$specialfeecat = 16; // class id for the particular payment
$spfee = 0.00; // initialize particular payment
$spfeeperprod = 0.05; //particular payment per product
foreach ( $cart_object->cart_contents as $key => $worth ) {
$proid = $worth['product_id']; //get the product id from cart
$quantiy = $worth['quantity']; //get amount from cart
$itmprice = $worth['data']->worth; //get product worth
$phrases = get_the_terms( $proid, 'product_cat' ); //get taxonamy of the prducts
if ( $phrases && ! is_wp_error( $phrases ) ) :
foreach ( $phrases as $time period ) {
$catid = $term->term_id;
if($specialfeecat == $catid ) {
$spfee = $spfee + $itmprice * $quantiy * $spfeeperprod;
}
}
endif;
}
if($spfee > 0 ) WC()->cart->add_fee( 'Ticket Concierge Cost', $spfee, true, 'customary' );
}
add_action( 'woocommerce_cart_calculate_fees', 'df_add_ticket_surcharge' );