/* function woocommerce_get_loop_display_mode() { if ( is_search() ) { return 'products'; } // Only return products when filtering things. if ( wc_get_loop_prop( 'is_search' ) || wc_get_loop_prop( 'is_filtered' ) ) { return 'products'; } $parent_id = 0; $display_type = ''; if ( is_shop() ) { $display_type = get_option( 'woocommerce_shop_page_display', '' ); } elseif ( is_product_category() ) { $parent_id = get_queried_object_id(); $display_type = get_term_meta( $parent_id, 'display_type', true ); $display_type = '' === $display_type ? get_option( 'woocommerce_category_archive_display', '' ) : $display_type; } if ( ( ! is_shop() || 'subcategories' !== $display_type ) && 1 < wc_get_loop_prop( 'current_page' ) ) { return 'products'; } // Ensure valid value. if ( '' === $display_type || ! in_array( $display_type, array( 'products', 'subcategories', 'both' ), true ) ) { $display_type = 'products'; } // If we're showing categories, ensure we actually have something to show. if ( in_array( $display_type, array( 'subcategories', 'both' ), true ) ) { $subcategories = woocommerce_get_product_subcategories( $parent_id ); if ( empty( $subcategories ) ) { $display_type = 'products'; } } return $display_type; } */ /* * Snippet: How to Stop Spam Orders in WooCommerce Without a Plugin – 2024 * Author: John Cook * URL: https://wcsuccessacademy.com/?p=1560 * Tested with WooCommerce 9.3.3 * "This function adds a honeypot field to WooCommerce checkout to trap bots" */ function wcsuccess_add_honeypot_field() { echo '
'; } add_action( 'woocommerce_before_checkout_form', 'wcsuccess_add_honeypot_field' ); function wcsuccess_check_honeypot_field() { if ( ! empty( $_POST['honey_field'] ) ) { wc_add_notice( __( 'Spam detected. Please try again.', 'woocommerce' ), 'error' ); wp_die(); // Stop processing the order } } add_action( 'woocommerce_checkout_process', 'wcsuccess_check_honeypot_field' );