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 May 31, 2025 23:25
WP Wham Checkout Files Upload -- restore normal file type validation
add_filter( 'wpwham_checkout_files_upload_validate_file_type', 'wpw20250531_restore_normal_file_type_validation', 10, 3 );
function wpw20250531_restore_normal_file_type_validation( $result, $file_uploader, $file ) {
$result = true;
$files_accepted = get_option( 'alg_checkout_files_upload_file_accept_' . $file_uploader, '.jpg,.jpeg,.png' );
if ( $files_accepted > '' ) {
$files_accepted = array_map( 'trim', explode( ',', strtolower( $files_accepted ) ) );
if ( is_array( $files_accepted ) && ! empty( $files_accepted ) ) {
$file_type = strtolower( '.' . pathinfo( $file['name'], PATHINFO_EXTENSION ) );
if ( ! in_array( $file_type, $files_accepted ) ) {
$result = array(
@grantalltodavid
grantalltodavid / functions.php
Created February 20, 2025 11:02
Sliced Invoices: PayPal Gateway change NOSHIPPING parameter from 1 to 0
<?php
add_action( 'setted_transient', 'si20250220_change_paypal_params', 10, 3 );
function si20250220_change_paypal_params( $transient, $value, $expiration ) {
if ( strpos( $transient, 'sliced_paypal_' ) === 0 && strpos( $value, 'NOSHIPPING=1' ) !== false ) {
$value = str_replace( 'NOSHIPPING=1', 'NOSHIPPING=0', $value );
set_transient( $transient, $value, 60*60*24 );
}
}
@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;
}