Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Optimize WooCommerce Scripts
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*/
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
//remove generator meta tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
<?php
// Copies woocommerce orders and users over from source to target.
// I use this on my local machine - loading both db's up there side by side
// could easily adjust the connect strings to connect elsewhere if needed.
// will change order ids
// My use case for this is when I've got a staging/test version of a site with new posts/products/pages etc, that needs
// to go live without the loss of any orders placed on the site site since we copied it to the staging site.
<?php
/*
Template Name: Print Processing Orders :)
*/
if (!is_user_logged_in() || !current_user_can('manage_options')) wp_die('This page is private.');
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?php
// Add Now: R12, Was: R15, Save 20% price for items on sale
add_action( 'woocommerce_sale_price_html', 'wc_custom_sale_price', 10, 2 );
function wc_custom_sale_price( $price, $product ) {
$percentage = round( ( ( $product->regular_price - $product->get_price() ) / $product->regular_price ) * 100 );
return sprintf( __( 'Now: %s, Was: %s, Save %s', 'woocommerce' ), woocommerce_price( $product->get_price() ), woocommerce_price( $product->regular_price ), $percentage . '%' );
}
?>
@ddbs
ddbs / functions.php
Created March 22, 2014 23:52 — forked from kloon/functions.php
WooCommerce Previous & Next product links
<?php
// Add previous and next links to products under the product details
add_action( 'woocommerce_single_product_summary', 'wc_next_prev_products_links', 60 );
function wc_next_prev_products_links() {
previous_post_link( '%link', '< Previous' );
echo ' | ';
next_post_link( '%link', 'Next >' );
}
?>
@ddbs
ddbs / functions.php
Created March 22, 2014 23:52 — forked from kloon/functions.php
WooCommerce CC all emails
<?php
add_filter('woocommerce_email_headers', 'woo_cc_emails' );
function woo_cc_emails() {
return 'Bcc: youremail@yourdomain.com' . "\r\n";
}
?>
@ddbs
ddbs / functions.php
Created March 22, 2014 23:52 — forked from kloon/functions.php
WooCommerce Mark Virtual Product Orders Completed
<?php
add_filter( 'woocommerce_payment_complete_order_status', 'virtual_order_payment_complete_order_status', 10, 2 );
function virtual_order_payment_complete_order_status( $order_status, $order_id ) {
$order = new WC_Order( $order_id );
if ( $order_status == 'processing' &&
( $order->status == 'on-hold' || $order->status == 'pending' || $order->status == 'failed' ) ) {
$virtual_order = true;
@ddbs
ddbs / functions.php
Created March 22, 2014 23:53 — forked from kloon/functions.php
WooCommerce add "Save x%" next to sale prices
<?php
// Add save percent next to sale item prices.
add_filter( 'woocommerce_sale_price_html', 'woocommerce_custom_sales_price', 10, 2 );
function woocommerce_custom_sales_price( $price, $product ) {
$percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );
return $price . sprintf( __(' Save %s', 'woocommerce' ), $percentage . '%' );
}
?>
@ddbs
ddbs / gist:9716257
Created March 22, 2014 23:53 — forked from kloon/gist:4162957
WooCommerce remove from: price
// Change from text on price
function custom_from_price_html( $price, $product ) {
if ( strpos( $price, 'From: ' ) <> false )
return str_replace( 'From: ', '', $price ) . __( ' and up', 'woocommerce');
else return $price;
}
add_filter( 'woocommerce_get_price_html', 'custom_from_price_html', 10, 2 );
@ddbs
ddbs / gist:9716258
Created March 22, 2014 23:53 — forked from kloon/gist:4015723
WooCommerce Change empty price text
// Change empty price
function custom_empty_price( $price, $product ) {
return __( 'Call or Email for price', 'WooCommerce' ) ;
}
add_filter( 'woocommerce_variable_empty_price_html', 'custom_empty_price', 10, 2 );
add_filter( 'woocommerce_empty_price_html', 'custom_empty_price', 10, 2 );