• Resolved Matt Pramschufer

    (@mattpramschufer)


    Hey there,

    We use your plugin and it works great. However we are trying to utilize the TD Composer from TagDiv for their Newspaper theme, and when we create a product cloud template, the fields do not show up on the front end of the site. Is there a way to manually inject them into a template via shortcode or code snippet?

    Example of it working – https://www.myneworleans.com/product/magazine/

    Example of page with TD Composer – https://staging.myneworleans.com/product/magazine/

    I have a feeling that the TD composer is not firing the proper actions on their cloud templates, so I am hoping you might be able to help me out and see what I can do to get the Gifting custom field to show up.

    Thanks in advance!

    The page I need help with: [log in to see the link]

Viewing 14 replies - 1 through 14 (of 14 total)
  • Thread Starter Matt Pramschufer

    (@mattpramschufer)

    Just a followup, I looked at your code and you are tapping into “woocommerce_before_add_to_cart_button” action, so i added the follow action in my code snippets and I can confirm that it shows up on the product page, but I just do not know why the product options are not showing up.

    add_action(‘woocommerce_before_add_to_cart_button’, function(){
    echo ‘Here’;
    });

    Plugin Author Maarten

    (@maartenbelmans)

    Hi @mattpramschufer

    I tried accessing your site but get a 403 error. Are you blocking it from the outside world?

    Thread Starter Matt Pramschufer

    (@mattpramschufer)

    Ahh, yes we actually are blocking outside US. Are you able to VPN to the states and view? If not if you wanted to reach out to me directly via email I can grab your IP and whitelist you

    Plugin Author Maarten

    (@maartenbelmans)

    I can’t VPN, sorry. Please lift the blockage temporarily so we can check it.

    Thread Starter Matt Pramschufer

    (@mattpramschufer)

    Okay I have just temporarily removed that. You can try now.

    I was able to find out why it is not working, it is because the global $product is null.

        public function display_field_groups() {
    
                global $product;
            var_dump($product);
    
                if(!$product)
                    return;

    var_dump(‘line 192’);

    You will see on the staging my output debug code.

    Plugin Author Maarten

    (@maartenbelmans)

    When visiting a “single product” page, WooCommerce sets a global variable $product which is then accessible through various hooks (such as woocommerce_before_add_to_cart_button which we use).

    This works correctly with page builders like Divi, Elementor, Beaver Builder, etc… If this doesn’t work with your page builder, there are a few things I can think of:

    1) The page you are creating is just a page, and not a “single product” template. In that case, our plugin and Woo have no idea you are trying to create a product page. For plugins, this is just a regular page. From the source code of your page, this does not seem to be the case so I think you can ignore this point.

    2) You have a plugin or custom code snippet that is overwriting the global $product variable somewhere. Woo sets it correctly, but a plugin or code can be removing it. You can test if this is the case by disabling all custom coding and all plugins except ours and WooCommerce. If that solves the issue, you know you have another plugin overwriting the $product variable.

    2) Your theme is not following Woo standards 100%. Ask the authors of your theme why the global $product is null while it should point to the product object (which correctly happens with other themes and page builders).

    Thread Starter Matt Pramschufer

    (@mattpramschufer)

    Thanks for the feedback, I have already confirmed 1 and 2, and the 3rd item is what I was going to do next. I totally understand this is not an issue with your plugin, and I really appreciate the knowledgable replies to my questions. I’m going to reach out to TagDiv now and see what we can come up with. If I get a response from them I will follow up on this thread for others, but in the meantime we can just mark this as resolved. 🙂

    Plugin Author Maarten

    (@maartenbelmans)

    Thanks, I appreciate that! Hopefully they’re quick about it!

    Thread Starter Matt Pramschufer

    (@mattpramschufer)

    So I haven’t heard back yet from TagDiv, but I was able to get it to work by modifying your display_field_groups function to have the following. It sucks that I have to do this, but was the only way I could do it with what they give me. I was thinking that maybe adding a filter there for $product could be beneficial for other developers/pagebuilders that do not follow standards?

        public function display_field_groups() {
    
            global $product;
    
            if(is_null($product)){
                global $td_woo_state_single_product_page;
                $product = $td_woo_state_single_product_page->get_product();
            }
    
            if(!$product)
                    return;
    Plugin Author Maarten

    (@maartenbelmans)

    Hi @mattpramschufer

    Glad you found a fix (albeit not ideal)! I’m not against introducing filters, but there are a few issues I currently have:

    1. Adding filters introduces new complexity: we must maintain them, and everyone using them will contact us for support if their custom code doesn’t work. This introduces a potential support bottleneck, which we can’t really handle in the free version.
    2. Filters are primarily meant to extend code, not fix issues. Seems a little crazy that we need to add a filter to something so basic ( “global $product”) 🙂
    3. We’d like to keep our code as lightweight and quality-oriented as we can, for everyone. Adding a filter there (to a function that is run early in the game and on every page), we are a step further from guaranteeing that same quality (not necessarily in terms of speed, but more in terms of “spaghetti code”).

    I would prefer if the people from TagDiv just stuck to the Woo standards and fixed it on their end. I am definitely open to discuss this with them if they think I am in the wrong. But as your own debugging already pointed out, it doesn’t seem related to our plugin. So do we really need to add a filter to fix someone else’s things? It’s an interesting discussion for sure, but I’m in doubt!

    Thread Starter Matt Pramschufer

    (@mattpramschufer)

    Oh I totally agree! I was being selfish and wanting the filter for my own benefit so I didn’t have to worry about upgrades! Ultimately I am hoping TagDiv will get back to me with a proper solution. However in the meantime, my “hack” works for my needs, and if someone stumbles onto this thread maybe it will help them as well. Again, if I hear anything back from TagDiv with a proper fix, I will be sure to update this thread. Thanks again.

    Plugin Author Maarten

    (@maartenbelmans)

    Please do! We can circle back to the filter debate when they are not fixing it on their end. In the meantime: thanks for your understanding!

    Thread Starter Matt Pramschufer

    (@mattpramschufer)

    Hey @maartenbelmans TagDiv hasn’t gotten back to me yet, but I finally figured it out! If you want to check out the video below, apparently if you do not include the WooCommerce Ratings widget on their template then it does not populate the global $product;

    [video src="https://s3.amazonaws.com/pramadillo/pramadillo-2024-05-07-14-36-12.mp4" /]

    So long story short, no need to have a discussion about a filter on your plugin, your plugin is fantastic the way it is!

    Plugin Author Maarten

    (@maartenbelmans)

    Thanks for the update! It’s still strange but at least you found a temporary workaround! Hopefully TD replies soon.

Viewing 14 replies - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.