Skip to content

Instantly share code, notes, and snippets.

@BrianHenryIE
Created July 29, 2022 20:39
Show Gist options
  • Save BrianHenryIE/5cbd2d05e6474bbaa8b0b1c9609b2ce2 to your computer and use it in GitHub Desktop.
Save BrianHenryIE/5cbd2d05e6474bbaa8b0b1c9609b2ce2 to your computer and use it in GitHub Desktop.
Fix for Lootly w/ Oxygen theme
<?
// In themes with do not call the get_footer action, this JavaScript will add the required Div.
$handle = 'lootly-create-div-script';
wp_register_script( $handle, '', array(), '1.2.3', true );
wp_enqueue_script( $handle );
$lootly_customer_id ='';
$lootly_customer_signature = '';
$api_key = lootly()->options->getOption('api_key');
$api_secret = lootly()->options->getOption('api_secret');
$lootly_shop_domain = get_site_url();
$lootly_shop_signature = md5($lootly_shop_domain.$api_secret);
if(get_current_user_id()){
$lootly_customer_id = get_current_user_id();
$lootly_customer_signature = md5($lootly_customer_id.$api_secret);
}
$lootly_div_data = array(
'id' => 'lootly-widget',
'class'=>'lootly-init',
'style' => array(
'display' => 'none'
),
'data' => array(
'provider'=>esc_url(lootly()->api->endpoint),
'api-key' => esc_html($api_key),
'shop-domain' => esc_url($lootly_shop_domain),
'shop-id' => $lootly_shop_signature,
'customer-id' => $lootly_customer_id,
'customer-signature' => $lootly_customer_signature,
)
);
$lootly_div_data_json = wp_json_encode( $lootly_div_data );
$script = <<<EOD
var lootlyDivData = $lootly_div_data_json;
jQuery(document).ready(function($) {
var lootlyDiv = $('<div />').appendTo('body');
lootlyDiv.attr('id', lootlyDivData.id);
lootlyDiv.attr('class', lootlyDivData.class);
lootlyDiv.attr('id', lootlyDivData.id);
for (const key in lootlyDivData.style) {
lootlyDiv.css(key, lootlyDivData.style[key]);
}
for (const key in lootlyDivData.data) {
lootlyDiv.attr('data-'+key, lootlyDivData.data[key]);
}
});
EOD;
wp_add_inline_script($handle, $script );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment