add_action( 'wp_enqueue_scripts', 'jwelar_child_enqueue_scripts', PHP_INT_MAX ); function jwelar_child_enqueue_scripts() { // Only run on single product pages if ( ! is_singular( 'product' ) ) { return; } global $post; // 1) Enqueue the JwelAR embed script from your plugin wp_enqueue_script( 'jwelar-api', plugin_dir_url( __FILE__ ) . '../plugins/JwelAR/assets/js/jwelar_api.js', [], // no dependencies '1.0.0', // version true // load in footer ); // 2) Identify the product - use its ID instead of SKU $product = wc_get_product( $post->ID ); $identifier = $product ? $product->get_id() : $post->ID; // 3) Retrieve the AR link from product meta $ar_link = get_post_meta( $post->ID, '_jwlr_ar_link', true ); if ( ! $ar_link ) { // Fallback to the bundled AR widget if no custom link is set $ar_link = plugin_dir_url( __FILE__ ) . '../plugins/JwelAR/assets/ar_widget.html'; } // 4) Prepare inline JavaScript to initialize the Try-On button $inline_js = " document.addEventListener('DOMContentLoaded', function(){ loadTryOnButton({ // psku is just a unique identifier for the AR backend psku: '". esc_js( $identifier ) ."', // company name as registered in your AR service company: 'tigervue', // URL of the AR viewer page arUrl: '". esc_url( $ar_link ) ."', // CSS selector where the button will be inserted prependButton: { class: 'woocommerce-product-gallery' }, // Custom styles for the Try-On button styles: { tryonbutton: { backgroundColor:'white', color:'#7b9dc1', border:'2px solid #7b9dc1', borderRadius:'0px', position:'absolute', zIndex:'22', width:'150px', fontWeight:'600' }, tryonbuttonHover: { backgroundColor:'transparent', color:'#7b9dc1', border:'1px solid #7b9dc1' }, MBtryonbutton: { width:'148px', margin:'-10px 32%', position:'relative', bottom:'24px' } }, // Text and icon for the button tryonButtonData: { text:'Virtual Try On', faIcon:'fa fa-camera' } }); }); "; // 5) Inject the inline script right after the enqueued jwelar-api.js wp_add_inline_script( 'jwelar-api', $inline_js ); }