add_filter('woocommerce_placeholder_img_src', 'custom_woocommerce_placeholder_img_src');
function custom_woocommerce_placeholder_img_src($src) {
$upload_dir = wp_upload_dir();
$uploads = untrailingslashit($upload_dir['baseurl']);
$src = $uploads . '/2012/07/placeholder.png';
return $src;
}
add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 );
function hide_shipping_when_free_is_available( $rates, $package ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
if ( 'free_shipping' === $rate->method_id ) {
$free[ $rate_id ] = $rate;
break;
}
}
return !empty( $free ) ? $free : $rates;
}
add_filter ( 'woocommerce_account_menu_items', 'misha_custom_my_account_menu_items' );
function misha_custom_my_account_menu_items( $items ) {
$items = array(
'dashboard' => __( 'Dashboard', 'woocommerce' ),
'orders' => __( 'Orders', 'woocommerce' ),
// add more items or remove by unset()
);
return $items;
}
add_action('woocommerce_registration_redirect', 'auto_login_new_user');
function auto_login_new_user($redirect_url) {
$auto_login = true; // change to false to disable auto login
if ($auto_login) {
$customer_login = wc_get_customer_login_from_session();
if ($customer_login) {
wp_set_current_user($customer_login);
wp_set_auth_cookie($customer_login);
}
}
return $redirect_url;
}
add_filter('woocommerce_checkout_fields', 'remove_billing_on_virtual');
function remove_billing_on_virtual($fields) {
$only_virtual = true;
foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
if (!($cart_item['data']->is_virtual())) $only_virtual = false;
}
if ($only_virtual) {
unset($fields['billing']);
}
return $fields;
}
add_filter('woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text');
function woo_custom_cart_button_text() {
return __('My Custom Text', 'woocommerce');
}
add_filter('woocommerce_add_to_cart_redirect', 'redirect_to_checkout');
function redirect_to_checkout() {
return wc_get_checkout_url();
}
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 12;' ), 20 );
add_filter('loop_shop_columns', 'loop_columns');
if (!function_exists('loop_columns')) {
function loop_columns() {
return 3; // 3 products per row
}
}