Title: Custom button HTML Added Text
Last modified: April 20, 2021

---

# Custom button HTML Added Text

 *  [adam198](https://wordpress.org/support/users/adam198/)
 * (@adam198)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/custom-button-html-added-text/)
 * Hello
 * Excellent plugin, but I am trying to change the button HTML in my functions and
   I can get that to work. But the problem I am having is getting it to have the
   class and added text. I know it is because I am not calling the cookie correctly.
   My code is below. What am I doing wrong?
 *     ```
       add_filter( 'woosw_button_html', 'woosw_custom_button_html', 99, 2 );
       function woosw_custom_button_html( $html, $product_id ) {
   
       						global $product;
       						$atts['id'] = $product->get_id();
       					$added = array();
   
       					// added products
       					$key = get_query_var( 'woosw_id' );
   
       					if ( get_option( 'woosw_list_' . $key ) ) {
       						$added = get_option( 'woosw_list_' . $key );
       					}
   
       					if ( $atts['id'] ) {
       						// check cats
       						$selected_cats = get_option( 'woosw_cats', array() );
   
       						if ( ! empty( $selected_cats ) && ( $selected_cats[0] !== '0' ) ) {
       							if ( ! has_term( $selected_cats, 'product_cat', $atts['id'] ) ) {
       								return '';
       							}
       						}
   
       						$class = 'woos-btn woosw-btn woosw-btn-' . esc_attr( $atts['id'] );
   
       						if ( array_key_exists( $atts['id'], $added ) ) {
       							$class .= ' woosw-added';
       							$text  = get_option( 'woosw_button_text_added' );
   
       							if ( empty( $text ) ) {
       								$text = esc_html__( 'Browse wishlist', 'woosw' );
       							}
   
       						} else {
       							$text = get_option( 'woosw_button_text' );
   
       							if ( empty( $text ) ) {
       								$text = esc_html__( 'Add to wishlist', 'woosw' );
       							}
   
       						}
   
       						if ( get_option( 'woosw_button_class', '' ) !== '' ) {
       							$class .= ' ' . esc_attr( get_option( 'woosw_button_class' ) );
       						}
   
       					}
   
       	 return '<button class="' . esc_attr( $class ) . '" data-id="' . esc_attr( $atts['id'] ) . '" title="' . esc_html( $text ) . '"><i class="icon-heart"></i> <span>' . esc_html( $text ) . '</span></button>';
   
       }
       ```
   

Viewing 1 replies (of 1 total)

 *  Plugin Author [WPClever](https://wordpress.org/support/users/wpclever/)
 * (@wpclever)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/custom-button-html-added-text/#post-14364317)
 * Hi [@adam198](https://wordpress.org/support/users/adam198/)
 * I think you should use the below function to get the wishlist key:
 * `$key = WPCleverWoosw::get_key();`
 * Then you can retrieve correct products in the current wishlist.
 * In case you just want to add the icon and kept other parts, you can use below
   code:
 *     ```
       add_filter( 'woosw_button_html', 'woosw_custom_button_html', 99, 1 );
       function woosw_custom_button_html( $html ) {
       	$html = str_replace( '">', '"><i class="icon-heart"></i> <span>', $html );
       	$html = str_replace( '</button>', '</span></button>', $html );
   
       	return $html;
       }
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Custom button HTML Added Text’ is closed to new replies.

 * ![](https://ps.w.org/woo-smart-wishlist/assets/icon-128x128.png?rev=1857805)
 * [WPC Smart Wishlist for WooCommerce](https://wordpress.org/plugins/woo-smart-wishlist/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woo-smart-wishlist/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woo-smart-wishlist/)
 * [Active Topics](https://wordpress.org/support/plugin/woo-smart-wishlist/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woo-smart-wishlist/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woo-smart-wishlist/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [WPClever](https://wordpress.org/support/users/wpclever/)
 * Last activity: [5 years, 1 month ago](https://wordpress.org/support/topic/custom-button-html-added-text/#post-14364317)
 * Status: not resolved