my code working fine in functions file
how i can create a custom plugin for working this code ?
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, '' );
}
}
}
i need correct snippets for use in custom plugin
2
Answers
You can easily convert your working code into a plugin.
Step1: Create a folder for your plugin name (Example: custom-plugin)
Step2: Create a new file with the same name as your plugin
Step3: Add your code to this file
Step4: Make sure you have added the headers for the plugin file.
Finally, your plugin code will be like this.
Refer to this link for more details https://brianhogg.com/functional-wordpress-plugins/