Wordpress 在购物车中添加费用的自定义插件
我的代码在函数文件中运行良好 如何创建一个自定义插件来处理此代码Wordpress 在购物车中添加费用的自定义插件,wordpress,woocommerce,Wordpress,Woocommerce,我的代码在函数文件中运行良好 如何创建一个自定义插件来处理此代码 add_action( 'woocommerce_cart_calculate_fees' , 'wpdesk_checkout_fee' ); add_action( 'woocommerce_after_cart_item_quantity_update', 'wpdesk_checkout_fee' ); function wpdesk_checkout_fee() { global $woocommerce;
add_action( 'woocommerce_cart_calculate_fees' , 'wpdesk_checkout_fee' );
add_action( 'woocommerce_after_cart_item_quantity_update', 'wpdesk_checkout_fee' );
function wpdesk_checkout_fee() {
global $woocommerce;
$items = $woocommerce->cart->get_cart();
$list = array();
foreach($items as $item=> $values ){
array_push($list, $values['product_id']);
}
foreach($list as $productid){
if($productid == 2361){
$fee = (int)-5000;
WC()->cart->add_fee( "fee: ", $fee, false, '' );
}
}
}
我需要在自定义插件中使用正确的代码段您可以轻松地将工作代码转换为插件 步骤1:为您的插件名称创建一个文件夹(例如:自定义插件) 步骤2:创建一个与插件同名的新文件 步骤3:将代码添加到此文件 第4步:确保已添加插件文件的标题 最后,您的插件代码如下所示
<?php
/*
Plugin Name: Customize Other Plugin Output
Plugin URI: http://brianhogg.com/
Description: Changes the output from The Other Plugin using a bit of code
Author: Brian Hogg
Version: 1.0.0
Author URI: http://brianhogg.com
add_action( 'woocommerce_cart_calculate_fees' , 'wpdesk_checkout_fee' );
add_action( 'woocommerce_after_cart_item_quantity_update', 'wpdesk_checkout_fee' );
function wpdesk_checkout_fee() {
global $woocommerce;
$items = $woocommerce->cart->get_cart();
$list = array();
foreach($items as $item=> $values ){
array_push($list, $values['product_id']);
}
foreach($list as $productid){
if($productid == 2361){
$fee = (int)-5000;
WC()->cart->add_fee( "fee: ", $fee, false, '' );
}
}
}
创建插件名称的文件夹(不要使用空格)
创建与插件同名的文件(不要使用空格)
使用以下插件详细信息向插件文件添加代码