Skip to content

Instantly share code, notes, and snippets.

View bobwol's full-sized avatar
💭
coding as usual

bobwol

💭
coding as usual
View GitHub Profile
@bobwol
bobwol / wc-display-category-image-archive.php
Created October 3, 2020 19:09 — forked from woogists/wc-display-category-image-archive.php
[Theming] Display category image on category archive
/**
* Display category image on category archive
*/
add_action( 'woocommerce_archive_description', 'woocommerce_category_image', 2 );
function woocommerce_category_image() {
if ( is_product_category() ){
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
@bobwol
bobwol / wc-products-displayed-per-page.php
Created October 3, 2020 19:09 — forked from woogists/wc-products-displayed-per-page.php
[Theming Snippets] Change number of products displayed per page
/**
* Change number of products that are displayed per page (shop page)
*/
add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 );
function new_loop_shop_per_page( $cols ) {
// $cols contains the current number of products per page based on the value stored on Options -> Reading
// Return the number of products you wanna show per page.
$cols = 9;
return $cols;
@bobwol
bobwol / wc-add-currency-symbol.php
Created October 3, 2020 19:09 — forked from woogists/wc-add-currency-symbol.php
Add a custom currency / symbol
/**
* Custom currency and currency symbol
*/
add_filter( 'woocommerce_currencies', 'add_my_currency' );
function add_my_currency( $currencies ) {
$currencies['ABC'] = __( 'Currency name', 'woocommerce' );
return $currencies;
}
/**
* Change a currency symbol
*/
add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);
function change_existing_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case 'AUD': $currency_symbol = 'AUD$'; break;
}
return $currency_symbol;
@bobwol
bobwol / wc-new-account-notify-admin.php
Created October 3, 2020 19:09 — forked from woogists/wc-new-account-notify-admin.php
[General Snippets] Notify admin when a new customer account is created
/**
* Notify admin when a new customer account is created
*/
add_action( 'woocommerce_created_customer', 'woocommerce_created_customer_admin_notification' );
function woocommerce_created_customer_admin_notification( $customer_id ) {
wp_send_new_user_notifications( $customer_id, 'admin' );
}
@bobwol
bobwol / wc-change-email-subject.php
Created October 3, 2020 19:09 — forked from woogists/wc-change-email-subject.php
Change email subject lines
/*
* goes in theme functions.php or a custom plugin
*
* Subject filters:
* woocommerce_email_subject_new_order
* woocommerce_email_subject_customer_processing_order
* woocommerce_email_subject_customer_completed_order
* woocommerce_email_subject_customer_invoice
* woocommerce_email_subject_customer_note
* woocommerce_email_subject_low_stock
@bobwol
bobwol / wc-send-coupons-by-email.php
Created October 3, 2020 19:09 — forked from woogists/wc-send-coupons-by-email.php
Send coupons used in an order by email
/**
* Send an email each time an order with coupon(s) is completed
* The email contains coupon(s) used during checkout process
*
*/
function woo_email_order_coupons( $order_id ) {
$order = new WC_Order( $order_id );
if( $order->get_used_coupons() ) {
@bobwol
bobwol / wc-add-custom-field.php
Created October 3, 2020 19:09 — forked from woogists/wc-add-custom-field.php
Add a custom field (in an order) to the emails
/**
* Add a custom field (in an order) to the emails
*/
add_filter( 'woocommerce_email_order_meta_fields', 'custom_woocommerce_email_order_meta_fields', 10, 3 );
function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
$fields['meta_key'] = array(
'label' => __( 'Label' ),
'value' => get_post_meta( $order->id, 'meta_key', true ),
);
@bobwol
bobwol / wc-unhook-remove-emails.php
Created October 3, 2020 19:09 — forked from woogists/wc-unhook-remove-emails.php
[General Snippets] Unhook and remove WooCommerce default emails.
/**
* Unhook and remove WooCommerce default emails.
*/
add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );
function unhook_those_pesky_emails( $email_class ) {
/**
* Hooks for sending emails during store events
**/
@bobwol
bobwol / wc-hide-all-shipping-if-free-shipping-is-available.php
Created October 3, 2020 19:08 — forked from woogists/wc-hide-all-shipping-if-free-shipping-is-available.php
[General Snippets][Hide other shipping methods when “Free Shipping” is available] Hides all other shipping methods but free_shipping if it’s available. Compatible with Shipping zones.
/**
* Hide shipping rates when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {