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 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';
}
@grantalltodavid
grantalltodavid / functions.php
Created October 8, 2021 07:59
Sliced Invoices PDF Extension: disable email attachment
add_filter( 'sliced_email_attachment', 'sliced_remove_pdf_attachment', 20, 2 );
function sliced_remove_pdf_attachment( $attachment = null, $id ) {
return null;
}
@grantalltodavid
grantalltodavid / functions.php
Created September 30, 2021 18:29
WP Wham Product Open Pricing: change per-product metabox's "enabled" setting default to "yes"
add_filter( 'wpwham_product_open_pricing_metabox_options', 'wpwham_20210930_change_metabox_defaults' );
function wpwham_20210930_change_metabox_defaults( $options ) {
foreach ( $options as &$option ) {
if ( $option['name'] === 'alg_wc_product_open_pricing_enabled' ) {
$option['default'] = 'yes';
break;
}
}
return $options;
}
@grantalltodavid
grantalltodavid / functions.php
Created August 26, 2021 13:30
Sliced Invoices: add extra email recipient depending on type of email
add_filter( 'sliced_get_email_recipient', 'sliced_custom_add_recipient', 10, 3 );
function sliced_custom_add_recipient( $output, $id, $type ) {
if ( $type === 'invoice_available' ) // new invoice email sent to client
$output .= ', second_email_address@example.com';
elseif ( $type === 'quote_available' ) // new quote email sent to client
$output .= ', second_email_address@example.com';
elseif ( $type === 'quote_accepted' ) // quote accept email sent to admin
$output .= ', second_email_address@example.com';
elseif ( $type === 'quote_declined' ) // quote declined email sent to admin
@grantalltodavid
grantalltodavid / functions.php
Created August 26, 2021 12:13
WP Wham SKU Generator: example of creating custom SKU template variables
add_filter( 'wpwham_sku_sku_template_variables', 'wpwham_20210826_add_custom_sku_variables', 10, 7 );
function wpwham_20210826_add_custom_sku_variables( $variables, $product_id, $sku_number, $variation_suffix, $is_preview, $parent_product_id, $_product ) {
$variables['{raw_sku}'] = '';
if ( $_product instanceof WC_Product_Variation ) {
$parent_raw_sku = get_post_meta( $parent_product_id, 'raw_sku', true );
$variables['{raw_sku}'] = $parent_raw_sku;
} else {
$raw_sku = get_post_meta( $parent_product_id, 'raw_sku', true );
@grantalltodavid
grantalltodavid / functions.php
Created April 14, 2021 10:10
WP Wham Checkout Files Upload - don't allow files to be deleted from admin side
add_filter( 'wpwham_checkout_files_upload_allow_admin_delete_files', '__return_false' );
@grantalltodavid
grantalltodavid / functions.php
Last active April 1, 2021 19:22
WP Wham Bulk Regenerate Download Permissions: examples of using functions to trigger regenerations programmatically
/* To trigger a regeneration of all orders: */
$BRDP = Alg_WC_Bulk_Regenerate_Download_Permissions_Core::get_instance();
$BRDP->bulk_regenerate_download_permissions_all_orders();
/* To trigger a regeneration of a single order: */
$order_id = 12345; // your WooCommerce order ID goes here
$BRDP = Alg_WC_Bulk_Regenerate_Download_Permissions_Core::get_instance();
$BRDP->smart_downloadable_product_permissions( $order_id, 'single_item' );
@grantalltodavid
grantalltodavid / gist:1f83770f7b84122860e441275127c19c
Created March 16, 2021 19:35
WP Wham Product Visibility by Country: helper to convert array of countries to serialized data (for CSV import or whatever)
// use online at https://3v4l.org/CfM8n
// use ISO 2-digit country codes
// example: AU = Australia, US = United States, GB = United Kingdom, etc.
// reference: https://www.nationsonline.org/oneworld/country_code_list.htm
// put as many countries as you need, 1 per line:
$countries = array
(
'AU',
@grantalltodavid
grantalltodavid / gist:c5fed6d0e1042c2914e2f0162210b130
Created March 16, 2021 19:34
WP Wham Product Visibility by User Role: helper to convert array of roles to serialized data (for CSV import or whatever)
// use online at https://3v4l.org/brsbU
$roles = array
(
'guest',
'administrator',
'editor',
'author',
'contributor',
'subscriber',