if ( ! function_exists( 'wpcb_hide_product_description_for_non_logged_users' ) ) { /* * wpcb_hide_product_description_for_non_logged_users. * * @see https://wpcodebook.com/snippets/hide-product-description-for-non-logged-users-in-woocommerce/ */ function wpcb_hide_product_description_for_non_logged_users( $content ) { return ( is_product() && ! is_user_logged_in() ? 'You must be logged in to see the product description.' : $content ); } add_filter( 'the_content', 'wpcb_hide_product_description_for_non_logged_users', PHP_INT_MAX ); }
Add screen to WooCommerce screen IDs
add_filter( 'woocommerce_screen_ids', 'wpcb_add_screen_to_wc_screen_ids' ); if ( ! function_exists( 'wpcb_add_screen_to_wc_screen_ids' ) ) { /** * wpcb_add_screen_to_wc_screen_ids. * * @see https://wpcodebook.com/snippets/add-screen-to-woocommerce-screen-ids/ */ function wpcb_add_screen_to_wc_screen_ids( $screen_ids ) { $screen_ids[] = 'your-screen-id'; // to get your screen ID call `$your_screen = get_current_screen()`, then get `$your_screen->id` return $screen_ids; } }
Add product min, max and step quantity columns to admin products list in WooCommerce
add_filter( 'manage_edit-product_columns', 'wpcb_add_product_qty_columns' ); if ( ! function_exists( 'wpcb_add_product_qty_columns' ) ) { /** * Add qty columns to products list. */ function wpcb_add_product_qty_columns( $columns ) { $columns['wpcb_min_qty'] = 'Min Qty'; $columns['wpcb_max_qty'] = 'Max Qty'; $columns['wpcb_qty_step'] = 'Qty Step'; return $columns; } } add_action( 'manage_product_posts_custom_column', 'wpcb_render_product_qty_columns' ); if ( ! function_exists( 'wpcb_render_product_qty_columns' ) ) { /** * Output qty columns. */ function wpcb_render_product_qty_columns( $column ) { switch ( $column ) { case 'wpcb_min_qty': echo apply_filters( 'woocommerce_quantity_input_min', 1, wc_get_product() ); break; case 'wpcb_max_qty': echo apply_filters( 'woocommerce_quantity_input_max', 1, wc_get_product() ); break; case 'wpcb_qty_step': echo apply_filters( 'woocommerce_quantity_input_step', 1, wc_get_product() ); break; } } }
Add Bcc to all emails in WordPress
add_filter( 'wp_mail', 'wpcb_add_bcc_to_all_emails' ); if ( ! function_exists( 'wpcb_add_bcc_to_all_emails' ) ) { /** * wpcb_add_bcc_to_all_emails. * * @see https://wpcodebook.com/snippets/add-bcc-to-all-emails-in-wordpress/ */ function wpcb_add_bcc_to_all_emails( $atts ) { if ( ! isset( $atts['headers'] ) ) { $atts['headers'] = ''; } $atts['headers'] .= 'Bcc: ' . 'email@example.com' . "\r\n"; return $atts; } }
Replace add to cart button on archives with add to cart button from single product page in WooCommerce
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_single_add_to_cart', 10 );