Skip to content

Instantly share code, notes, and snippets.

@Mte90
Last active March 24, 2021 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mte90/b3690ed5ab4e6e918f73d268d5d2e965 to your computer and use it in GitHub Desktop.
Save Mte90/b3690ed5ab4e6e918f73d268d5d2e965 to your computer and use it in GitHub Desktop.
Esempio plugin per WooCommerce che aggiunge una colonna
<?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