Woocommerce cart button dynamic tag

<?php
/** creates a dynamic tag for use in the facetwp layout builder - {{ cart }} **/

add_filter( 'facetwp_builder_dynamic_tag_value', function( $tag_value, $tag_name, $params ) {
    if ( 'cart' == $tag_name ) {
        global $product;
        $product = wc_get_product( get_the_ID() );
        ob_start();
        woocommerce_template_loop_add_to_cart();
        $tag_value = ob_get_clean();
    }
    return $tag_value;
  }, 10, 3 );