Skip to content

Instantly share code, notes, and snippets.

View grantalltodavid's full-sized avatar

David Grant grantalltodavid

View GitHub Profile
@grantalltodavid
grantalltodavid / functions.php
Last active September 19, 2017 11:24
Sliced Invoices: Show quantity field as whole numbers only, no decimals
add_filter( 'sliced_invoice_line_items_output', 'sliced_invoice_line_items_output_custom' );
function sliced_invoice_line_items_output_custom( $output ) {
if ( preg_match_all('#<td class="qty">(.*?)</td>#', $output, $matches) ) {
$patterns = array();
$replacements = array();
foreach ( $matches[1] as $match ) {
$patterns[] = '#<td class="qty">'.$match.'</td>#';
$replacements[] = '<td class="qty">'.intval($match).'</td>';
}
$output = preg_replace($patterns, $replacements, $output);
@grantalltodavid
grantalltodavid / functions.php
Last active September 19, 2017 11:24
Sliced Invoices: in wp-admin area, show quotes and invoices only to admin users
function sliced_custom_params_admins_only( $opts ) {
$opts['map_meta_cap'] = false;
$opts['capabilities'] = array(
'edit_post' => 'manage_options',
'read_post' => 'manage_options',
'delete_post' => 'manage_options',
'edit_posts' => 'manage_options',
'edit_others_posts' => 'manage_options',
'delete_posts' => 'manage_options',
'publish_posts' => 'manage_options',
@grantalltodavid
grantalltodavid / functions.php
Created October 3, 2017 06:09
Sliced Invoices Stripe Gateway: move Apple Pay button right to the top of invoice page
add_action( 'sliced_invoice_top_bar_left', 'sliced_custom_apple_pay_button', 999 );
add_action( 'sliced_invoice_head', 'sliced_custom_apple_pay_button_scripts' );
function sliced_custom_apple_pay_button() {
$payments = get_option( 'sliced_payments' );
if ( ! $payments['stripe_apple_pay'] ) {
return;
}
if( has_term( array( 'paid', 'cancelled' ), 'invoice_status' ) ) {
return;
}
@grantalltodavid
grantalltodavid / functions.php
Created October 13, 2017 10:21
Sliced Invoices: remove rate field from showing
add_filter( 'sliced_invoice_line_items_output', 'sliced_invoice_line_items_output_20171013' );
function sliced_invoice_line_items_output_20171013( $output ) {
// remove rate field from showing
$regex = array(
'#<th class="rate">(.*?)</th>#',
'#<td class="rate">(.*?)</td>#'
);
$output = preg_replace( $regex, '', $output );
return $output;
}
@grantalltodavid
grantalltodavid / functions.php
Created October 27, 2017 00:51
Sliced Invoices: hide "adjust (%)" field from admin quote/invoice pages
add_action( 'sliced_after_line_items', 'sliced_admin_hide_the_adjust_field', 10, 2 );
function sliced_admin_hide_the_adjust_field( $line_items_group_id, $line_items ) {
// for historical reasons the "adjust(%)" field is called "tax" internally,
// although it is no longer used for this purpose.
return $line_items->remove_field( 'tax', $line_items_group_id );
}
@grantalltodavid
grantalltodavid / functions.php
Last active August 10, 2018 19:26
Sliced Invoices: add additional options to Payment Reminder Days settings
add_filter( 'sliced_email_option_fields', 'sliced_email_option_fields_add_reminder_days' );
function sliced_email_option_fields_add_reminder_days( $array ) {
if ( ! isset( $array['fields'] ) ) { return $array; }
foreach ( $array['fields'] as $i => $field ) {
if ( isset( $field['id'] ) && $field['id'] === 'payment_reminder_days' ) {
// add to beginning of options list:
$array['fields'][$i]['options'] = array_replace( array(
'-60' => '60 days before Due Date',
'-30' => '30 days before Due Date', //etc...
), $array['fields'][$i]['options'] );
@grantalltodavid
grantalltodavid / functions.php
Created October 31, 2017 03:59
Sliced Invoices PDF Extension: disable watermark
add_action( 'sliced_pdf_init', 'sliced_pdf_html_custom_params', 10, 1 );
function sliced_pdf_html_custom_params( $pdf ) {
$pdf->showWatermarkText = false;
}
@grantalltodavid
grantalltodavid / functions.php
Created November 7, 2017 04:11
Sliced Invoices: automatically send invoice to client upon invoice creation
add_action( 'new_to_publish', 'sliced_auto_send_invoice', 10, 1 );
add_action( 'draft_to_publish', 'sliced_auto_send_invoice', 10, 1 );
add_action( 'pending_to_publish', 'sliced_auto_send_invoice', 10, 1 );
add_action( 'sliced_auto_send_invoice_deferred', 'sliced_auto_send_invoice_deferred_function', 10, 1 );
function sliced_auto_send_invoice( $post ) {
if ( $post->post_type === 'sliced_invoice' ) {
// run in background
wp_schedule_single_event( time(), 'sliced_auto_send_invoice_deferred', array( $post ) );
}
}
@grantalltodavid
grantalltodavid / functions.php
Last active June 22, 2020 20:37
Sliced Invoices: automatically send quote to client upon invoice creation
add_action( 'new_to_publish', 'sliced_auto_send_quote', 10, 1 );
add_action( 'draft_to_publish', 'sliced_auto_send_quote', 10, 1 );
add_action( 'pending_to_publish', 'sliced_auto_send_quote', 10, 1 );
add_action( 'sliced_auto_send_quote_deferred', 'sliced_auto_send_quote_deferred_function', 10, 1 );
function sliced_auto_send_quote( $post ) {
if ( $post->post_type === 'sliced_quote' ) {
// run in background
wp_schedule_single_event( time(), 'sliced_auto_send_quote_deferred', array( $post ) );
}
}
@grantalltodavid
grantalltodavid / functions.php
Created November 13, 2017 07:01
Sliced Invoices Stripe Gateway: show Stripe logo at bottom of payment form
add_filter( 'sliced_stripe_gateway_image', 'sliced_stripe_gateway_image_custom' );
function sliced_stripe_gateway_image_custom() {
return '<img src="' . plugins_url( '/sliced-invoices-stripe/accept-stripe.png' ) . '" alt="" />';
}