[Support request] woocommerce category images / rows

Home Forums Support woocommerce category images / rows

This topic contains 36 replies, has 3 voices, and was last updated by  Tom 3 days, 15 hours ago.

Viewing 15 posts - 16 through 30 (of 37 total)
  • Author
    Posts
  • #1075266

    sparkle

    i’m setting it to contain just your code in my functions file. but here are the other functions i had.

    <?php
    /**
     * GeneratePress child theme functions and definitions.
     *
     * Add your custom PHP in this file. 
     * Only edit this file if you have direct access to it on your server (to fix errors if they happen).
     */
    function generatepress_child_enqueue_scripts() {
    	if ( is_rtl() ) {
    		wp_enqueue_style( 'generatepress-rtl', trailingslashit( get_template_directory_uri() ) . 'rtl.css' );
    	}
    }
    add_action( 'wp_enqueue_scripts', 'generatepress_child_enqueue_scripts', 100 );
    
    // Enqueue Google Fonts.
    function wpb_add_google_fonts() {
    
    wp_enqueue_style( 'wpb-google-fonts', 'https://fonts.googleapis.com/css?family=Aclonica|Catamaran|Krona+One', false ); 
    }
    
    add_action( 'wp_enqueue_scripts', 'wpb_add_google_fonts' );
    
    add_action( 'wp_enqueue_scripts', 'tu_load_font_awesome' );
    // Enqueue Font Awesome.
    function tu_load_font_awesome() {
        wp_enqueue_style( 'font-awesome', '//use.fontawesome.com/releases/v5.3.1/css/all.css', array(), '5.3.1' );
    }
    
    // Use ACF with Elementor.
    define ('ACF_EARLY_ACCESS', '5');
    
    // Change number of products that are displayed per page (shop page)
    add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 21);
    
    function new_loop_shop_per_page( $cols ) {
      // $cols contains the current number of products per page based on the value stored on Options -> Reading
      // Return the number of products you wanna show per page.
      $cols = 21;
      return $cols;
    }
    
    // html in excerpts
    function wpse_allowedtags() {
        // Add custom tags to this string
            return '<script>,<style>,<br>,<em>,<i>,<ul>,<ol>,<li>,<a>,<p>,<img>,<video>,<audio><h2><h3>'; 
        }
    
    if ( ! function_exists( 'wpse_custom_wp_trim_excerpt' ) ) : 
    
        function wpse_custom_wp_trim_excerpt($wpse_excerpt) {
        $raw_excerpt = $wpse_excerpt;
            if ( '' == $wpse_excerpt ) {
    
                $wpse_excerpt = get_the_content('');
                $wpse_excerpt = strip_shortcodes( $wpse_excerpt );
                $wpse_excerpt = apply_filters('the_content', $wpse_excerpt);
                $wpse_excerpt = str_replace(']]>', ']]>', $wpse_excerpt);
                $wpse_excerpt = strip_tags($wpse_excerpt, wpse_allowedtags()); /*IF you need to allow just certain tags. Delete if all tags are allowed */
    
                //Set the excerpt word count and only break after sentence is complete.
                    $excerpt_word_count = 75;
                    $excerpt_length = apply_filters('excerpt_length', $excerpt_word_count); 
                    $tokens = array();
                    $excerptOutput = '';
                    $count = 0;
    
                    // Divide the string into tokens; HTML tags, or words, followed by any whitespace
                    preg_match_all('/(<[^>]+>|[^<>\s]+)\s*/u', $wpse_excerpt, $tokens);
    
                    foreach ($tokens[0] as $token) { 
    
                        if ($count >= $excerpt_length && preg_match('/[\,\;\?\.\!]\s*$/uS', $token)) { 
                        // Limit reached, continue until , ; ? . or ! occur at the end
                            $excerptOutput .= trim($token);
                            break;
                        }
    
                        // Add words to complete sentence
                        $count++;
    
                        // Append what's left of the token
                        $excerptOutput .= $token;
                    }
    
                $wpse_excerpt = trim(force_balance_tags($excerptOutput));
    
                    $excerpt_end = ' <a href="'. esc_url( get_permalink() ) . '">' . '&nbsp;&raquo;&nbsp;' . sprintf(__( 'Read more about: %s &nbsp;&raquo;', 'wpse' ), get_the_title()) . '</a>'; 
                    $excerpt_more = apply_filters('excerpt_more', ' ' . $excerpt_end); 
    
                    //$pos = strrpos($wpse_excerpt, '</');
                    //if ($pos !== false)
                    // Inside last HTML tag
                    //$wpse_excerpt = substr_replace($wpse_excerpt, $excerpt_end, $pos, 0); /* Add read more next to last word */
                    //else
                    // After the content
                    $wpse_excerpt .= $excerpt_more; /*Add read more in new paragraph */
    
                return $wpse_excerpt;   
    
            }
            return apply_filters('wpse_custom_wp_trim_excerpt', $wpse_excerpt, $raw_excerpt);
        }
    
    endif; 
    
    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('get_the_excerpt', 'wpse_custom_wp_trim_excerpt'); 
    
    // Move Secondary Nav
    
    add_action( 'after_setup_theme', 'lh_move_secondary_nav' );
    function lh_move_secondary_nav() {
        remove_action( 'generate_before_header', 'generate_add_secondary_navigation_before_header', 7 );
        add_action( 'generate_inside_navigation', 'generate_add_secondary_navigation_before_header', 7 );
    }
    
    // Add CPTs to author archives
    function custom_post_author_archive($query) {
        if ($query->is_author)
            $query->set( 'post_type', array('portfolio', 'post') );
        remove_action( 'pre_get_posts', 'custom_post_author_archive' );
    }
    add_action('pre_get_posts', 'custom_post_author_archive'); 
    
    // default images for social media - url fallback required
    
    function jeherve_custom_image( $media, $post_id, $args ) {
        if ( $media ) {
            return $media;
        } else {
            $permalink = get_permalink( $post_id );
            $url = apply_filters( 'jetpack_photon_url', 'https://thebridgebrothers.com/wp-content/uploads/2019/01/Flipped.jpg' );
         
            return array( array(
                'type'  => 'image',
                'from'  => 'custom_fallback',
                'src'   => esc_url( $url ),
                'href'  => $permalink,
            ) );
        }
    }
    add_filter( 'jetpack_images_get_images', 'jeherve_custom_image', 10, 3 );
    
    // Remove Default Category (UNCATEGORIZED from Woocommerce Catalog
    add_filter( 'woocommerce_product_subcategories_args', 'custom_woocommerce_product_subcategories_args' );
    function custom_woocommerce_product_subcategories_args( $args ) {
      $args['exclude'] = get_option( 'default_product_cat' );
      return $args;
    }
    
    //Add clear cart button on checkout page
    	// check for empty-cart get param to clear the cart
    add_action( 'init', 'woocommerce_clear_cart_url' );
    function woocommerce_clear_cart_url() {
        global $woocommerce;
        if ( isset( $_GET['empty-cart'] ) ) {
            $woocommerce->cart->empty_cart();
        }
    }
    add_action( 'woocommerce_cart_actions', 'patricks_add_clear_cart_button', 20 );
    function patricks_add_clear_cart_button() {
        echo "<a class='button' href='?empty-cart=true'>" . __( 'Empty Cart', 'woocommerce' ) . "</a>";
    } 
    
    // ENABLE SHORTCODES IN CONTACT FORM 7 
    add_filter( 'wpcf7_form_elements', 'do_shortcode' );
    
    // turn off admin email check
    add_filter( 'admin_email_check_interval', '__return_false' );
    
    // woo change # of images in row by category
    add_filter( 'option_generate_woocommerce_settings', 'tu_custom_wc_columns' );
    function tu_custom_wc_columns( $options ) {
        if ( is_product_category( 'apparel' ) ) {
            $options['columns'] = 6;
        }
    
        return $options;
    }
    
    

    i’m heading out for the evening but will be back tomorrow to keep trying.

    #1075319

    Leo Customer Support

    Is the function still added?

    Can you make sure it’s the only added function for now?

    #1075408

    sparkle

    yes. it’s the only function in the file.

    View post on imgur.com

    #1076070

    sparkle

    hm, it may or may not be related that the menu in the woocommerce pages are now truncated and the icon buttons don’t show.

    View post on imgur.com

    #1076674

    Tom Lead Developer

    Let’s test that conditional quick..

    add_action( 'generate_before_header', function() {
        if ( is_product_category( 'apparel' ) ) {
            echo 'hi';
        }
    } );

    Does this function add the text “hi” above your header in the apparel category?

    #1076753

    sparkle

    yes, it does. πŸ™‚

    #1076795

    sparkle

    (also i fixed something that brought the icons back)

    #1077179

    Tom Lead Developer

    Weird, that code should work. Is there anything special about the category? Is it using shortcodes or anything to display the content?

    #1077763

    sparkle

    no. the category is populated with items from printful (print on demand) but other than that it’s just a standard archive.

    #1078860

    Tom Lead Developer

    If you use the columns feature in the Customizer (Customize > Layout > WooCommerce), does it do anything?

    #1079609

    sparkle

    yes, i can change the catalog look with the customizer. happy to give you a login if that helps, tom

    #1080479

    Tom Lead Developer

    That would be great, thanks!: https://generatepress.com/contact

    Be sure to mention this topic πŸ™‚

    #1088198

    sparkle

    ok. i sent you the deets in the contact form. i also put back in all my functions on the development site so you can see what i had been working with. i have a back up so feel free to muck around.

    #1088769

    Tom Lead Developer

    Hi there,

    Can you try activating the WooCommerce module in “Appearance > GeneratePress”?

    Let me know πŸ™‚

    #1089405

    sparkle

    ok. i did that and now everything is four across….

Viewing 15 posts - 16 through 30 (of 37 total)

You must be logged in to reply to this topic.