Home Forums WoodMart support forum change behaveor of the add to cart buttom

change behaveor of the add to cart buttom

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #557387

    av_admin_1984
    Participant

    Hi
    Is it possible to change behavor of the “add to cart” buttom?
    I dont mean to change the text, I want this buttom open the product not added to cart

    #557570

    Hello,

    Define the code below in the functions.php file in your child theme.

    /* Remove add to cart button */
    add_action('woocommerce_before_shop_loop_item','remove_loop_add_to_cart_button'); 
    function remove_loop_add_to_cart_button(){
        global $product; // Current product
        remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); 
    }
    
    /* Add see details button to replace add to cart button*/
    add_action('woocommerce_after_shop_loop_item','replace_add_to_cart_with_view_product'); 
    function replace_add_to_cart_with_view_product() {
        global $product;
        $link = get_permalink(); 
        echo '<a class="button" href="' . esc_attr($link) . '">See Details</a>';
    }

    Best Regards.

    #557617

    av_admin_1984
    Participant

    Excellent
    Thank you for this

    I found this code too from stackoveflow

    what are the differences between them?

    // First, remove AJAX Add to Cart Button
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
    
    // Second, add View Product Button
    add_action( 'woocommerce_after_shop_loop_item', 'shop_view_product_button', 10);
    function shop_view_product_button() {
    global $product;
    $link = $product->get_permalink();
    echo '<a href="' . $link . '" class="button addtocartbutton">نمایش کالا</a>';
    }
    #557730

    Hello,

    The code you found on Stack Overflow achieves the same result as the code I provided. Both replace it with a “View Product” button. The difference lies in the way they’re implemented.

    Best Regards.

    #557982

    av_admin_1984
    Participant

    I will use your code in this case

    close this topic please

    Thanks

    #558051

    Most Welcome!!!.

    I’m so happy to hear you are pleased with the Theme and Support. XTEMOS strives to deliver the best customer experience, and it makes our day to hear we have accomplished that.

    We count ourselves lucky to have you as a customer. You can always reach us at any time. We are always here to help you.

    Thanks for contacting us.
    Have a great day.

    Topic Closed.
    Best Regards.

Viewing 6 posts - 1 through 6 (of 6 total)