Support

Account

Forum Replies Created

  • I don’t think I put it outside the loop. How would I share the JSON or XML export of the field group?

    The complete template is attached.

  • I wound up having to create a jQuery condition to post the correct file, as I couldn’t work out the ACF code. When I have more time, I’ll go back to it.

  • Each product is assigned a catalog, whether they have Upsells or not.

    WITH YOUR FIRST SET OF CODE:
    Products that have Upsells:
    string(80) “http://domainname.com/wp-content/uploads/Fire-Catalog.pdf”

    Products that have no Upsells are blank

    WITH YOUR SECOND SET OF CODE:
    Products that have Upsells:
    string(80) “http://domainname.com/wp-content/uploads/Fire-Catalog.pdf”

    Products that have no Upsells are blank

  • Thanks for all your work, James, but the above didn’t work either. Logically your code makes sense, but the way WP seems to be posting it still ignores posting the DOWNLOAD CATALOG with products that do not have an ‘Accessories’ associated with it.

  • The Accessories are set using WooCommerce’s UpSells section. If there are no items in the UpSells, I still want the DOWNLOAD CATALOG to display.

    if ( ! defined( 'ABSPATH' ) ) {
    	exit; // Exit if accessed directly
    }
    
    ?>
    <h1 itemprop="name" class="product_title entry-title"><?php the_title(); ?></h1>
    
    <?php
    global $product, $woocommerce_loop;
    
    $upsells = $product->get_upsells();
    
    if ( sizeof( $upsells ) === 0 ) {
    	return;
    }
    
    $meta_query = WC()->query->get_meta_query();
    
    $args = array(
    	'post_type'           => 'product',
    	'ignore_sticky_posts' => 1,
    	'no_found_rows'       => 1,
    	'posts_per_page'      => $posts_per_page,
    	'orderby'             => $orderby,
    	'post__in'            => $upsells,
    	'post__not_in'        => array( $product->id ),
    	'meta_query'          => $meta_query
    );
    
    $products = new WP_Query( $args );
    
    $woocommerce_loop['columns'] = $columns;
    
    if ( $products->have_posts() ) : ?>
    
     	<div class="upsells products">
    
    		<a id="trigger" class="product btn"><?php _e( 'Accessories', 'woocommerce' ) ?> <span class="glyphicon glyphicon-chevron-down">&nbsp;</span></a>
          
    		<?php 
            
                    $file = get_field('catalog');
                    
                    if( $file ) {
                    
                        $url = wp_get_attachment_url( $file );
                        
                        ?><a id="catalog" target="_blank" class="product btn" href="<?php echo $url; ?>" >DOWNLOAD CATALOG</a><?php
                    
                    }
                    
                    ?>  
    
    		<?php woocommerce_product_loop_start(); ?>
    
    			<?php while ( $products->have_posts() ) : $products->the_post(); ?>
    
    				<?php wc_get_template_part( 'content', 'accessories' ); ?>
    
    			<?php endwhile; // end of the loop. ?>
    
    		<?php woocommerce_product_loop_end(); ?>
            
    	</div>
        
       
        
    
    <?php endif;
    
    wp_reset_postdata();
    
    ?>

    What does work, but not layout I want, is to move the DOWNLOAD CATALOG link outside the loop. But then I would have to make modifications to my CSS to force the layout that I want if there was/wasn’t any Accessories to post.

  • Okay. I think I may have found something:

    I have a series of subcategories. My understanding was that the subcategories would have adopted the parent category if there was no Product or Category image assigned to that subcategory. But the code doesn’t work like that. So what I wound up doing is assigning a Category and Product to each subcategory, and everything works from there.

  • Nothing posts. Not even the ‘No accessories’ message.

  • Narrowing it down:
    There is one category that the images are working correctly with the logic that if there is no “products_background_image” then it would take the category’s image.

    With another category, I selected the same images (for testing). All of the items under that category are NOT adopting the category image, leaving a blank space.

    Where shall I look next?

  • Well it seems this has quit working:

    <?php 
      $taxonomy = 'product_cat';
      $queried_object = get_queried_object(); 
      $post_id = $queried_object->ID;
      $terms = wp_get_post_terms($post_id, $taxonomy, array('fields' => 'ids'));
      $term_id = $terms[0];
      ?>
       
    			<div class="catback" style="background-image: url('<?php the_field('products_background_image', $taxonomy . '_' . $term_id); ?>');"></div>

    I’m not sure why.
    I have a Category image assigned and Products image assigned under the Category. The image no longer appears.

    Would upgrading to PRO have caused this to stop working?

  • Well I’ve managed to get it working, although it’s the querest thing. I guess I’ll have to wait to see what the developer comes up with and see if it happens again.

  • Well I can’t say it worked for me.

    I reinstalled the latest version (I already had it) and still nothing is posting in the frontend. It doesn’t make sense to disable the plugins because I have other ACF fields developed and they post just fine in the frontend.

    So I went in a disabled most of the plugins (all but two: ACF and Woocommerce) and still nothing posting on the frontend.

  • So you’re suggesting I revert back to 5.3.5 and start all over again and then update? There’s no fix?

  • THAT works great! Thank you for taking the time to help me solve this.

    I can see that the taxonomy had to be specific, the post_id is based on the object that is being queried, the terms is based on the post ID, taxonomy, and then it creates the array of ids. So then the ‘$term_id’ variable is a loop, right?

  • Okay. You’re dealing with an idiot here.

    I’ve added another field under the Category Background Image Custom Field so when the user chooses the Category Background image, they can also add the Product Background image (the settings are the same as the Category Background Image field) so all products under that one category will share the same image. This is logical.

    But I’m wondering if that makes a difference in the call in the template.

    I’m using the same code, but changed to post the ‘product’ image field:
    <div class=”catback” style=”background-image: url(‘<?php the_field(‘products_background_image’, $taxonomy . ‘_’ . $term_id); ?>’);”></div>

    But it comes up blank. Why would it make much difference which field I’m calling if it’s for a specific taxonomy?

  • This works great for the Category Pages. Now I’m trying to implement a header background image for the product pages. The product pages are only going to use ONE image per category. So say a product that is under the Fan category would need to use a background image and all of the other products under that same category would use the same image.

    A different product under a different category would use a different image and all other products under that same category would use the same image.

    Is there any way to do this type of condition for product pages and post the code in the ‘single-product.php’ page?:

  • I think I got it figured out:

    <?php
    		$queried_object = get_queried_object(); 
    		$taxonomy = $queried_object->taxonomy;
    		$term_id = $queried_object->term_id;  
    	?>
       		<?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
    
    			<div class="catback" style="background-image: url('<?php the_field('category_background_image', $taxonomy . '_' . $term_id); ?>');">
        
    				<h1 class="page-title"><?php woocommerce_page_title(); ?></h1>
                
          		</div>
    
    		<?php endif; ?>

    I’ve only tested it with one category, though. So I’ll be testing with more categories to see if it works.

Viewing 17 posts - 51 through 67 (of 67 total)