php - 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;
}
我是这个世界上的初学者,所以我不知道错误在哪里。
非常感谢!
解决方案
推荐阅读
- javascript - 在循环中执行 fetch 语句 javascript async-await
- arrays - 将列中的列表转换为数组
- google-bigquery - 为什么只在“from”子句之后才提供 UNNEST
- batch-file - 写入文本文件 - 批处理
- python - python程序的数据库存储在哪里?
- angular - Angular Reactive Forms - 如何在多个表单之间共享控件/组
- javascript - JavaScript 类中的乘法方法返回 NAN
- reactjs - 等待所有承诺成功
- c# - Newtonsoft Json 不会更新 C# 文件中重命名的字段
- python - 如何在 QTableWidget 中将拖放与排序结合起来?