Skip to content

Instantly share code, notes, and snippets.

@LaurenaRehbein
Created May 14, 2018 16:56
Show Gist options
  • Save LaurenaRehbein/f5b6ac06e6a752161d8f7abf9e4ca453 to your computer and use it in GitHub Desktop.
Save LaurenaRehbein/f5b6ac06e6a752161d8f7abf9e4ca453 to your computer and use it in GitHub Desktop.
Functions I used in the donations setup referenced here: https://laurena.blog/collecting-donations-with-woocommerce/
/**
* Function to remove the variable subscription price string
* Add this to your child theme's functions.php file.
*/
function wc_remove_var_subscriptions_price() {
return '';
}
add_filter( 'woocommerce_variable_subscription_price_html', 'wc_remove_var_subscriptions_price' );
function wc_subscriptions_custom_price_string( $pricestring ) {
$newprice = str_replace( 'for 1 day', 'once', $pricestring );
return $newprice;
}
add_filter( 'woocommerce_subscriptions_product_price_string', 'wc_subscriptions_custom_price_string' );
function lr_subscriptions_custom_price_string( $pricestring ) {
$newprice = str_replace( 'every day once', 'once', $pricestring );
return $newprice;
}
add_filter( 'woocommerce_subscriptions_product_price_string', 'lr_subscriptions_custom_price_string' );
/**
* // Custom redirect for users after clicking 'return to shop'
**/
add_filter('woocommerce_return_to_shop_redirect', 'lr_wc_return_to_shop_redirect');
function lr_wc_return_to_shop_redirect( $redirect ) {
$redirect = '/products/donation/';
return $redirect;
}
add_filter( 'pdf_template_order_total', 'lr_get_pdf_order_total', 10, 2);
function lr_get_pdf_order_total( $output, $order_id ){
global $woocommerce;
$woocommerce_pdf_invoice_options = get_option( 'woocommerce_pdf_invoice_settings' );
if (!$order_id) return;
$order = new WC_Order( $order_id );
// Check WC version - changes for WC 3.0.0
$pre_wc_30 = version_compare( WC_VERSION, '3.0', '<' );
$order_total = $pre_wc_30 ? woocommerce_price( $order->order_total ) : wc_price( $order->get_total() );
$output = __('', 'woocommerce-pdf-invoice') . $order_total;
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment