Last active
March 24, 2021 17:17
-
-
Save Mte90/b3690ed5ab4e6e918f73d268d5d2e965 to your computer and use it in GitHub Desktop.
Esempio plugin per WooCommerce che aggiunge una colonna
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: WooCommerce Colonna IVA | |
* Description: Aggiunge una colonna nei prodotti WooCommerce | |
* Version: 1.0.0 | |
* Author: LUGRieti | |
* Author URI: | |
* Requires at least: 4.9 | |
* Tested up to: 4.9 | |
* | |
*/ | |
// https://github.com/WPBP/CPT_Columns | |
include('CPT_Columns.php'); | |
add_action( 'plugins_loaded', 'aggiungi_colonna', 0 ); | |
function aggiungi_colonna() { | |
$post_columns = new CPT_columns( 'product' ); | |
$post_columns->add_column( 'iva', array( | |
'label' => __( 'IVA' ), | |
'type' => 'custom_value', | |
'sortable' => true, | |
'callback' => 'calcola_iva', | |
'def' => 'Not defined', // Default value in case post meta not found | |
'order' => '-1' // This is the last column | |
) | |
); | |
} | |
function calcola_iva() { | |
$product = wc_get_product( get_the_ID() ); | |
$print = '€ ' . $product->get_price() * ( 22/100 ); | |
return $print; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment