php [WooCommerce Core]根据送货国家/地区添加附加费

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php [WooCommerce Core]根据送货国家/地区添加附加费相关的知识,希望对你有一定的参考价值。

/**
 * Add a 1% surcharge to your cart / checkout based on delivery country
 * Taxes, shipping costs and order subtotal are all included in the surcharge amount
 *
 * Change $percentage to set the surcharge to a value to suit
 *
 * Add countries to array('US'); to include more countries to surcharge
 * http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes for available alpha-2 country codes 
 *
 * Change in_array to !in_array to EXCLUDE the $countries array from surcharges
 *
 * Uses the WooCommerce fees API
 * Add to theme functions.php
 */
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge() {
  global $woocommerce;
 
	if ( is_admin() && ! defined( 'DOING_AJAX' ) )
		return;

 	$county 	= array('US');
	$percentage 	= 0.01;

	if ( in_array( $woocommerce->customer->get_shipping_country(), $county ) ) :
		$surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage;
		$woocommerce->cart->add_fee( 'Surcharge', $surcharge, true, '' );
	endif;
 
}

以上是关于php [WooCommerce Core]根据送货国家/地区添加附加费的主要内容,如果未能解决你的问题,请参考以下文章

php [WooCommerce Core]根据送货国家/地区添加附加费

php [WooCommerce Core]根据送货国家/地区添加附加费

php [WooCommerce Core]根据送货国家/地区添加附加费

php 在WooCommerce通知上添加密送电子邮件

php [不允许PO BOX运输]禁止在WooCommerce中运送邮政信箱

php [不允许PO BOX运输]禁止在WooCommerce中运送邮政信箱