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
Created July 7, 2022 09:34
WP Wham Checkout Files Upload -- getting uploaded file info programmatically
// which file uploader... i.e. "File Uploader #1" in the settings:
$file_uploader_id = 1;
// with the WooCommerce $order_id, we can get all the files for $file_uploader_id here:
$order_files = get_post_meta( $order_id, '_alg_checkout_files_upload_' . $file_uploader_id, true );
// $order_files will be an array. we can grab a specific file by key here:
$order_file = $order_files[ $file_key ];
// once we've picked a single $order_file, we can access it's 'tmp_name' (name it's stored under on the server):
@grantalltodavid
grantalltodavid / functions.php
Created July 7, 2022 08:47
Sliced Invoices Deposit Invoices: don't show "this is....(balance/deposit" message at top of invoices
add_filter( 'sliced_deposit_invoice_message', '__return_false' );
@grantalltodavid
grantalltodavid / functions.php
Last active June 27, 2022 17:11
Sliced Invoices: redirect to newly created Invoice immediately upon Quote acceptance
add_action( 'sliced_client_accepted_quote', 'si20220627_custom_quote_acceptance_action', 20, 2 );
function si20220627_custom_quote_acceptance_action( $id, $new_post_id ) {
$invoice_id = $new_post_id ? $new_post_id : $id;
if ( $invoice_id ) {
if ( wp_redirect( get_permalink( $invoice_id ) ) ) {
exit;
}
}
}
@grantalltodavid
grantalltodavid / functions.php
Created May 25, 2022 05:32
Sliced Invoices: example of how to add "non-cloneable post metas"
add_filter( 'sliced_invoices_non_cloneable_post_metas', 'si20220524_add_non_cloneable_post_metas' );
function si20220524_add_non_cloneable_post_metas( $non_cloneable_post_metas ) {
$non_cloneable_post_metas[] = '_sliced_invoice_created';
$non_cloneable_post_metas[] = '_sliced_invoice_due';
return $non_cloneable_post_metas;
}
@grantalltodavid
grantalltodavid / functions.php
Created May 24, 2022 23:52
Sliced Invoices: use same terms and conditions from Quote on the Invoice when converting a Quote to Invoice, or creating a new Invoice from an existing Quote
function si20220524_preserve_quote_terms_on_invoice_before( $id ) {
global $si20220524_quote_terms;
$si20220524_quote_terms = get_post_meta( $id, '_sliced_quote_terms', true );
}
function si20220524_preserve_quote_terms_on_invoice_after( $id, $new_post_id = null ) {
global $si20220524_quote_terms;
if ( $si20220524_quote_terms ) {
if ( $new_post_id ) {
// created new invoice from quote
update_post_meta( $new_post_id, '_sliced_invoice_terms', $si20220524_quote_terms );
@grantalltodavid
grantalltodavid / function.php
Created March 17, 2022 07:45
Sliced Invoices: remove quantity field from frontend views
add_filter( 'sliced_invoice_line_items_output', 'si20220317_sliced_invoice_line_items_output_custom' );
function si20220317_sliced_invoice_line_items_output_custom( $output ) {
if ( preg_match_all('#<t[hd] class="qty">(.*?)</t[hd]>#', $output, $matches) ) {
$patterns = array();
$replacements = array();
foreach ( $matches[1] as $match ) {
$patterns[] = '#<t[hd] class="qty">'.$match.'</t[hd]>#';
$replacements[] = '';
}
$output = preg_replace($patterns, $replacements, $output);
@grantalltodavid
grantalltodavid / functions.php
Created March 11, 2022 05:45
Sliced Invoices: allow shortcodes in invoice terms field
add_filter( 'sliced_get_invoice_terms', 'si20220310_do_shortcodes_in_terms' );
function si20220310_do_shortcodes_in_terms( $content ) {
return do_shortcode( $content );
}
@grantalltodavid
grantalltodavid / functions.php
Created February 22, 2022 14:13
Sliced Invoices: disable comments for all quotes
add_filter( 'comments_open', 'si20220222_disable_comments_for_all_quotes', 10, 2 );
function si20220222_disable_comments_for_all_quotes( $open, $post_id = null ) {
$_post = get_post( $post_id );
if ( $_post && ( $_post->post_type === 'sliced_quote' ) ) {
$open = false;
}
return $open;
}
@grantalltodavid
grantalltodavid / functions.php
Created October 21, 2021 09:31
Sliced Invoices: pre-fill description field for new quotes
add_action( 'sliced_after_description', 'si20211021_pre_fill_quote_description' );
function si20211021_pre_fill_quote_description( $cmb ) {
global $pagenow;
// only pre-fills new quotes
if ( $pagenow === 'post-new.php' && isset( $_GET['post_type'] ) && $_GET['post_type'] === 'sliced_quote' ) {
$field = $cmb->get_field( '_sliced_description' );
if ( $field ) {
$field->args['default'] = 'Text to pre-fill goes here';
}
}
@grantalltodavid
grantalltodavid / functions.php
Created October 13, 2021 09:56
Sliced Invoices Authorize.net Gateway: change "pay with Authorize.net" button text
add_filter( 'sliced_get_gateway_authorize_net_label', 'sliced_customize_authorize_net_gateway_label' );
function sliced_customize_authorize_net_gateway_label( $label ) {
return 'Pay by Credit Card';
}