Skip to content

Instantly share code, notes, and snippets.

View fschmittlein's full-sized avatar

Frank Schmittlein fschmittlein

View GitHub Profile
@manuelhudec
manuelhudec / woocommerce-disable-downloadable-virtual-products.php
Created June 1, 2021 19:00
WooCommerce - disable downloadable & virtual products
function my_remove_product_type_options( $options ) {
// uncomment this if you want to remove virtual too.
if ( isset( $options['virtual'] ) ) {
unset( $options['virtual'] );
}
if ( isset( $options['downloadable'] ) ) {
unset( $options['downloadable'] );
}
return $options;
}
@manuelhudec
manuelhudec / woocommerce-customer-account-enable-label-for-billing-and-shipping-adress.php
Last active February 24, 2022 12:51
WooCommerce - Customer account: Enable "Label" for billing and shipping address
// Billing Fields.
add_filter( 'woocommerce_billing_fields', 'custom_woocommerce_billing_fields' );
function custom_woocommerce_billing_fields( $fields ) {
$fields['billing_address_2']['label'] = 'Address 2';
$fields['billing_address_2']['label_class'] = '';
return $fields;
}
// Shipping Fields.
@manuelhudec
manuelhudec / woocommerce-customer-account-shop-recently-purchased-products.php
Created June 1, 2021 19:07
WooCommerce - Customer account: Show recently purchased products
add_filter ( 'woocommerce_account_menu_items', 'misha_purchased_products_link', 40 );
add_action( 'init', 'misha_add_products_endpoint' );
add_action( 'woocommerce_account_purchased-products_endpoint', 'misha_populate_products_page' );
// here we hook the My Account menu links and add our custom one
function misha_purchased_products_link( $menu_links ){
// we use array_slice() because we want our link to be on the 3rd position
return array_slice( $menu_links, 0, 2, true )
+ array( 'purchased-products' => 'Purchased Products' )
@manuelhudec
manuelhudec / woocommerce-hide-category-product-count-in-product-archives.php
Created June 1, 2021 19:08
WooCommerce - Hide category product count in product archives
add_filter( 'woocommerce_subcategory_count_html', '__return_false' );
@manuelhudec
manuelhudec / woocommerce-reviews-as-shortcode.php
Created June 1, 2021 19:08
WooCommerce - Reviews as shortcode
add_shortcode( 'wpse_comments_template', function( $atts = array(), $content = '' )
{ if( is_singular() && post_type_supports( get_post_type(), 'comments' ) )
{
ob_start();
comments_template();
return ob_get_clean();
}
return '';
}, 10, 2 );
@manuelhudec
manuelhudec / woocommerce-display-out-of-stock-products-in-archives-last.php
Created June 1, 2021 19:10
WooCommerce - Show out of stock products in archives last
add_action( 'woocommerce_product_query', 'out_of_stock_last', 999 );
function out_of_stock_last( $query ) {
if ( is_admin() ) return;
$query->set( 'meta_key', '_stock_status' );
$query->set( 'orderby', array( 'meta_value' => 'ASC' ) );
}
@manuelhudec
manuelhudec / woocommerce-shopping-cart-redirect-to-checkout.php
Created June 1, 2021 19:10
WooCommerce - Shopping cart redirect to checkout
add_action( 'template_redirect', function() {
// Replace "cart" and "checkout" with cart and checkout page slug if needed
if ( is_page( 'cart' ) ) {
wp_redirect( '/checkout/' );
die();
}
} );
add_action( 'template_redirect', 'redirect_empty_checkout' );
@manuelhudec
manuelhudec / woocommerce-enable-gutenberg-support-for-products.php
Created June 1, 2021 19:11
WooCommerce - Enable Gutenberg support for products
function activate_gutenberg_product( $can_edit, $post_type ) {
if ( $post_type == 'product' ) {
$can_edit = true;
}
return $can_edit;
}
add_filter( 'use_block_editor_for_post_type', 'activate_gutenberg_product', 10, 2 );
// enable taxonomy fields for woocommerce with gutenberg on
function enable_taxonomy_rest( $args ) {
@manuelhudec
manuelhudec / woocommerce-hide-checkout-fields-in-the-checkout-page.php
Created June 1, 2021 19:14
WooCommerce - Hide checkout fields in the checkout page
// Remove checkout fields
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
// remove billing fields
// unset($fields['billing']['billing_first_name']); // Billing First name
// unset($fields['billing']['billing_last_name']); // Billing Last name
// unset($fields['billing']['billing_company']); // Billing company
// unset($fields['billing']['billing_address_1']); // Billing Address 1
// unset($fields['billing']['billing_address_2']); // Billing Address 2
@manuelhudec
manuelhudec / woocommerce-remove-tabs-in-single-product.php
Created June 1, 2021 19:17
WooCommerce - Remove Tabs in single product
add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
function woo_remove_product_tabs( $tabs ) {
// unset( $tabs['description'] ); // Remove the description tab
// unset( $tabs['reviews'] ); // Remove the reviews tab
// unset( $tabs['additional_information'] ); // Remove the additional information tab
return $tabs;
}