Home › Forums › WoodMart support forum › Add an extra class to wish list button
Add an extra class to wish list button
- This topic has 9 replies, 2 voices, and was last updated 1 year, 3 months ago by
Hung Pham.
-
AuthorPosts
-
November 28, 2023 at 3:34 pm #516357
raulisParticipantHi,
How can I add extra class to wish list button? I need this to track clicks on google tag manager. Trying to integrate GTM kit plugin and they use .add_to_wishlist class to track whish lists.
Thank you.
November 28, 2023 at 5:42 pm #516496
Hung PhamKeymasterHi raulis,
Thanks for reaching to us.
Unfortunately, this cannot be done with Custom Code.
Regards,
November 28, 2023 at 5:54 pm #516506
raulisParticipantHow can it be done?
can’t I copy a file to child theme and add the class?
November 29, 2023 at 9:55 am #516653
Hung PhamKeymasterHi raulis,
You can place custom code in functions.php in Child theme.
However, it requires Customization and this is beyond our limitations and support policy scope. Hope you can understand our limitations.
Regards,
November 29, 2023 at 11:02 am #516732
raulisParticipantYou should want to be compatible with as much llugins as possible for google tracking purpose. Especialy when it is as easy as adding one extra class.
Neverminding that, what file holds the code for add to wishlist button in catalog and in single product pages?
Thank you.
November 30, 2023 at 6:56 pm #517400
Hung PhamKeymasterHi raulis,
Thanks for your patience.
Add below Custom code to functions.php file in Child theme.
add_action( 'init', function () { if ( ( woodmart_get_opt( 'wishlist_logged' ) && is_user_logged_in() ) || ! woodmart_get_opt( 'wishlist_logged' ) ) { remove_action( 'woocommerce_single_product_summary', array( XTS\WC_Wishlist\Ui::get_instance(), 'add_to_wishlist_single_btn' ), 33 ); remove_action( 'woodmart_sticky_atc_actions', array( XTS\WC_Wishlist\Ui::get_instance(), 'add_to_wishlist_sticky_atc_btn' ), 20 ); add_action( 'woocommerce_single_product_summary', function () { wd_add_wishlist_btn( 'wd-action-btn wd-style-text wd-wishlist-icon' ); }, 33 ); add_action( 'woodmart_sticky_atc_actions', function () { woodmart_enqueue_js_library( 'tooltips' ); woodmart_enqueue_js_script( 'btns-tooltips' ); wd_add_wishlist_btn( 'wd-action-btn wd-style-icon wd-wishlist-icon wd-tooltip' ); }, 20 ); } if ( woodmart_get_opt( 'product_loop_wishlist' ) && ( ( woodmart_get_opt( 'wishlist_logged' ) && is_user_logged_in() ) || ! woodmart_get_opt( 'wishlist_logged' ) ) ) { remove_action( 'woodmart_product_action_buttons', array( XTS\WC_Wishlist\Ui::get_instance(), 'add_to_wishlist_loop_btn' ), 30 ); add_action( 'woodmart_product_action_buttons', function () { wd_add_wishlist_btn( 'wd-action-btn wd-style-icon wd-wishlist-icon' ); }, 30 ); } }, 300 ); function wd_add_wishlist_btn( $classes = '' ) { woodmart_enqueue_js_script( 'wishlist' ); if ( woodmart_get_opt( 'wishlist_expanded' ) && 'disable' !== woodmart_get_opt( 'wishlist_show_popup', 'disable' ) && is_user_logged_in() ) { woodmart_enqueue_js_script( 'wishlist-group' ); } $link_classes = 'add_to_wishlist'; $text = esc_html__( 'Add to wishlist', 'woodmart' ); $product_id = apply_filters( 'wpml_object_id', get_the_ID(), 'product', true, apply_filters( 'wpml_default_language', null ) ); $classes .= woodmart_get_old_classes( ' woodmart-wishlist-btn' ); ?> <div class="wd-wishlist-btn <?php echo esc_attr( $classes ); ?>"> <a class="<?php echo esc_attr( $link_classes ); ?>" href="<?php echo esc_url( woodmart_get_wishlist_page_url() ); ?>" data-key="<?php echo esc_attr( wp_create_nonce( 'woodmart-wishlist-add' ) ); ?>" data-product-id="<?php echo esc_attr( $product_id ); ?>" rel="nofollow" data-added-text="<?php esc_html_e( 'Browse Wishlist', 'woodmart' ); ?>"> <span><?php echo esc_html( $text ); ?></span> </a> </div> <?php }
But please note that it will
NOT
work on a Custom Single Produc layout build with WooCommerce builder https://xtemos.com/docs-topic/woodmart-woocommerce-layout-builder/WoodMart theme also has a featurethat shows which products the user has added to the wishlist https://monosnap.com/file/ZLngk3wzSbKPfYIYhgv6QLo6AHHo3w
Regards,
December 1, 2023 at 5:37 pm #517675
raulisParticipantThis seems excesive.
I have found that on woodmart/inc/integrations/woocommerce/modules/wishlist/class-ui.php
Line 499 is the html for the button. So I have added the class I need there and it seems to work perfecly fine.The only question is if you can provide a simple shortcode to add a custom class to this place or I have to copy this whole file to my child theme to keep this change?
I attach image.
Attachments:
You must be logged in to view attached files.December 2, 2023 at 8:58 am #517768
Hung PhamKeymasterHi raulis,
Did you add above Custom Code to functions.php file Child theme file? You can keep this change as well.
Regards,
December 2, 2023 at 1:01 pm #517821
raulisParticipantI mean if it does not add class to single product pages mage with elementor it makes no sense to use it. As The example I said, added the class everywhere.
December 3, 2023 at 6:46 pm #517998
Hung PhamKeymasterHi raulis,
So, you can add class to that file. I will ask developer for more details and update you once I receive replies.
Regards,
-
AuthorPosts
- You must be logged in to create new topics. Login / Register