首页 > 解决方案 > PHP 代码在 Wordpress 插件中不起作用

问题描述

我需要一些关于 wordpress 中的 php 代码的帮助。

我有一个预订网站,当客人要支付住宿费用时(在结帐页面上),我需要添加预订费。我在 wordpress 和 woocommerce 中使用 WP Rentals 主题进行付款。为此,我找到了以下说明:https ://docs.woocommerce.com/document/add-a-surcharge-to-cart-and-checkout-uses-fees-api/ ,所以我使用了下面的代码和代码实现更改的片段,但没有任何反应。不包括额外费用,也没有显示错误。

/**
 * Add a standard $ value surcharge to all transactions in cart / checkout
 */
add_action( 'woocommerce_cart_calculate_fees','wc_add_surcharge' ); 
function wc_add_surcharge() { 
global $woocommerce; 

if ( is_admin() && ! defined( 'DOING_AJAX' ) ) 
return;

$county = array('US');
// change the $fee to set the surcharge to a value to suit
$fee = 1.00;

if ( in_array( WC()->customer->get_shipping_country(), $county ) ) : 
    $woocommerce->cart->add_fee( 'Surcharge', $fee, true, 'standard' );  
endif;
}

我是这个世界上的初学者,所以我不知道错误在哪里。

非常感谢!

标签: phpwordpresswoocommerce

解决方案


推荐阅读