Skip to content

Instantly share code, notes, and snippets.

@SirDarcanos
SirDarcanos / functions.php
Created July 28, 2017 06:00
functions.php
add_action( 'woocommerce_no_products_found', 'show_products_on_no_products_found', 20 );
function show_products_on_no_products_found() {
echo '<h2>' . __( 'You may be interested in...', 'domain' ) . '</h2>';
echo do_shortcode( '[recent_products per_page="4"]' );
}
@SirDarcanos
SirDarcanos / functions.php
Created July 18, 2017 08:30
functions.php
/**
* Checks if the customer is a reseller and
* returns false if they are trying to purchase from a specific category.
*
* @param bool $is_purchasable If the product is purchasable or not.
* @return bool
*/
function limit_purchases_by_role( $is_purchasable, $product ) {
$categories = $product->get_category_ids();
<?php
/**
* Load a custom template for vendor taxonomy
*/
function load_custom_vendor_template( $located, $template_name ) {
if( is_tax( WC_PRODUCT_VENDORS_TAXONOMY ) && 'archive-product.php' == $template_name ) {
return get_stylesheet_directory() . '/woocommerce/taxonomy-shop_vendor.php';
}
return $located;
@SirDarcanos
SirDarcanos / functions.php
Created May 16, 2017 05:51
functions.php
function wc_ninja_remove_password_strength() {
if ( wp_script_is( 'wc-password-strength-meter', 'enqueued' ) ) {
wp_dequeue_script( 'wc-password-strength-meter' );
}
}
add_action( 'wp_print_scripts', 'wc_ninja_remove_password_strength', 100 );
@SirDarcanos
SirDarcanos / functions.php
Created May 16, 2017 05:49
functions.php
add_filter( 'woocommerce_min_password_strength', create_function( '', 'return 2;' ) );
@SirDarcanos
SirDarcanos / functions.php
Last active May 16, 2017 05:30
functions.php
/**
* Removes the attribute from the product title, in the cart.
*
* @return string
*/
function remove_variation_from_product_title( $title, $cart_item, $cart_item_key ) {
$_product = $cart_item['data'];
$product_permalink = apply_filters( 'woocommerce_cart_item_permalink', $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '', $cart_item, $cart_item_key );
if ( $_product->is_type( 'variation' ) ) {
@SirDarcanos
SirDarcanos / functions.php
Created May 16, 2017 05:26
functions.php
add_filter( 'woocommerce_is_attribute_in_product_name', '__return_false' );
/**
* Hides the product's weight and dimension in the single product page.
*/
add_filter( 'wc_product_enable_dimensions_display', '__return_false' );
// Get current user ID
$user_id = get_current_user_id();
// Check if the user is member of the plan 'gold'
if ( wc_memberships_is_user_active_member( $user_id, 'gold' ) ) {
echo 'This is a special message only for Gold members!';
} else {
echo 'I\'m sorry, you are not a gold member. There\'s nothing here for you!';
}
remove_action( 'storefront_footer', 'storefront_handheld_footer_bar', 999 );