Skip to content

Instantly share code, notes, and snippets.

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 dancameron/1f9de259f8dfb756a27f to your computer and use it in GitHub Desktop.
Save dancameron/1f9de259f8dfb756a27f to your computer and use it in GitHub Desktop.
Add new item type and replace column title
<?php // don't include this in your functions.php
// add new item type (working)
function add_sizeproduct_line_item_type( $types = array() ) {
$types = array_merge( $types, array( 'sizeproduct' => __( 'Size Product' ) ) );
return $types;
}
add_filter( 'si_line_item_types', 'add_sizeproduct_line_item_type' );
// replace new item types column 'rate' with 'Per SQM' (not working)
function add_persqm( $columns = array(), $type = 'sizeproduct' ) {
if ( 'sizeproduct' !== $type ) {
return $columns;
}
$columns = array(
'_id' => array(
'type' => 'hidden',
'value' => mt_rand(),
'weight' => 0,
),
'desc' => array(
'label' => __( 'Size', 'sprout-invoices' ),
'type' => 'textarea',
'calc' => false,
'hide_if_parent' => false,
'weight' => 1,
),
'sku' => array(
'type' => 'hidden',
'placeholder' => '',
'calc' => false,
'numeric' => false,
'weight' => 3,
),
'rate' => array(
'label' => __( 'per', 'sprout-invoices' ),
'type' => 'small-input',
'placeholder' => '120',
'calc' => false,
'hide_if_parent' => true,
'weight' => 5,
),
'qty' => array(
'label' => __( 'sqm', 'sprout-invoices' ),
'type' => 'small-input',
'placeholder' => 1,
'calc' => true,
'hide_if_parent' => true,
'weight' => 10,
),
'tax' => array(
'label' => sprintf( '&#37; <span class="helptip" title="%s"></span>', __( 'A percentage adjustment per line item, i.e. tax or discount', 'sprout-invoices' ) ),
'type' => 'small-input',
'placeholder' => 0,
'calc' => false,
'hide_if_parent' => true,
'weight' => 15,
),
'total' => array(
'label' => __( 'Amount', 'sprout-invoices' ),
'type' => 'total',
'placeholder' => sa_get_formatted_money( 0 ),
'calc' => true,
'hide_if_parent' => false,
'weight' => 50,
),
);
return $columns;
}
add_filter( 'si_line_item_columns', 'add_persqm', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment