Forum Replies Created

Viewing 15 replies - 331 through 345 (of 1,795 total)
  • I think I’m with you. So your code above works except when a user uses the filters?

    What happens when you comment out the line:

    
    if ( ! $q->is_main_query() ) return;
    

    I’m wondering if the filters return false on the main query check. It seems like there will be a way to execute your code for the query the filters run as well.

    There may be others, and I haven’t used this so you should check the reviews and support for it, but Order Store Hours Scheduler for WooCommerce would be a good place to start.

    You might find some more candidates on the Plugins Page, though coming up with the keywords to search for is tricky for this one.

    I may be missing the point, but why not just set the products’ “Catalog Visibility” to “Hidden,” which will keep them from appearing in Shop and Search results?

    Hi @polycellroot,

    It’s possible it’s your theme, but I think it’s more likely that I misunderstood what you’re trying to accomplish.

    The code snippet I gave you is built to work on a Product Category Page. In your original post, you asked about “an image in image gallery.” Since you posted in the WooCommerce Support Forum, I assumed the image gallery you meant was a Product Category Page, which shows a gallery of product images with Add to Cart/Select Options buttons.

    Is the image gallery you’re working with a WooCommerce page, or did you build it some other way?

    I think the redirects are kind of messy, so I looked at the possibilities for adding a little code to your child theme’s functions.php to accomplish this so you can use one less plugin.

    The following code will first check to make sure the product in question is an external/affiliate product. If it is, it will change the image link to the same URL as you use for the “Buy Product” button. If it’s not an external/affiliate product, it won’t do anything:

    
    // *** Affiliate Product Landing Page Link ***
    add_action ('woocommerce_before_shop_loop_item', 'custom_product_image_link', 1);
    function custom_product_image_link(){
      global $product;
      if ($product->get_type() == 'external') {
        // For product category archives pages only
        if(is_product_category()){
          // Remove default image link
          remove_action ('woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10);
          // Add custom image link function
          add_action ('woocommerce_before_shop_loop_item', 'custom_set_external_product_image_link', 10);
        }
      }
    }
    
    // Custom image link for external (affiliate) products only.
    function custom_set_external_product_image_link(){
      global $product;
      echo '<a href="' . $product->add_to_cart_url()  . '" class="woocommerce-LoopProduct-link">';
    }
    // *** End Affiliate Product Landing Page Link ***
    

    I tested it, and it’s working for me. Thanks to LoicTheAztec whose code I modified to get this.

    I’m not a Windows guy, but judging from this article, it looks like there are HTTP redirects on Windows servers, but the necessary packages aren’t necessarily installed by default, and your server may not have them. Your web host would be the ones to help with that.

    However, there may be another option. Take a look at the Redirection Plugin. Although it can use .htaccess, which would require Apache, it sounds like the default is to use WordPress (probably just PHP) to do the redirects. I would give that plugin a try with one or two of your products and see if it will work.

    If that doesn’t work, there’s another plugin called 301 Redirects that may.

    If those don’t do the trick, then I’d start looking for a code-based solution to use the “Buy Product” links you’ve added for the image links.

    Okay, I think I know what you mean now.

    Adding the Open Graph meta tag for images does sound like what you need to do.

    Take a look at this tutorial. It suggests using the Yoast SEO plugin to add the Open Graph meta tags and has some useful information about how to debug Facebook if it’s not showing your images. If you don’t need all the features of Yoast SEO, search the plugins page for “open graph” and you’ll see a bunch of plugins that can add the meta tags.

    You will need to add Featured Images to each post, but if there are pages/posts that you don’t want to display a featured image for on your site, you can use CSS to hide them or use a theme that doesn’t display them.

    Sorry about that. You mentioned in your initial post that you wanted the image to link to the landing page as well.

    If you only have a limited number of products that you’ve set up as external/affiliate products, and you want the images to link to the landing page as well as the “Buy Product” buttons, the easiest thing to do would be to create redirects for each link. For example, if you are running on an Apache web server, you’d create .htaccess redirects for the links on the images to the correct landing page.

    If you have a lot of products you want to do this with, then some conditional logic like, “if this is an affiliate product, then set the image link to the same URL as the “Buy Product” button would be a better approach.

    How many products–or is it all your products–are we talking about?

    After I cleared my browser cache of your previous stylesheets, it worked for me consistently, never showing the product count in ~five page loads, so I think that worked, but with an intermittent problem, only time will tell. 🙂

    The alignment of the products on your category pages is dependent on the number of columns you have set in Appearance -> Customize -> WooCommerce -> Product Catalog -> Products Per Row. You could set it to two, which would use larger images and center the two current products, but if you ever add products, you’ll have to adjust the column setting accordingly.

    If you need to change the column setting on a page-by-page basis, there are several options described in the docs. You can do it without an extra plugin as you already have a child theme. Which route you go depends on what you want to accomplish, but it looks like you may only have two products, in which case just setting the column count will work?

    Are you talking about the Site Icon? In WordPress Admin, take a look at Appearance -> Customize -> Site Identity. make sure you have uploaded a 512 x 512 pixel image for your Site Icon.

    It wouldn’t hurt to also add a favicon to the public_html folder for your site.

    If the image gallery you’re thinking of is the Shop Page or some other page showing a list of products, I think you can create a new product and on the General Tab for Product Data, select a Product Type of “External/Affiliate Product” and then put the landing page URL from your own site in the “Product URL” box. Set the Button Text to whatever you want, like, “View Details” or something. On the landing page, use a WooCommerce Block or shortcode to display the link to the actual product.

    The reason I asked where you added it is that I’m trying to determine why it’s not showing up. Since you added it in Additional CSS, I’m thinking that something, perhaps a plugin or your theme, is interfering with it being loaded. If it were in a stylesheet, I would have been thinking more along the lines of some caching issue, either at the server level or maybe with a content delivery network (CDN) serving an old version of the file(s).

    I am seeing the page with the correct CSS now, and I can see where WordPress has loaded it.

    Since we’re dealing with the CSS coming from Additional CSS, maybe something is blocking it. If that’s the case you might be able to discover what’s doing it by disabling all your plugins except WooCommerce using something like the Health Check Plugin, which allows you to test a live site with plugins disabled and a default theme without affecting the site for your customers. You could then enable one thing at a time and test to see which one causes the problem. However, we already know the problem is intermittent, which makes such an approach really difficult; it might make something look responsible when the CSS would be loading anyway.

    The other option is to abandon the Additional CSS utility, and add all the CSS that’s currently in there into your child theme’s stylesheet. Putting the CSS in your child theme’s stylesheet will prevent it from being overwritten when the parent theme is updated. Using a stylesheet instead of Additional CSS might solve the problem. I’d say it’s worth a try that way as it’s less work.

    To try the child theme stylesheet approach, you’d simply copy all the CSS you’ve added into Additional CSS and paste it at the end of the file /public_html/wp-content/themes/savant/style.css, which appears to be your active child theme.

    Next, delete the content in the Additional CSS field. I’d save that CSS in a text file on your PC somewhere too for safety sake.

    Finally, clear any caching plugins you’re running, and check the results.

    That is odd! I just opened the Shop page again, and now I’m seeing the count, and the product is no longer centered! I tried it in two different browsers and both show the same thing.

    When I look at the files loaded currently, the CSS I noted above is not in either:

    
    https://outsource-typing.com/wp-content/themes/avant/style.css?ver=1.0.3
    

    or

    
    https://outsource-typing.com/wp-content/themes/savant/style.css?ver=1.0.3
    

    I would look in your local copies of those two files for the string:

    
    .archive.woocommerce mark.count
    

    and see if you can find it in either. Alternatively, you may have added that CSS in Appearance -> Customize -> Additional CSS.

    Once you find out where the code is supposed to be, we may be able to determine why it’s not showing up intermittently.

    It looks like you’ve already fixed this with the following CSS:

    
    .archive.woocommerce mark.count {
    	display: none;
    }
    

    If you’re still seeing the count, you may need to clear your browser cache.

    I haven’t ever tried it, but there is a plugin called Featured Image by URL that sounds like it will do the trick.

    One thing to keep in mind is that some sites block hotlinking, which is what you’ll be doing, to prevent their bandwidth from being used to display images on other sites.

Viewing 15 replies - 331 through 345 (of 1,795 total)