Booster Empty Cart + Shoptimizer.

Tags
Created
Nov 4, 2022 7:56 PM
Status
Done

Booster for WooCommerce has an Empty cart option. When enabled it breaks Shoptimizer layout on the cart page. This is the code generated when using the shortcode.

<input type="hidden" id="wcj_empty_cart_nonce" name="wcj_empty_cart_nonce" value="3faf296234" />
<input type="hidden" name="_wp_http_referer" value="/cart/" />
<div style="display:inline"><form action="" method="post">
<input type="submit" class="button" name="wcj_empty_cart" value="Empty Cart">
<input type="hidden" id="wcj_empty_cart_nonce" name="wcj_empty_cart_nonce" value="3faf296234" />
<input type="hidden" name="_wp_http_referer" value="/cart/" />
</form>
</div>

There is no requirement for a <form> tag, since the checkout is a form tag so you can remove the form tag using the following code.

add_action( 'woocommerce_cart_actions', 'on_action_cart_updated', 20, 1 );
function on_action_cart_updated() {
	$bad_html = do_shortcode('[wcj_empty_cart_button]');
    $good_html = str_replace('<form action="" method="post">','',$bad_html);
    $good_html = str_replace('</form>','',$good_html);
    echo $good_html;
}