1. Home
  2. Docs
  3. BeatStore WordPress Plugin
  4. Code Snippets

Code Snippets

If you would like to use one of the  code snippets on your Website, we recommend using a Plugin like Code Snippets: https://wordpress.org/plugins/code-snippets/

Hide the audio player on WooCommerce Product Detail Page


/**
* Remove Audio Preview Player on WooCommerce Product Page
*
*/
function remove_audio_player_woosingle() {
    global $beatstore_woo;
    remove_action( 'woocommerce_product_meta_end', array($beatstore_woo,'beatstore_woocommerce_single_product_player') );
}
add_action( 'init', 'remove_audio_player_woosingle' );

 

Allow embedding your player on a different domain. Edit your .htaccess file and add this snippet, AFTER the #End WordPress line.

Header always edit Set-Cookie ^(.*)$ $1;Secure;SameSite=None

 

Communicate between BeatStore Player iFrame and the parent page. In this example we are running a JS function when a cart item is added or removed in the Player.

window.addEventListener('message', (event) => {
    if (event.data.type === 'cartItemAdded' || event.data.type === 'cartItemRemoved') {
        myCustomCartFragments();
    }
});
function myCustomCartFragments() {
    jQuery.ajax({
        type: 'POST',
        url: wc_cart_fragments_params.wc_ajax_url.toString().replace('%%endpoint%%', 'get_refreshed_fragments'),
        data: { _wpnonce: wc_cart_fragments_params.wc_ajax_nonce },
        success: function (data) {
            if ( data && data.fragments ) {
                jQuery.each( data.fragments, function( key, value ) {
                    jQuery( key ).replaceWith( value );
                });
               jQuery( document.body ).trigger( 'wc_fragments_refreshed' );
            }
        },
    });
}

 

Was this article helpful to you? Yes 2 No

How can we help?