This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Don't use this it is a bad idea. This code replaces all acrhcive and shop page thumbnail links to work as add to cart urls. When clicked the item will be added to cart instead of opening the single product page. Works only for simple products (obviously). | |
| function wc_custom_shop_thumbnail_link( $link, $product ) { | |
| if ( $product->is_type( 'simple' ) && ( is_shop() || is_product_category() || is_product_tag() ) ) { | |
| $link = '?add-to-cart='. $product->get_id(); | |
| } | |
| return $link; | |
| } | |
| add_filter( 'woocommerce_loop_product_link', 'wc_custom_shop_thumbnail_link', 10, 2 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_action( 'template_redirect', 'remove_woocommerce_styles_scripts', 999 ); | |
| function remove_woocommerce_styles_scripts() { | |
| if ( function_exists( 'is_woocommerce' ) ) { | |
| if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) { | |
| remove_action('wp_enqueue_scripts', [WC_Frontend_Scripts::class, 'load_scripts']); | |
| remove_action('wp_print_scripts', [WC_Frontend_Scripts::class, 'localize_printed_scripts'], 5); | |
| remove_action('wp_print_footer_scripts', [WC_Frontend_Scripts::class, 'localize_printed_scripts'], 5); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function custom_password_protected_error_message( $translated_text, $text, $domain ) { | |
| if ( $text === 'This product is protected and cannot be purchased.' ) { | |
| $translated_text = 'Your custom error message here.'; | |
| } | |
| return $translated_text; | |
| } | |
| add_filter( 'gettext', 'custom_password_protected_error_message', 20, 3 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This code will resave / update 200 woocommerce products every time you visit one of your pages. Increase or decrease limit depending on your server resources. | |
| add_action( 'woocommerce_loaded', 'update_products_by_x' ); | |
| function update_products_by_x(){ | |
| $limit = 200; | |
| // getting all products | |
| $products_ids = get_posts( array( | |
| 'post_type' => 'product', // or ['product','product_variation'], | |
| 'numberposts' => $limit, | |
| 'post_status' => 'publish', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //This script will reattach media files to their relvant products (when you open and update a product) that do not get assigned when you import via a csv. | |
| add_action( 'woocommerce_process_product_meta', function ( $post_id, $post ) { | |
| global $wpdb; | |
| $attachment_ids = isset( $_POST['product_image_gallery'] ) ? array_filter( explode( ',', wc_clean( $_POST['product_image_gallery'] ) ) ) : array(); | |
| // update posts in the $attachment_ids array to have post_parent = $post_id | |
| $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE ID IN (" . implode( ',', $attachment_ids ) . ")", $post_id ) ); | |
| }, 21, 2 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| This SQL query wll remove all gallery images from all Woo products but leave the Product Image in tact. It will not delete the images from the media gallery. Just detach them from the gallery. | |
| DELETE pm | |
| FROM pwj_postmeta pm | |
| INNER JOIN pwj_posts p ON pm.post_id = p.ID | |
| WHERE p.post_type = 'product' | |
| AND pm.meta_key = '_product_image_gallery'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Wordpress Submit Sendfox Form On User Registration by u/acephaliax | |
| // This snippet will submit a sendfox form of your choosing anytime a new user signs up via a non standard resgstarion method on your wordpress site. Replace the form details below with the form from your dashboard. | |
| function auto_submit_sendfox_form_on_user_register( $user_id ) { | |
| $user_info = get_userdata( $user_id ); | |
| // Prepare the data to be sent | |
| $body = array( | |
| 'first_name' => $user_info->first_name, | |
| 'last_name' => $user_info->last_name, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Swap Woocommerce product thumbnail with first image in gallery by u/acephaliax | |
| //This snippet will swap out the product thumbnail for all archive and shop loops to display first galery image but show product image as main image on a single product page. | |
| add_filter('woocommerce_product_get_image', 'custom_woocommerce_product_get_image', 10, 5); | |
| function custom_woocommerce_product_get_image($image, $product, $size, $attr, $placeholder) { | |
| if (is_shop() || is_product_category() || is_product_tag()) { // Adjust condition as needed | |
| $gallery_images = $product->get_gallery_image_ids(); | |
| if (!empty($gallery_images)) { | |
| $image_id = $gallery_images[0]; // Sets first gallery image as thumbnail |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Disable/Enable Shipping Methods based on the number of products in the cart by u/acephaliax | |
| add_filter( 'woocommerce_package_rates', 'conditionally_enable_shipping_methods', 10, 2 ); | |
| function conditionally_enable_shipping_methods( $rates, $package ) { | |
| $cart_items_count = WC()->cart->get_cart_contents_count(); | |
| // Instance IDs to adjust (replace with your actual IDs) | |
| $method_id_to_disable_for_large_carts = 9; | |
| $method_id_to_enable_for_large_carts = 10; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Start Shop The Look Shortcode by u/acephaliax | |
| function shop_the_look_button_shortcode($atts) { | |
| // Shortcode attributes | |
| $atts = shortcode_atts( | |
| array( | |
| 'ids' => '', // Product IDs comma-separated | |
| ), | |
| $atts, | |
| 'shop_the_look' | |
| ); |