Forked from northernbeacheswebsites/Add new item type and replace column title
Last active
November 9, 2015 17:47
-
-
Save dancameron/1f9de259f8dfb756a27f to your computer and use it in GitHub Desktop.
Add new item type and replace column title
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 // 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( '% <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