Created
May 11, 2023 15:59
-
-
Save marcusig/bb35463bf3bf9868fd94929ec556f781 to your computer and use it in GitHub Desktop.
Remove configurable product from the cart, and only keep linked products.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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