• 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

    (@wpclever)

    Hi @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.