我在尝试使用woocommerce_before_cart_table
自定义值进行一些计算并将它们传递给woocommerce_cart_calculate_fees
. 问题是 woocommerce_before_cart_table
先加载,我无法将这些值传递woocommerce_before_cart_table
给woocommerce_cart_calculate_fees
钩子……</p>
add_action( 'woocommerce_before_cart_table', 'my_custom_cart_items_raw_output');
function my_custom_cart_items_raw_output() {
//$sum = array();
foreach(WC()->cart->get_cart() as $cart_item_key => $item_values){
global $wpdb;
$mylink = $wpdb->get_row( "SELECT * FROM tax_hotel_and_name WHERE hotel_id= '".$item_values['st_booking_data']['room_id']."'" );
$x = $mylink->tax_percentage;
// Outputting the raw Cart items data to retrieve Bookings related data
$y = $item_values['st_booking_data']['total_price'];
$sum[]= ($x / 100) * $y;
($x / 100) * $y.'<br>';
// echo '<pre>'; print_r($item_values); echo '</pre>';
}
array_sum($sum);
}
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
// $percentage = 0;
// $taxes = array_sum($woocommerce->cart->taxes);
// $surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total + $taxes ) * $percentage;
// // Make sure that you return false here. We can't double tax people!
$woocommerce->cart->add_fee( 'Processing Fee', 12, false, '' );
}
我怎样才能通过woocommerce_cart_calculate_fees
钩子计算?
谢谢