Skip to content

Instantly share code, notes, and snippets.

@jmabbas
Created July 19, 2024 18:12
Show Gist options
  • Save jmabbas/bd64c7107e85a2df50c0f8fa4b7a63e9 to your computer and use it in GitHub Desktop.
Save jmabbas/bd64c7107e85a2df50c0f8fa4b7a63e9 to your computer and use it in GitHub Desktop.
Electro arcade custom codes
<?php
/**
* Recommended way to include parent theme styles.
* (Please see http://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme)
*
*/
add_action( 'wp_enqueue_scripts', 'electro_child_style' );
function electro_child_style() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array('parent-style') );
}
/**
* Your code goes below.
*/
function themename_custom_logo_setup() {
$defaults = array(
'height' => 100,
'width' => 400,
'flex-height' => true,
'flex-width' => true,
'header-text' => array( 'site-title', 'site-description' ),
'unlink-homepage-logo' => true,
);
add_theme_support( 'custom-logo', $defaults );
}
add_action( 'after_setup_theme', 'themename_custom_logo_setup' );
add_filter( 'woocommerce_product_tabs', 'woo_custom_product_tabs' );
function woo_custom_product_tabs( $tabs ) {
// phpinfo();die;
$product_id = get_the_id();
$technical_specifications = get_field( "technical_specification",$product_id );
$console_x_technical_specifications = get_field('console_x_technical_specifications',$product_id );
$lego_technical_specifications = get_field('lego_technical_specifications',$product_id );
/* Add New in Woocommerce - Specification Tab */
if(!empty($technical_specifications)){
if(!empty(array_filter(array_map('array_filter', $technical_specifications)))){
$allcar = array("retro-handheld-gaming-consoles", "accessories-upgrades", "mini-pcs");
$primery_cat = get_primary_category( $product_id ,$allcar);
if($primery_cat == true){
$tabs['technical_specifications'] = array(
'title' => __( 'Specification', 'woocommerce' ),
'priority' => 120,
'callback' => 'woo_technical_specifications_products_tab_content'
);
}
}
}else if(!empty($lego_technical_specifications)){
if(!empty(array_filter(array_map('array_filter', $lego_technical_specifications)))){
$allcar = array('Block & Brick sets');
$primery_cat = get_primary_category( $product_id ,$allcar);
if($primery_cat){
$tabs['technical_specifications'] = array(
'title' => __( 'Specification', 'woocommerce' ),
'priority' => 120,
'callback' => 'woo_technical_specifications_products_tab_content'
);
}
}
}elseif(!empty($console_x_technical_specifications)){
if(!empty(array_filter(array_map('array_filter', $console_x_technical_specifications)))){
$allcar = array('Arcade Machines');
$primery_cat = get_primary_category( $product_id ,$allcar);
if($primery_cat){
$tabs['technical_specifications'] = array(
'title' => __( 'Specification', 'woocommerce' ),
'priority' => 120,
'callback' => 'woo_technical_specifications_products_tab_content'
);
}
}
}
return $tabs;
}
/* Callback Function of Specification Tab */
function woo_technical_specifications_products_tab_content(){
echo do_shortcode( '[custom_addition]');
}
/* Callback Function of Video Tab */
function woo_video_products_tab_content(){
$Post_id = get_the_id();
echo get_field('video',$Post_id);
}
/* Remove tab frpm single product page in woocommerce */
add_filter( 'woocommerce_product_tabs', 'remove_product_tabs', 98 );
function remove_product_tabs( $tabs ) {
unset( $tabs['specification'] );
return $tabs;
}
use AIOSEO\Plugin\Common\Standalone\PrimaryTerm as CommonPrimaryTerm;
use AIOSEO\Plugin\Common\Models as CommonModels;
function get_primary_category($product_id , $allcar ) {
global $wpdb;
// Get the table name with the correct prefix
$table_name = $wpdb->prefix . 'aioseo_posts';
// Assuming $postId holds the ID of the post you want to retrieve data for
$postId = $product_id;
// Prepare the SQL query
$query = $wpdb->prepare("SELECT * FROM $table_name WHERE post_id = %d", $postId);
// Execute the query
$results = $wpdb->get_results($query);
$retur = false;
if($results[0]->primary_term == ''){
$retur = true;
}else{
$data = json_decode($results[0]->primary_term, true);
// Access the value associated with the key "product_cat"
$product_cat_value = isset($data['product_cat']) ? $data['product_cat'] : null;
$category = get_term_by('id',$product_cat_value,'product_cat');
$primery_cat = $category->slug;
if(in_array($primery_cat,$allcar)){
$retur = true;
}
}
return $retur;
}
add_shortcode('custom_addition','woo_custom_specification');
function woo_custom_specification(){
$Post_id = get_the_id();
$categories = wp_get_post_terms( $Post_id, 'product_cat' );
$allcat = array();
foreach ( $categories as $category ) {
$allcat[] = $category->name;
}
$field = get_field_object('technical_specification',$Post_id );
$lego_technical_specifications = get_field_object('lego_technical_specifications',$Post_id );
$console_x_technical_specifications = get_field_object('console_x_technical_specifications',$Post_id );
$lego_name = '_'.$lego_technical_specifications['_name'];
$field_name = '_'.$field['_name'];
$console_name = '_'.$console_x_technical_specifications['_name'];
$custom_fildes = get_post_meta($Post_id );
/* lego_technical_specifications */
if(in_array("Block & Brick sets", $allcat) ){
if(!empty(array_filter(array_map('array_filter', $lego_technical_specifications['value'])))){
if(array_key_exists($lego_name,$custom_fildes)){
$legoTechnical_value = $lego_technical_specifications['value'];
$lego_technical_label = $lego_technical_specifications['sub_fields'];
for( $i=0; $i<= count($lego_technical_specifications['sub_fields']); $i++ ){
$array_key = $lego_technical_label[$i]['name'];
$html .= '<div class = "technical_specification" id = "tab-'.$i.'"><h2><span style="color: #0c0d5f;">'.$lego_technical_label[$i]['label'].'</span></h2>';
foreach( $lego_technical_label[$i]['sub_fields'] as $subfield_key => $subfields ){
$key = $subfields['name'];
$html .= '
<table width="100%">
<tr>';
if(!empty($legoTechnical_value[$array_key][$key])){
$html .= '<td style="width: 43.2928%;"><b>'.$subfields['label'].':'.'</b></td>';
}
$html .= '<td style="width: 53.5237%;">'.$legoTechnical_value[$array_key][$key].'</td>
</tr>
</table>';
}
$html .= '</div>';
}
echo $html ;
}
}
}
/* technical_specification */
$allcar = array("Retro Handheld Gaming Consoles", "Accessories & Upgrades", "Mini PC");
if(!empty($field['value'])){
if(!empty(array_filter(array_map('array_filter', $field['value'])))){
if(array_key_exists($field_name,$custom_fildes)){
if($field['key'] == $custom_fildes[$field_name][0]){
$fields_values = $field['value'];
$fields_labels = $field['sub_fields'];
for( $i=0; $i<= count($field['sub_fields']); $i++ ){
$array_key = $fields_labels[$i]['name'];
$html .= '<div class = "technical_specification" id = "tab-'.$i.'"><h2><span style="color: #0c0d5f;">'.$fields_labels[$i]['label'].'</span></h2>';
foreach( $fields_labels[$i]['sub_fields'] as $subfield_key => $subfields ){
$key = $subfields['name'];
$html .= '<table width="100%" >';
$html .= '<tr>';
if(!empty($fields_values[$array_key][$key])){
$html .= '<td style="width: 43.2928%;"><b>'.$subfields['label'].':'.'</b></td>';
}
$html .='<td style="width: 43.2928%;">'.$fields_values[$array_key][$key].'</td>
</tr>';
$html .= '</table>';
}
$html .= '</div>';
}
echo $html;
}
}
}
}
/* console_x_technical_specifications */
if(in_array("Arcade Machines", $allcat) ){
if(!empty(array_filter(array_map('array_filter', $console_x_technical_specifications['value'])))){
if(array_key_exists($console_name,$custom_fildes)){
if($console_x_technical_specifications['key'] == $custom_fildes[$console_name][0] ){
$console_x_values = $console_x_technical_specifications['value'];
$console_x_labels = $console_x_technical_specifications['sub_fields'];
for( $i=0; $i<= count($console_x_technical_specifications['sub_fields']); $i++ ){
$array_key = $console_x_labels[$i]['name'];
$html .= '<div class = "technical_specification" id = "tab-'.$i.'"><h2><span style="color: #0c0d5f;">'.$console_x_labels[$i]['label'].'</span></h2>';
foreach( $console_x_labels[$i]['sub_fields'] as $subfield_key => $subfields ){
$key = $subfields['name'];
$html .= '
<table>
<tr>';
if(!empty($fields_values[$array_key][$key])){
$html .= '<td style="width: 43.2928%;"><b>'.$console_x_values['label'].':'.'</b></td>';
}
$html .= '<td style="width: 43.2928%;">'.$console_x_values[$array_key][$key].'</td>
</tr>
</table>';
}
}
echo $html ;
}
$html .= '</div>';
}
}
}
}
function footer_data(){
?>
<script>
let tr = jQuery('.technical_specification').children('table').children('tbody').children()
jQuery(tr).each(function() {
jQuery.each(this.cells, function(){
if(jQuery(this).text() == ""){
jQuery(this).parent().css("display","none")
console.log(jQuery(this).parent().parent().children().length)
}
});
});
jQuery('.technical_specification').each(function(){
tablecount = jQuery(this).children('table').length;
count=0;
jQuery(this).children('table').each(function(){
if(jQuery(this).children().find('td').text() == ''){
count++;
}
})
if(tablecount == count){
// jQuery(this).children('h2').css('display','none')
console.log(jQuery(this).remove());
}
})
</script>
<?php
}
add_action('wp_footer','footer_data');
add_action( 'init', 'ec_child_star_rating_products_card_carousel', 10 );
function ec_child_star_rating_products_card_carousel() {
add_action( 'electro_product_card_view_body', 'electro_template_loop_rating', 45 );
}
//Single product custom label
function display_regular_price_on_single_product() {
global $product;
if ( ! $product ) {
return;
}
$regular_price = $product->get_regular_price();
echo '<span class="regular-price">' . wc_price( $regular_price ) . '</span>';
}
function display_sale_price_on_single_product() {
global $product;
if ( ! $product ) {
return;
}
$sale_price = $product->get_sale_price();
echo '<span class="sale-price">' . wc_price( $sale_price ) . '</span>';
}
function woocommerce_custom_fields_display() {
global $post;
$product = wc_get_product($post->ID);
$regular_price = $product->get_regular_price();
$sale_price = $product->get_sale_price();
$saving_price = round((($regular_price-$sale_price)/$regular_price)*100); ?>
<div class="top-content">Instand Savings: <?php echo $saving_price;?>%</div><?php
}
function woocommerce_sale_cust_label() {
global $product;
if ( $product->is_on_sale() && ! $product->is_type( 'variable' ) ) {
$regular_price = $product->get_regular_price();
$sale_price = $product->get_sale_price();
$payment_price = $sale_price/4;
?>
<div class="sale-lable-cus" style=" margin-bottom: 20px; ">
<div class="top-label-inner"style="display: flex; align-items: center;">
<div class="sale-label" style="font-size: 35px; color: #7ca02d; font-weight: 700;"><?php echo display_sale_price_on_single_product();?></div>
<div class="regu-top-label" style=" line-height: 1.2; margin-left: 6px; ">
<div class="regu-label" style="text-decoration: line-through; color: #888;display: flex;">WAS:&nbsp;<?php echo display_regular_price_on_single_product();?></div>
<div class="top-label-inner"style=" color: #c16f02; "><?php echo woocommerce_custom_fields_display(); ?></div>
</div>
</div>
<div class="bottom-label-inner">or 4 payments of $<?php echo ($payment_price); ?> with <img src="<?php echo get_site_url(); ?>/wp-content/uploads/2024/05/paypal_icon.jpg" alt=""></div>
</div>
<?php }
}
function ec_child_custom_sale_lable_variation() { ?>
<script type="text/javascript">
jQuery(document).ready(function($) {
function addDiscountInfo() {
var templateUrl = window.location.hostname;
$('.woocommerce-variation-price .price').each(function() {
var $priceContainer = $(this);
var regularPrice = $priceContainer.find('del .woocommerce-Price-amount').text();
var salePrice = $priceContainer.find('ins .woocommerce-Price-amount').text();
var regularPrice1 = $priceContainer.find('del .woocommerce-Price-amount').text();
var salePrice1 = $priceContainer.find('ins .woocommerce-Price-amount').text();
if (regularPrice && salePrice) {
regularPrice = parseFloat(regularPrice.replace(/[^0-9\.]/g, ''));
salePrice = parseFloat(salePrice.replace(/[^0-9\.]/g, ''));
let savings = Math.round(((regularPrice-salePrice)/regularPrice)*100);
let fourpayments = salePrice/4;
if (regularPrice > salePrice) {
var discountText = `<div class="sale-lable-cus" style=" margin-bottom: 20px; font-size:14px;">
<div class="top-label-inner"style="display: flex; align-items: center;">
<div class="sale-label" style="font-size: 35px; color: #7ca02d; font-weight: 700;">${salePrice1}</div>
<div class="regu-top-label" style=" line-height: 1.2; margin-left: 6px; ">
<div class="regu-label" style="text-decoration: line-through; color: #888;display: flex;">WAS: ${regularPrice1}</div>
<div class="top-label-inner"style=" color: #c16f02;">Instant Savings: ${savings}%</div>
</div>
</div>
<div class="bottom-label-inner">or 4 payments of $${fourpayments} with <img src="https://${templateUrl}/wp-content/uploads/2024/05/paypal_icon.jpg" alt=""></div>
</div>`;
$priceContainer.find('.discount-info').remove();
$priceContainer.append(discountText);
setTimeout(function () {
$priceContainer.append(discountText);
}, 3000);
}
}
});
}
addDiscountInfo();
$('form.variations_form').on('show_variation', function() {
addDiscountInfo();
});
$('body').on('woocommerce_update_variation_values', function() {
addDiscountInfo();
});
});
</script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.summary > .price').each(function() {
var templateUrl = window.location.hostname;
var $priceContainer = $(this);
var regularPrice1 = $priceContainer.find('del .woocommerce-Price-amount').text();
var salePrice1 = $priceContainer.find('ins .woocommerce-Price-amount').text();
var regularPrice = $priceContainer.find('del .woocommerce-Price-amount').text();
var salePrice = $priceContainer.find('ins .woocommerce-Price-amount').text();
regularPrice = parseFloat(regularPrice.replace(/[^0-9\.]/g, ''));
salePrice = parseFloat(salePrice.replace(/[^0-9\.]/g, ''));
let savings = Math.round(((regularPrice-salePrice)/regularPrice)*100);
let fourpayments = salePrice/4;
var discountText = `<div class="sale-lable-cus" style=" margin-bottom: 20px; font-size:14px;">
<div class="top-label-inner"style="display: flex; align-items: center;">
<div class="sale-label" style="font-size: 35px; color: #7ca02d; font-weight: 700;">${salePrice1}</div>
<div class="regu-top-label" style=" line-height: 1.2; margin-left: 6px; ">
<div class="regu-label" style="text-decoration: line-through; color: #888;display: flex;">WAS: ${regularPrice1}</div>
<div class="top-label-inner"style=" color: #c16f02;">Instant Savings: ${savings}%</div>
</div>
</div>
<div class="bottom-label-inner">or 4 payments of $${fourpayments} with <img src="https://${templateUrl}/wp-content/uploads/2024/05/paypal_icon.jpg" alt=""></div>
</div>`;
$priceContainer.append(discountText);
});
});
</script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.iconic-wsb-product-bumps__sales_pitch').each(function() {
var templateUrl = this.textContent;
// document.querySelector(".awdr_discount_bar_content").innerHTML = templateUrl;
//console.log(templateUrl);
});
});
</script>
<?php }
add_action( 'wp_head', 'ec_child_custom_sale_lable_variation', 10 );
add_filter('yith_woocompare_filter_table_fields', 'yith_woocompare_customize_filter_table_fields');
if (!function_exists('yith_woocompare_customize_filter_table_fields')) {
function yith_woocompare_customize_filter_table_fields($fields) {
$fields['colours'] = 'Colours';
$fields['technology'] = 'Technology';
$fields['resolution'] = 'Resolution';
$fields['controls'] = 'Controls';
$fields['hdmi'] = 'HDMI';
$fields['wifi'] = 'WiFi';
$fields['bluetooth'] = 'Bluetooth';
$fields['battery'] = 'Battery';
$fields['ram_memory'] = 'RAM';
$fields['product_dimensions'] = 'Console Dimensions';
$fields['jgm-preview-badge'] = 'Rating';
return $fields;
}
}
add_filter('yith_woocompare_value_default_field', 'yith_woocompare_show_value_for_default_field', 10, 3);
if (!function_exists('yith_woocompare_show_value_for_default_field') && function_exists('get_field')) {
function yith_woocompare_show_value_for_default_field($value, $product, $field) {
if ($field === 'colours') {
$value = get_field('technical_specification_Console_colours', $product->get_id());
}
if ($field === 'technology') {
$value = get_field('technical_specification_display_technology', $product->get_id());
}
if ($field === 'resolution') {
$value = get_field('technical_specification_display_resolution', $product->get_id());
}
if ($field === 'controls') {
$value = get_field('technical_specification_io_interface_controls', $product->get_id());
}
if ($field === 'hdmi') {
$value = get_field('technical_specification_io_interface_hdmi', $product->get_id());
}
if ($field === 'wifi') {
$value = get_field('technical_specification_io_interface_wifi', $product->get_id());
}
if ($field === 'bluetooth') {
$value = get_field('technical_specification_io_interface_bluetooth', $product->get_id());
}
if ($field === 'battery') {
$value = get_field('technical_specification_battery_capacity', $product->get_id());
}
if ($field === 'ram_memory') {
$value = get_field('technical_specification_memorystorage_ram_memory', $product->get_id());
}
if ($field === 'product_dimensions') {
$value = get_field('technical_specification_dimension-weight_product_dimensions', $product->get_id());
}
if ($field === 'jgm-preview-badge') {
$body = get_post_meta( $product->get_id(), '_judgeme_widget_preview_badge', true );
if ( ! isset( $body['badge'] ) ) {
$body = array( 'badge' => '' );
}
ob_start();
include JGM_PLUGIN_PATH . 'templates/judgeme/preview-badge-template.php';
$output = ob_get_clean();
$value = $output;
}
return $value;
}
}
add_action( 'wp_head', 'el_child_404_page_font', 10 );
function el_child_404_page_font() {
if ( is_404() ) {
?>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap" rel="stylesheet">
<?php
}
}
if ( ! function_exists( 'yith_woocompare_custom_scripts' ) ) {
function yith_woocompare_custom_scripts() {
$jquery = '
jQuery(document).on( "yith_woocompare_table_updated", function($){
setTimeout(function(){
jQuery( ".dataTables_scrollBody #yith-woocompare-table tbody tr" ).each( function() {
let count_td = 0;
let count_empty = 0;
jQuery( "td", this ).each( function() {
count_td++;
let text = jQuery.trim( jQuery( this ).text() )
if( text == "" || text == "-") {
count_empty++;
}
})
if( count_empty == count_td ) {
let row_empty_class = "tr." + jQuery( this ).attr( "class" ).split(" ")[0];
jQuery( row_empty_class ).remove();
}
});
}, 1000);
});';
wp_add_inline_script( 'yith-woocompare-main', $jquery );
}
add_action( 'wp_enqueue_scripts', 'yith_woocompare_custom_scripts', 99 );
}
/*if ( ! function_exists( 'yith_woocompare_show_value_for_rating_field' ) ) {
function yith_woocompare_show_value_for_rating_field( $value, $product, $field ) {
error_log( 'fielddd: ' . $field );
error_log( 'ttproduct: ' . print_r( $product, true ) );
if ( 'rating' === $field ) {
error_log( "hola" );
error_log( 'ttproduct: ' . print_r( $product, true ) );
$value = "insert your logic here";
}
return $value;
}
add_filter( 'yith_woocompare_value_default_field', 'yith_woocompare_show_value_for_rating_field', 99, 3 );
}*/
// Show all products in shop page.
add_filter( 'electro_loop_shop_per_page', 'ec_child_show_all', 20 );
function ec_child_show_all( $per_page ) {
$per_page = -1;
return $per_page;
}
function woocommerce_product_custom_fields () {
global $woocommerce, $post;
echo '<div class="product_custom_field">';
woocommerce_wp_text_input(
array(
'id' => '_custom_product_text_field2',
'placeholder' => 'Ads Link',
'label' => __('Ads Link', 'woocommerce'),
'desc_tip' => 'true'
)
);
echo '</div>';
}
function woocommerce_product_custom_fields_save($post_id) {
$custom_field_value = isset($_POST['_custom_product_text_field2']) ? sanitize_text_field($_POST['_custom_product_text_field2']) : '';
update_post_meta($post_id, '_custom_product_text_field2', $custom_field_value);
}
if ( ! function_exists( 'ec_child_custom_options_product_genera_data' ) ) {
function ec_child_custom_options_product_genera_data() {
add_action( 'woocommerce_product_options_general_product_data', 'woocommerce_product_custom_fields' );
add_action( 'woocommerce_process_product_meta', 'woocommerce_product_custom_fields_save' );
}
}
add_action( 'init', 'ec_child_custom_options_product_genera_data' );
function woocommerce_custom_fields_display1() {
global $post;
$product = wc_get_product($post->ID);
$custom_content1 = get_post_meta( $post->ID, '_custom_product_text_field2', true );
if($custom_content1) { ?>
<div class="loop-ads-img">
<a href="<?php echo ($custom_content1)?>">
<?php echo electro_template_loop_product_thumbnail(); ?>
</a>
</div>
<?php
}
}
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_custom_fields_display1', 97 );
function add_custom_class_to_woocommerce_product_post_class($classes, $class, $post_id) {
global $post;
$product = wc_get_product($post->ID);
$custom_content = get_post_meta( $post->ID, '_custom_product_text_field2', true );
if ('product' === get_post_type($post_id)) {
if ($custom_content){
$classes[] = 'loop-custom-ads';
} else {
$classes[] = '';
}
}
return $classes;
}
add_filter('post_class', 'add_custom_class_to_woocommerce_product_post_class', 10, 3);
//exclude products in sitemap
function get_products_ids_for_exclude_sitemap() {
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => '_custom_product_text_field2',
'compare' => 'EXISTS'
)
)
);
$query = new WP_Query($args);
$products = array();
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$products[] = get_the_ID();
}
}
wp_reset_postdata();
//print_r($products);
}
add_filter('wpseo_sitemap_entry', 'exclude_product_from_sitemap', 10, 3);
function exclude_product_from_sitemap($url, $type, $post) {
$excluded_product_id = get_products_ids_for_exclude_sitemap();
if ($type == 'post' && $post->ID == $excluded_product_id) {
return false;
}
return $url;
}
// Custom ordering + Published on
add_action('woocommerce_product_query', 'custom_woocommerce_product_order');
function custom_woocommerce_product_order($query) {
if (!is_admin() && $query->is_main_query() && (is_shop() || is_product_category() || is_product_tag())) {
$query->set('orderby', array(
'menu_order' => 'ASC',
'date' => 'DESC'
));
}
}
// Whats include box after product tabs
add_action( 'woocommerce_after_single_product_summary', 'electro_output_product_data_tabs1', 10 );
function electro_output_product_data_tabs1() {
$tabs = apply_filters( 'woocommerce_product_tabs', array() );
if ( ! empty( $tabs ) ) : ?>
<?php
$header = ''; ?>
<div class="include-box">
<?php
$specific_tab_class = isset($_GET['tab_class']) ? sanitize_text_field($_GET['tab_class']) : 'included_tab';
foreach ( $tabs as $key => $tab ) :
$tab_class_name = esc_attr( $key ) . '_tab';
if ( $specific_tab_class === '' || $specific_tab_class === $tab_class_name ) :
?>
<div class="electro-tab" id="tab-<?php echo esc_attr( $key ); ?>">
<div class="container">
<div class="tab-content">
<?php
$search = 'class="' . $tab_class_name . '"';
$replace = 'class="' . $tab_class_name . ' active"';
$n_header = str_replace( $search, $replace, $header );
echo wp_kses_post( $n_header );
call_user_func( $tab['callback'], $key, $tab );
?>
</div>
</div>
</div>
<?php
endif;
endforeach;
if ( $specific_tab_class !== '' && !in_array($specific_tab_class, array_map(function($key) { return esc_attr($key) . '_tab'; }, array_keys($tabs))) ) {
echo '';
}
?>
</div>
<?php endif;
}
//judge.me review tab in single product page
add_filter( 'woocommerce_product_tabs', 'review_product_tab' );
function review_product_tab( $tabs ) {
$tabs['test_tab'] = array(
'title' => __( 'Reviews', 'woocommerce' ),
'priority' => 150,
'callback' => 'review_product_tab_content'
);
return $tabs;
}
function review_product_tab_content() {
echo do_shortcode('[jgm-review-widget]');
}
// add image tag in category description
foreach ( array( 'pre_term_description' ) as $filter ) {
remove_filter( $filter, 'wp_filter_kses' );
if ( ! current_user_can( 'unfiltered_html' ) ) {
add_filter( $filter, 'wp_filter_post_kses' );
}
}
foreach ( array( 'term_description' ) as $filter ) {
remove_filter( $filter, 'wp_kses_data' );
}
function ec_child_iconic_discount() { ?>
<script>
const actualPriceText = document.querySelector('.iconic-wsb-product-bumps__total-price-amount del').innerText;
const discountPriceText = document.querySelector('.iconic-wsb-product-bumps__total-price-amount ins').innerText;
const actualPrice1 = parseFloat(actualPriceText.replace('$', ''));
const discountPrice1 = parseFloat(discountPriceText.replace('$', ''));
const discountValue1 = actualPrice1 - discountPrice1;
const discountPercentage = (discountValue1 / actualPrice1) * 100;
const integerDisc = Math.floor(discountPercentage);
document.addEventListener('DOMContentLoaded', () => {
const accessoriesCheckboxes = document.querySelectorAll('.iconic-wsb-product-bumps__list-item');
accessoriesCheckboxes.forEach(checkbox => {
checkbox.addEventListener('click', () => {
const priceAmountElement = document.querySelector('.iconic-wsb-product-bumps__total-price-amount');
setTimeout(() => {
const containerElement = document.querySelector('.iconic-wsb-product-bumps__total-price-amount');
const getTargetElementValue = () => {
const delElement = containerElement.querySelector('del');
const targetElement = delElement ? delElement : containerElement;
return targetElement.textContent;
};
const callback = function(mutationsList, observer) {
for (let mutation of mutationsList) {
if (mutation.type === 'childList') {
const value = getTargetElementValue();
}
}
};
const observer = new MutationObserver(callback);
const config = { childList: true, subtree: true };
observer.observe(containerElement, config);
const str = getTargetElementValue();
const value = parseFloat(str.replace(/[^0-9.-]+/g, ""));
let textContent = value;
let priceWithoutSymbol = textContent;
let discountValue = priceWithoutSymbol*integerDisc/100;
let discountfinal = priceWithoutSymbol-discountValue;
let discountfinal1 = discountfinal.toString();
let discount = discountfinal1.substring(6,0);
const existingDiscountDiv = document.querySelector('.custom-discount');
if (existingDiscountDiv) {
existingDiscountDiv.remove();
}
const newDivElement = document.createElement('div');
newDivElement.className = 'custom-discount';
newDivElement.innerHTML = `<span class="iconic-wsb-product-bumps__total-price-amount-custom"><ins><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>${discount}</bdi></span></ins> <del><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>${priceWithoutSymbol}</bdi></span></del></span>`;
priceAmountElement.parentNode.insertBefore(newDivElement, priceAmountElement.nextSibling);
}, 3000);
});
});
});
document.addEventListener("click", function() {
setTimeout(() => {
const listItems = document.querySelectorAll('.iconic-wsb-product-bumps__list-item');
const ulElement = document.querySelector('.iconic-wsb-product-bumps__list');
function checkFadedClass() {
let allFaded = true;
for (let i = 1; i < listItems.length; i++) {
if (!listItems[i].classList.contains('iconic-wsb-product-bumps__list-item--faded')) {
allFaded = false;
break;
}
}
if (allFaded) {
ulElement.classList.add('new-class-name');
} else {
ulElement.classList.remove('new-class-name');
}
}
checkFadedClass();
}, 100);
});
const originalPriceElement = document.querySelector('.iconic-wsb-product-bumps__total-price-amount');
const priceElement1 = document.querySelector('.iconic-wsb-product-bumps__total-price-amount del');
let priceText1 = priceElement1.textContent.trim();
let priceWithoutSymbol1 = priceText1.slice(1);
let discountValue = priceWithoutSymbol1*integerDisc/100;
let discountfinal = priceWithoutSymbol1-discountValue;
let discountfinal1 = discountfinal.toString();
let discount = discountfinal1.substring(6,0);
const newDivElement1 = document.createElement('div');
newDivElement1.className = 'custom-discount-1';
newDivElement1.innerHTML = `<span class="iconic-wsb-product-bumps__total-price-amount-custom"><ins><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>${discount}</bdi></span></ins> <del><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>${priceWithoutSymbol1}</bdi></span></del></span>`;
originalPriceElement.parentNode.insertBefore(newDivElement1, originalPriceElement.nextSibling);
</script>
<?php }
add_action( 'wp_footer', 'ec_child_iconic_discount', 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment