Skip to content

Instantly share code, notes, and snippets.

@ofernandolopes
ofernandolopes / functions.php
Last active August 29, 2015 14:21 — forked from ChromeOrange/functions.php
WooCommerce - Sold Out Shortcode
<?php
add_shortcode('soldoutproducts', 'custom_woocommerce_soldout_products');
/**
* Recent Products shortcode with custom styles
**/
function custom_woocommerce_soldout_products( $atts ) {
global $woocommerce_loop;
@ofernandolopes
ofernandolopes / functions.php
Last active August 29, 2015 14:21 — forked from ChromeOrange/functions.php
WooCommerce - Replace all add to cart button text
<?php
// Single Product
add_filter( 'single_add_to_cart_text', 'custom_single_add_to_cart_text' );
function custom_single_add_to_cart_text() {
return 'Add to cart'; // Change this to change the text on the Single Product Add to cart button.
}
// Variable Product
add_filter( 'variable_add_to_cart_text', 'custom_variable_add_to_cart_text' );
@ofernandolopes
ofernandolopes / remove-woocommerce-submenu-items
Last active August 29, 2015 14:25 — forked from WillBrubaker/remove-woocommerce-submenu-items
WC - Removes submenu items from WooCommerce menu for 'Shop Managers'
<?php
/*
Don't copy the opening php tag
*/
/*
Removes submenu items from WooCommerce menu for 'Shop Managers'
available submenu slugs are:
wc-addons - the Add-ons submenu
wc-status - the System Status submenu
@ofernandolopes
ofernandolopes / functions.php
Last active August 29, 2015 14:25 — forked from woogist/functions.php
WordPress - Remove Jetpack menu
function jeherve_delete_jetpack_menu() {
if ( ! current_user_can( 'manage_options' ) ) {
remove_menu_page( 'jetpack' );
}
}
add_action ( 'admin_menu', 'jeherve_delete_jetpack_menu', 999 );
@ofernandolopes
ofernandolopes / functions.php
Last active August 29, 2015 14:25 — forked from woogist/functions.php
WooCommerce - Add custom fields to order emails
/**
* Add the field to order emails
**/
add_filter('woocommerce_email_order_meta_keys', 'my_custom_checkout_field_order_meta_keys');
function my_custom_checkout_field_order_meta_keys( $keys ) {
$keys[‘My Field 1′] = ‘_my_field_1;
$keys[‘My Field 2′] = ‘_my_field_2′;
return $keys;
}
<?php
// add custom field to invoice email
add_action( 'woocommerce_email_after_order_table', 'woocommerce_custom_invoice_fields' );
function woocommerce_custom_invoice_fields( $order ) {
?>
<p><strong><?php _e('Free Book:', 'woocommerce'); ?></strong> <?php echo get_post_meta( $order->id, 'Free Book', true ); ?></p>
<p><strong><?php _e('Free DVD:', 'woocommerce'); ?></strong> <?php echo get_post_meta( $order->id, 'Free DVD', true ); ?></p>
<p><strong><?php _e('Gift:', 'woocommerce'); ?></strong> <?php echo get_post_meta( $order->id, 'Gift Order', true ); ?></p>
<p><strong><?php _e('Gift Message:', 'woocommerce'); ?></strong> <?php echo get_post_meta( $order->id, 'Special Gift Message', true ); ?></p>
<?php
@ofernandolopes
ofernandolopes / gist:4883a8cb5cd4206909da
Last active August 29, 2015 14:25 — forked from Katamo/gist:10243188
WooCommerce - Hide Checkout Fields For Virtual Products
<?php
add_filter( 'woocommerce_checkout_fields' , 'woo_remove_billing_checkout_fields' );
/**
* Remove unwanted checkout fields
*
* @return $fields array
*/
function woo_remove_billing_checkout_fields( $fields ) {
@ofernandolopes
ofernandolopes / functions.php
Last active August 29, 2015 14:25 — forked from corsonr/gist:093cf4c57262b271fdef
WooCommerce - Add recipient email on completed order
/**
* WooCommerce Extra Feature
* --------------------------
* Add another email recipient when an order is completed
*/
function woo_extra_email_recipient($recipient, $object) {
$recipient = $recipient . ', [email protected]';
return $recipient;
}
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'woo_extra_email_recipient', 10, 2);
@ofernandolopes
ofernandolopes / functions.php
Created July 20, 2015 02:56 — forked from corsonr/gist:c2781c9e0cc086c5047f
WooCommerce - Add customer username to edit/view order admin page
<?php
// Add WooCommerce customer username to edit/view order admin page
add_action( 'woocommerce_admin_order_data_after_billing_address', 'woo_display_order_username', 10, 1 );
function woo_display_order_username( $order ){
global $post;
$customer_user = get_post_meta( $post->ID, '_customer_user', true );
echo '<p><strong style="display: block;">'.__('Customer Username').':</strong> <a href="user-edit.php?user_id=' . $customer_user . '">' . get_user_meta( $customer_user, 'nickname', true ) . '</a></p>';
@ofernandolopes
ofernandolopes / functions.php
Last active August 29, 2015 14:25
WordPress - Remove items from the admin bar to not administrators
<?php
// Remove items from the admin bar to not administrators
add_action( 'wp_before_admin_bar_render', 'hide_before_admin_bar_render' );
function hide_before_admin_bar_render() {
if (!current_user_can('administrator')) {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('wp-logo'); //WordPress Logo
$wp_admin_bar->remove_menu('site-name'); //Site Name
$wp_admin_bar->remove_menu('view-site'); //View Site
$wp_admin_bar->remove_menu('comments'); //Comments