Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcusig/bb35463bf3bf9868fd94929ec556f781 to your computer and use it in GitHub Desktop.
Save marcusig/bb35463bf3bf9868fd94929ec556f781 to your computer and use it in GitHub Desktop.
Remove configurable product from the cart, and only keep linked products.
<?php
// Prevent the linked items to be removed automatically when removing the main product
add_filter( 'mkl_pc/remove_linked_items', '__return_false' );
// Remove the configurable item from the cart, if the linked items were added to the cart.
add_action( 'mkl_pc/added_linked_product_to_the_cart', function( $cart_item_key, $product_id ) {
WC()->cart->remove_cart_item( $cart_item_key );
// Add custom notice
wc_add_notice( '<a href="' . esc_url( wc_get_cart_url() ) . '" class="button wc-forward">' . esc_html__( 'View cart', 'woocommerce' ) . '</a>' . ' Din kjole design er blevet tilføjet til din kurv.' );
// Prevent default notice
throw new Exception();
}, 20, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment