Skip Navigation

[Résolu] Create a custom image field that will display the second image product

This support ticket is created Il y a 1 année et 11 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

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

Ce sujet contient 3 réponses, a 2 voix.

Dernière mise à jour par Waqar Il y a 1 année et 11 mois.

Assisté par: Waqar.

Auteur
Publications
#2506849

I need a custom image field that displays woocommerce product's second image (taken from the product default gallery).

I managed to pull the second image via a shortcode with the following code:

-------------------------
function second_img_func($atts, $content){
$product = wc_get_product( get_the_ID() );
$product_id = $product-> get_id();
$attachment_ids = $product->get_gallery_attachment_ids();

foreach( $attachment_ids as $attachment_id )
{
echo wp_get_attachment_image($attachment_id, 'full');
}
}
-------------------------------------

but I need this image via a custom field to be able to use it in an Elementor widget.

Any ideas please?

#2507477

Hi,

Thank you for contacting us and I'd be happy to assist.

The Elementor's dynamic source feature is something that is managed and maintained by Elementor:
lien caché

I did some research online and Elementor does seem to offer some hooks to customize the output of its widgets ( ref: lien caché ) or register a custom dynamic tag ( ref: lien caché ), both of which could work to achieve, what you're looking for.

I hope this helps and for the most optimal recommendations and alternatives, it would be best to consult their official support team.

regards,
Waqar

#2508155

Thank you for your reply, Waqar.

I understand that Elementor's documentation is a good resource. However, my question was not very clear. Let's forget Elementor for a minute:

How can I grab the second product image and "place it" in a toolset custom field?
Is there a way to link or synchronize both fields? (second image URL and my Toolset custom field)?

#2510347

Thanks for writing back.

> Is there a way to link or synchronize both fields? (second image URL and my Toolset custom field)?

- There is no built-in method available for this, so this will require code customization.

For example, you already have the code to get the values from the WooCommerce product images. You can add a custom function attached to the "save_post" hook ( ref: https://developer.wordpress.org/reference/hooks/save_post/ ) that is executed every time a product post is saved/updated and updates the second image's value in the Toolset's custom field ( ref: https://developer.wordpress.org/reference/functions/update_post_meta/ ).

For more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/