[Resolved] Insert “Edit” link to Cred form into single-product.php

This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

You are not logged in. You can view support threads, but not post.
If you are already logged in, please refresh your browser.

This thread is resolved. Here is a description of the problem and solution.

Problem:
Display CRED Edit form for Products and "Edit" link below the WooCommerce product description in the single-products.php template file.

Can we use the below shortcode in a php template file (e.g. WooCommerce single-product.php)?

[toolset-edit-post-link content_template_slug="cred-edit-form-in-ct"]Edit %%POST_TITLE%%[/toolset-edit-post-link]

Solution:
No, at moment CRED Edit form shortcode can not be executed in WooCommerce single-product.php -- it is submitted as a feature request for further consideration. However, this shortcode works fine in normal post template php files.

1. Alternatively, display CRED editing forms for Products using standard Toolset method which works great:
https://wp-types.com/documentation/user-guides/displaying-cred-editing-forms/

2. OR you may want to use Views shortcode “Post edit link”.

[wpv-post-edit-link text="Edit Item"]

This does not work as frontend edit form but just gives a link that will take user to backend editor.

Some testing notes:
- This shortcode [toolset-edit-post-link] works when we insert directly in Product's body content / Product Description editor (NO Views CT).

- This shortcode [toolset-edit-post-link] also works when we add it in single.php file (Posts) and single-book.php file (CPT).

Relevant Documentation:
- https://wp-types.com/documentation/user-guides/displaying-cred-editing-forms/
- [toolset-edit-post-link] shortcode and its attributes are mentioned here:
https://wp-types.com/documentation/user-guides/views-shortcodes/#toolset-edit-post-link

Related documentation:

This topic contains 17 replies, has 2 voices, and was last updated by  Cec1413 1 month, 4 weeks ago. The support staff assigned to this topic is Noman.

Viewing 15 posts - 1 through 15 (of 18 total)
Author
Posts
#548253

I am trying to: add a WooCommerce hook to display an "Edit" link below the product description in the single-products.php content loop.

I've got a cred form 'Edit Product' and I figure I can use WC hooks to display a link to a WP page containing a content template shortcode which displays the 'Edit Product' form in the body of the page.

Following the guides/examples in docs and training sites, I created a cred form to edit an existing product (current in loop), and a content template to show it, based on the docs. The only thing is I could find extensive information on getting the form or content template to show up in product page using php.

This is what I've got so far.

WP Pages post type slug

wp-edit-product-page

Shortcode used in wp-edit-product-page

[wpv-post-body view_template="wc-edit-product"]

Shortcode used in wc-edit-product Content Template

[cred_form form='cc-product-form' form_name='Edit Product']

Content Template to display edit link based on user (SLUG: cc-wcsingleprod-edit-product-link)

  [wpv-conditional if="('[wpv-current-user info='id']' eq '[wpv-post-author format='meta' meta='ID']') OR ('[wpv-current-user info='role']' eq 'administrator')"] 
  [cred_link_form form='Edit Product' text='Edit' target='_self']
  [/wpv-conditional] 

For WC
PHP in child theme Functions.php

add_action( 'woocommerce_single_product_summary', 'show_edit_link', 70 );

function show_edit_link() {
    echo (CODE-TO-CALL-cc-wcsingleprod-edit-product-link);
}

where I'm clueless as to what to put in place of CODE-TO-CALL-cc-wcsingleprod-edit-product-link.

I can't figure out from the documentation on customising with php how to display the content template for the Edit link.
Any help would be greatly appreciated, and all the more so if I can be directed to documentation that illustrates how views/content template shortcodes can be used in php.

Thanks in advance.

#548302

Noman
Forum moderator

Supporter languages: English (English )

Supporter Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting Toolset Support. To add the Post / Product Edit links in a php template file, the procedure will be same as you add it in a View or Content Template using plugin interface as explained in this doc: https://wp-types.com/documentation/user-guides/displaying-cred-editing-forms/

The only difference is that you will insert the final editing link shortcode into your php file (instead of View or Content Template), the shortcode is this one:

[toolset-edit-post-link content_template_slug="cred-edit-form-in-ct"]Edit %%POST_TITLE%%[/toolset-edit-post-link]

And it can be added in php template file like this:

<?php echo do_shortcode( '[toolset-edit-post-link content_template_slug="cred-edit-form-in-ct"]Edit %%POST_TITLE%%[/toolset-edit-post-link]' ); ?>

==> Please ensure to replace content_template_slug="cred-edit-form-in-ct" with your Content Template slug that carries the cred edit form.

2. I can be directed to documentation that illustrates how views/content template shortcodes can be used in php.
==> You can use any Views/ Content Template shortcode in php template file using do_shortcode like the example I provided here, just replace the example shortcode with the one you want to use:
https://wp-types.com/forums/topic/buttons-added-by-3rd-party-plugins-in-views-or-layouts/#post-548001

Thank you

#548321

Thanks again, Noman. I'll give your instructions a shot when I'm back at my desk. Meanwhile, I am following your response in an earlier topic regarding the do_shortcode action, but what I was asking was where I can find a comprehensive list/details on the arguments I can pass through - ie 'toolset-edit-post-link' as you provided in your response above. I did come across a similar one in an old forum post during my search, but am struggling to find documentation on it. Could you provide a link to such documentation? Please and thank you in advance.

#548327

Noman
Forum moderator

Supporter languages: English (English )

Supporter Timezone: Asia/Karachi (GMT+05:00)

[toolset-edit-post-link] shortcode and its attributes are mentioned here:
https://wp-types.com/documentation/user-guides/views-shortcodes/#toolset-edit-post-link

Views shortcodes are listed on the same above page, every shortcode has different set of options & attributes. There are too many shortcodes for Views and it is possible that some shortcode might not be documented in the above page but you may find it in interface / UI or in our forums. If you find any such shortcode please let us know and we will try our best to add that to the page.

I hope this information is sufficient. Thank you

#548384

Yes, the shortcodes list is certainly extensive.
I've tried the above steps, by the way, and while the single product pages now include an edit link, it doesn't seem to load the content template with the cred form. The URL does change from /product-item/ to /product-item/?content-template-id=206531 in the browser, but the rendered page still shows the regular single product content, not the cred form I created.
FYR, this is what I have in the content template:


[wpv-conditional if="('[wpv-current-user info='id']' eq '[wpv-post-author format='meta' meta='ID']') OR ('[wpv-current-user info='role']' eq 'administrator')"] 
[cred_form form='cc-product-form-coo' form_name='CC Product form coo']
[/wpv-conditional]

The content template usage was initially set to none, but i did try Usage: Products as well.

This is what's in the functions.php:

add_action('woocommerce_after_single_product_summary', 'show_edit_link', 15);

function show_edit_link() {
    echo do_shortcode('[toolset-edit-post-link content_template_slug="cc-edit-product"]Edit item[/toolset-edit-post-link]');
}

Am I missing something here?

#548433

Noman
Forum moderator

Supporter languages: English (English )

Supporter Timezone: Asia/Karachi (GMT+05:00)

1. Does the same shortcode works when you insert that shortcode in a Content Template created by views-plugin? This will ensure that the initial steps of creating CRED Edit form links are correct or not.

2. 'woocommerce_after_single_product_summary' Is this action working properly when you echo some text content for testing purpose?

3. Also its helpful to check the same thing in a default theme like Twenty Seventeen theme.

If above does not solve the issue, then I would need to request temporary website WP-admin and FTP info for your site to debug further and to help in resolving this. Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. Thank you

#548593

[Update]
1. Does the same shortcode works when you insert that shortcode in a Content Template created by views-plugin? This will ensure that the initial steps of creating CRED Edit form links are correct or not.
>> I have tried the same content template in a pages post type and that seems to work right. Not sure if this would have the same implication.

2. 'woocommerce_after_single_product_summary' Is this action working properly when you echo some text content for testing purpose?
>> Yes, I did try this initially to ensure that the placement and hook worked as I wanted, before I even tried inserting the toolset shortcode.

[Edit]
3. Also its helpful to check the same thing in a default theme like Twenty Seventeen theme.
>> On Twentyseventeen, with the same modifications in functions.php, it seems that single-product.php does not render product content at all - just the title and the toolset-edit-post-link content appears (see screenshot 1).
3a. Note that this happens when Product Template file option is set to WC Views Template files in WC Views settings. In this case, the Edit link actually works and when clicked, renders the cred form onto the page.
3b. If I change this setting to use default WC Template files, I get the product contents back, as well as the Edit link, but when clicking the link, it simply refreshes the pages with the same content (ie no cred form).

This is consistent with the Divi child theme I was originally working with as well.

#548695

Noman
Forum moderator

Supporter languages: English (English )

Supporter Timezone: Asia/Karachi (GMT+05:00)

Thank you for providing login details and more information, I am working on this issue and will get back to you soon with an update.

Thank you for your patience.

#548787

Noman
Forum moderator

Supporter languages: English (English )

Supporter Timezone: Asia/Karachi (GMT+05:00)

I have tested various things but this shortcode [toolset-edit-post-link] is not working in the php template file, it works fine if we add directly into the product / post body content.

I am trying to get more info from our developer to see what's expected or if there is something we need to make it work in a template file. I will update you accordingly.

Thank you for your patience & cooperation.

#548791

Yes, that's what I figured as well, somehow it just won't work with the default woocommerce single product template, but when you switch view to use the woocommerce views template, it works just fine.

#548858

Noman
Forum moderator

Supporter languages: English (English )

Supporter Timezone: Asia/Karachi (GMT+05:00)

After discussing with lead developer it turns out that this shortcode does not work via php template file for WooCommerce due to the woocommerce template engine handles things differently, it's a kind of compatibility issue. I have now escalated this issue to our 2nd tier support for further review and we will get back to you with an update.

Alternatively you may want to use Views shortcode “Post edit link”

[wpv-post-edit-link text="Edit Item"]

This does not work as frontend edit form but just gives a link that will take user to backend editor, I understand that is not equivalent though.

Some testing notes:
- This shortcode [toolset-edit-post-link] works when we insert directly in Product's body content / Product Description editor (NO Views CT).

- This shortcode [toolset-edit-post-link] also works when we add it in single.php file (Posts) and single-book.php file (CPT).

Thank you

#548975

I appreciate the update, Noman. I was afraid the issue might be one of compatibility with woocommerce. At the moment, I suppose the clear options are to either switch to using the Views woocommerce template and forego third-party plugin features, or stick with the standard woocommerce template and forego frontend cred forms on that page.

Question: Is there perhaps a way to pass current product post ID from single product through a link to a Pages post type containing a cred form that then edits the passed product post ID?

For eg:
WC's single-product.php renders a Product of post ID 2233
In functions.php, print a link to a pages post type (titled "Edit Product" for example) carrying the post ID forward
The Edit Product page will call a view or cred form for the post ID

Is there any way this is possible?

On a related note, do you still need login access to the site and ftp?

#549000

[Update]

I also just realised that the version of components I've got installed are slightly outdated. Not sure if it's relevant, but thought I'd mention it anyway as it hasn't come up yet.
CRED 1.9
Access 2.4
Views 2.7.3
Framework Installer 2.1.4 (inactive)

FYI, I plan to update to the current versions of these components today.

#549437

Noman
Forum moderator

Supporter languages: English (English )

Supporter Timezone: Asia/Karachi (GMT+05:00)

- Plugins you can update but edit product form is not related to current version basically.

- Site logins if you can keep same that's great because I have escalated this ticket for further review to 2nd tier. But if its required to change login, you can do so as well as post comment here.

- The example you have think upon for passing post / product ID that will still be somewhat similar thing and won’t work. WooCommerce template engine is complex than that of WP default one due to which CRED is not able to takeover it easily, so unfortunately this may not work with this approach.

Its may be possible using some custom method. If you would like you can contact Toolset recommended consultants to further discuss the custom approach. We have some recommended list of service providers here if you would like to take a look: https://wp-types.com/consultant/

I am also waiting to hear back from 2nd tier support & developer as I logged this as feature or compatibility issue, I will update you accordingly. Thank you

#549450

Fair enough. I updated and checked and definitely no difference.

I'll leave the logins as they are, it's not an issue - just let me know when they are not required.

Something else I noticed, that I hadn't realised before, is that the WC products post type does not appear to be manageable by Toolset, as Posts and Pages post types are. Meanwhile it seems the woocommerce post terms are open to toolset. I imagine this is an limitation along similar lines?

As a side note, while I know you guys aren't required to suggest alternatives, I'd totally appreciate it if you have a spark of an idea on an alternative option I could experiment with to work around the current limitation. Totally fine, of course, if you don't get a sudden eureka moment 😀 - I'm certainly not getting any sparks myself.

Viewing 15 posts - 1 through 15 (of 18 total)

You are not logged in. You can view support threads, but not post.
If you are already logged in, please refresh your browser.

Known issues and their solutions

We document known issues and their solutions in Toolset erratas. Save time by checking there first and seeing if what you are facing is a known issue. This list is kept short. We do our best to resolve all known issues with every release of Toolset plugins.

Support Policy

Toolset staff will help you use the Toolset plugins correctly, provide any information you need, help troubleshoot problems and advice on best-practices.

Please make sure to issue only one topic per each support ticket.

For more information, read our full Customer Support Policy.

Need custom programming work for your site? Check out our certified partners.