Site logo

[Support request] Override Woocommerce cart menu

Home Forums Support [Support request] Override Woocommerce cart menu

Home Forums Support Override Woocommerce cart menu

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1943565
    Thomas

    Hello team,

    I dived into the GP Premium (Woocommerce) today in order to achieve something for SEO purposes.
    I have been able to cloak the link to the cart page on the cart item in menu by hard editing a function in the gp-premium/Woocommerce but I’m aware that the worst thing to do 😅
    Would like to know if it’s possible to override this function in my child-theme so that I would keep the edits if the plugins is updated.
    Also, does GeneratePress manage the html code génération for products archive ? Would like to achieve the same thing on the “add to cart” button on theses pages
    Thanks 🙏🏼

    #1943731
    David
    Staff
    Customer Support

    Hi there,

    the Mini Cart and the Add to Cart buttons all use core Woocommerce functions.
    Depending on what changes you want to make you can probably use Hooks in Woocommerce to change the output.
    For example you can unhook the woocommerce_widget_shopping_cart_button_view_cart and hook in your own custom button:

    add_action( 'woocommerce_widget_shopping_cart_buttons', function(){
        // Remove default cart button
        remove_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_button_view_cart', 10 );
        // Add custom cart callback
        add_action( 'woocommerce_widget_shopping_cart_buttons', 'my_custom_widget_shopping_cart_button_view_cart', 10 );
    
    }, 1 );
    
    // Custom cart callback
    function my_custom_widget_shopping_cart_button_view_cart() {
        // Do your custom cart stuff here
        // Example for reference:
        // $original_link = wc_get_cart_url();
        // $custom_link = home_url( '/cart/?id=1' ); // HERE replacing cart link
        // echo '<a href="' . esc_url( $custom_link ) . '" class="button wc-forward">' . esc_html__( 'View custom cart', 'woocommerce' ) . '</a>';
    }

    For the Add to cart button you could use the woocommerce_loop_add_to_cart_link filter:

    https://github.com/woocommerce/woocommerce/blob/b19500728b4b292562afb65eb3a0c0f50d5859de/templates/loop/add-to-cart.php#L25

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.