• Resolved startechmarketing

    (@startechmarketing)


    I am searching for a way to add a button to all products , maybe near the cart or so if they want to go back to the shop then can easily click it

    I found two pieces of code the 1st displays but does not work when clicked and is no space between the add to cart button and return to shop

    // add the filter 
    add_filter( 'wc_add_to_cart_message_html', 'filter_wc_add_to_cart_message_html', 10, 2 );
    
    add_action( 'woocommerce_after_add_to_cart_button', 'my_function_sample', 10 );
    function my_function_sample() {
      global $product;
      echo '   <button type="button" onclick="https://starpaint.de/shop-products/"> Zum allen Produkte </button> '; 
    }

    the second code did not work at all

    // define the wc_add_to_cart_message_html callback 
    function filter_wc_add_to_cart_message_html( $message, $products ) { 
    
        $prev_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; 
        $message .= sprintf( '<a href="%s" class="button">%s</a>', $prev_url, esc_html__( 'Zurück zum Shop', 'woocommerce' ) );
        return $message; 
    }; 

    can you please help me ? thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter startechmarketing

    (@startechmarketing)

    I found a solution for me that works , because I don’t want to return to a previous page, but to the shop

    add_action( 'woocommerce_after_add_to_cart_button', 'my_function_sample', 10 );
    function my_function_sample() {
        global $product;
        
    	echo "<button type='button' onclick=\"location.\" class='single_add_to_cart_button button alt wdm_enquiry' style='background:rgb(0, 171, 0) none repeat scroll 0% 0%';>Zum Shop</button>";
    
    	 
    }
    Saif

    (@babylon1999)

    Hello @startechmarketing,

    Thank you for sharing your solution with the community!
    I will mark the thread as solved, feel free to create a new one if you have any other questions. :?)

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Back to shop button on all products’ is closed to new replies.