Plugin Directory

Changeset 3450808


Ignore:
Timestamp:
01/31/2026 04:56:48 AM (3 weeks ago)
Author:
silverplugins217
Message:

code updates

Location:
frequently-bought-together-product-for-woocommerce/trunk
Files:
3 added
2 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • frequently-bought-together-product-for-woocommerce/trunk/frequently-bought-together-product-for-woocommmerce.php

    r3262514 r3450808  
    22/**
    33* Plugin Name: Frequently Bought Together Product For Woocommerce
    4 * Description: This plugin allows create Frequently Bought Together Product For Woocommerce  plugin.
     4* Description: This plugin allows create Frequently Bought Together Product For Woocommerce plugin.
    55* Version: 1.2
    66* Copyright: 2023
     7* License: GPL v2 or later
     8* License URI: https://www.gnu.org/licenses/gpl-2.0.html
    79* Text Domain: frequently-bought-together-product-for-woocommmerce
    8 * Domain Path: /languages
    910*/
    1011
     12if ( ! defined( 'ABSPATH' ) ) exit;
    1113
    1214// Define Plugin Dir
     
    3032
    3133/* Fronend file include*/
     34include_once('main/frontend/fbtpfw-common-functions.php');
     35include_once('main/frontend/fbtpfw-ajax-functions.php');
    3236include_once('main/frontend/fbtpfw-front.php');
    3337include_once('main/frontend/fbtpfw-layout-1.php');
     
    3640/* Resources file include*/
    3741include_once('main/resources/fbtpfw-installation-require.php');
    38 include_once('main/resources/fbtpfw-language.php');
    3942include_once('main/resources/fbtpfw-load-js-css.php');
    4043
     
    4548
    4649    $links_array[] = '<a href="https://www.plugin999.com/support/">'. __('Support', 'frequently-bought-together-product-for-woocommmerce') .'</a>';
    47     $links_array[] = '<a href="https://wordpress.org/support/plugin/frequently-bought-together-product-for-woocommerce/reviews/?filter=5">'. __('Rate the plugin ★★★★★', 'frequently-bought-together-product-for-woocommmerce') .'</a>';
     50    $links_array[] = '<a href="https://wordpress.org/support/plugin/frequently-bought-together-product-for-woocommerce/reviews/">'. __('Rate the plugin ★★★★★', 'frequently-bought-together-product-for-woocommmerce') .'</a>';
    4851
    4952    return $links_array;
    50 
    5153}
    5254add_filter( 'plugin_row_meta', 'FBTPFW_support_and_rating_links', 10, 4 );
     55
  • frequently-bought-together-product-for-woocommerce/trunk/includes/css/front-style.css

    r3262514 r3450808  
    109109    z-index: 9999;
    110110}
    111 table.fbtpfw_product_images {
     111/* table.fbtpfw_product_images {
    112112    width: auto;
    113113    display: flex;
    114     flex-direction: column;
     114    flex-direction: column; */
    115115    /*display: inline-block;
    116116    float: left;*/
    117     margin: 0;
     117    /* margin: 0;
    118118    padding: 0;
    119119    border: none;
    120120    overflow: initial;
     121} */
     122.layout2 .fbtpfw_product_images {
     123    display: flex;
     124    flex-wrap: wrap;
     125    align-items: center;
     126    justify-content: left;
     127    width: 100%;
     128    gap: 10px;
     129    margin: 10px 0;
     130}
     131.layout2 .fbtpfw_product_images img {
     132    max-width: 120px;
     133    height: auto;
     134    flex-shrink: 0;
    121135}
    122136form.fbtpfw_product_form {
     
    124138    flex-direction: column;
    125139}
    126 .layout2 .fbtpfw_product_images tr td {
     140/* .layout2 .fbtpfw_product_images tr td {
    127141    border: none;
    128142    position: relative;
     
    130144    text-align: center;
    131145    vertical-align: middle;
    132 }
    133 .layout2 .fbtpfw_product_images td.fbtpfw_img_plus {
     146} */
     147/* .layout2 .fbtpfw_product_images td.fbtpfw_img_plus {
    134148    width: 20px;
    135     text-align: center;
     149    text-align: center; */
    136150   /* padding: 0 10px;*/
     151    /* font-size: 20px;
     152    font-weight: bold;
     153} */
     154 .fbtpfw_product_images .fbtpfw_img_plus {
    137155    font-size: 20px;
    138156    font-weight: bold;
     157    color: #000;
     158    margin: 0 5px;
     159    display: flex;
     160    align-items: center;
     161    justify-content: center;
    139162}
    140163.layout2 table tr {
     
    143166    align-items: center;
    144167}
    145 .layout2 .fbtpfw_product_images td.fbtpfw_img img {
     168/* .layout2 .fbtpfw_product_images td.fbtpfw_img img {
    146169    background-color: #FFF;
    147170    padding: 5px;
     
    149172    width: 130px;
    150173    height: auto;
     174} */
     175/* .layout2 .fbtpfw_product_images .fbtpfw_img img {
     176    background-color: #FFF;
     177    padding: 5px;
     178    margin: 0 auto;
     179    width: 130px;
     180    height: auto;
     181    display: block;
     182} */
     183.fbtpfw_product_images .fbtpfw_img_div {
     184    position: relative;
     185    margin: 0 auto;
    151186}
    152187.layout2 .fbtpfw_img_div {
     
    156191.layout2 .fbtpfw_cart_div {
    157192    width: auto;
    158     margin: 15px 0px 15px 0px;
     193    /* margin: 15px 0px 15px 0px; */
    159194}
    160195.layout2.fbtpfw_main ul {
     
    171206    position: absolute;
    172207    top: -16px;
     208    right: -8px;
     209    z-index: 9999999;
     210    border-radius: 100%;
     211    padding: 2px 2px;
     212    border: 2px solid #eb1818;
     213    display: flex;
     214}
     215.fbtpfw_badge {
     216    text-transform: uppercase;
     217    position: absolute;
     218    top: -14px;
    173219    right: -8px;
    174220    z-index: 9999999;
     
    190236    border-radius: 100%;
    191237    padding-top: 6px;
     238    text-align: center;
    192239}
    193240.layout2 .fbtpfw_badge p {
     
    221268    align-items: center;
    222269}
    223 
    224270
    225271
     
    227273    /******************layout 1****************/
    228274    .layout1 .fbtpfw_each_item {
     275        display: flex;
    229276        align-items: center;
    230         flex-direction: column;
    231         padding: 20px 0;
    232     }
     277        flex-direction: row;   /* keep horizontal layout */
     278        justify-content: space-between;
     279        padding: 10px 0;
     280    }
     281
    233282    .layout1 .fbtpfw_each_item > div {
    234         padding: 5px 0 !important;
     283        padding: 0 5px !important;
    235284        width: auto !important;
    236         flex-basis: 0 !important;
    237         max-width: 100% !important;
    238     }
     285        flex: 1 1 auto !important;
     286        max-width: none !important;
     287    }
     288
    239289    .layout1 .fbtpfw_product_image img {
    240         display: block;
    241         margin: 0 auto;
    242         width: 80px;
    243     }
    244 
    245     .oc_cust_variation .variations {
    246         display: inline-block;
    247         width: 100%;
    248     }
    249     .oc_cust_variation .variation {
    250         margin-bottom: 10px;
     290        width: 50px;   /* smaller image for mobile */
     291        height: auto;
     292        margin: 0;
     293    }
     294
     295    .layout1 .fbtpfw_product_title {
     296        flex: 2;   /* let title take more space */
     297    }
     298
     299    .layout1 .fbtpfw_product_price {
     300        flex: 1;
     301        text-align: right;
    251302    }
    252303    /******************end layout 1****************/
    253304}
     305
     306.fbtpfw_product_images > div {
     307    display: flex;
     308    align-items: center;
     309    justify-content: center;
     310}
  • frequently-bought-together-product-for-woocommerce/trunk/includes/js/backend-script.js

    r3208337 r3450808  
    2121                    if ( data ) {
    2222                        jQuery.each( data, function( index, text ) {
    23                             options.push( { id: text[0], text: text[1], 'price': text[2]} );
     23                            options.push( { id: text[0], text: text[1], 'price': text[2], 'raw_price': text[3]} );
    2424                        });
    2525                    }
     
    4444                var perp = "selected";
    4545            }
    46             jQuery("#sortable").append('<li class="ui-state-default" id="'+value.id+'"><span class="occp-draggble-icon"></span><span class="product-attributes-drop">'+value.text+' ('+ value.price +') </span><div class="occp_qty_box"><input type="hidden" name="occp_drag_ids[]" value="'+value.id+'"><input type="number" name="occp_off_per['+value.id+']" value="'+value.discount+'"><select name="occp_discount_type['+value.id+']"><option value="fixed" '+perp+'>Fixed</option><option value="percentage" '+per+'>Percentage</option></select></div></li>');
     46            let maxValue = (value.discount_type === "percentage") ? 100 : value.raw_price;
     47
     48            let $newLi = jQuery('<li class="ui-state-default" id="'+value.id+'"><span class="occp-draggble-icon"></span><span class="product-attributes-drop">'+value.text+' ('+ value.price +') </span><div class="occp_qty_box"><input type="hidden" name="occp_drag_ids[]" value="'+value.id+'"><input type="number" name="occp_off_per['+value.id+']" value="'+value.discount+'" max="'+maxValue+'" data-price="'+maxValue+'" min="0"><select name="occp_discount_type['+value.id+']"><option value="fixed" '+perp+'>Fixed</option><option value="percentage" '+per+'>Percentage</option></select></div></li>');
     49            console.log('raw Value:', value.raw_price);
     50            jQuery("#sortable").append($newLi);
     51            jQuery(document).trigger('occp_product_added', [$newLi]);
     52            // jQuery("#sortable").append('<li class="ui-state-default" id="'+value.id+'"><span class="occp-draggble-icon"></span><span class="product-attributes-drop">'+value.text+' ('+ value.price +') </span><div class="occp_qty_box"><input type="hidden" name="occp_drag_ids[]" value="'+value.id+'"><input type="number" name="occp_off_per['+value.id+']" value="'+value.discount+'"><select name="occp_discount_type['+value.id+']"><option value="fixed" '+perp+'>Fixed</option><option value="percentage" '+per+'>Percentage</option></select></div></li>');
    4753        });
    4854    });
     
    7581   
    7682    }
     83
     84      // On change of discount type
     85    // jQuery(document).on('change', 'select[name^="occp_discount_type"]', function() {
     86    //     let select = jQuery(this);
     87    //     let box = select.closest('.occp_qty_box');
     88    //     let input = box.find('input[type="number"]');
     89    //  // let max_value = box.find('input[name="occp_max_value"]').val();
     90    //  // let max_value = box.find('input[name="occp_max_value"]').val();
     91    //  let price = input.data('price');
     92
     93    //     if (select.val() === 'percentage') {
     94    //         input.attr('max', 100);
     95    //         if (parseInt(input.val()) > 100) {
     96    //             input.val(100);
     97    //         }
     98    //     } else {
     99    //         input.attr('max', price);
     100    //     }
     101    // });
     102
     103    function occp_updateBox($box){
     104        let $input = $box.find('input[type="number"]');
     105        let $select = $box.find('select[name^="occp_discount_type"]');
     106
     107        if(!$input.length || !$select.length) return;
     108
     109        let price = parseFloat($input.data('price')) || 0;
     110        let type  = $select.val();
     111
     112        if(type === 'percentage'){
     113            $input.attr('max', 100);
     114            if(parseFloat($input.val()) > 100){
     115                $input.val(100);
     116            }
     117        }else{
     118            $input.attr('max', price);
     119            if(parseFloat($input.val()) > price){
     120                $input.val(price);
     121            }
     122        }
     123    }
     124
     125    jQuery(function($){
     126    // init all existing
     127    $('.occp_qty_box').each(function(){
     128        occp_updateBox($(this));
     129    });
     130
     131    // on type change
     132    $(document).on('change', 'select[name^="occp_discount_type"]', function(){
     133        occp_updateBox($(this).closest('.occp_qty_box'));
     134    });
     135
     136    // when adding a new product dynamically
     137    $(document).on('occp_product_added', function(e, $newRow){
     138        // $newRow should be the newly inserted <li> or container
     139        occp_updateBox($newRow.find('.occp_qty_box'));
     140    });
    77141});
     142
     143});
  • frequently-bought-together-product-for-woocommerce/trunk/includes/js/front-script.js

    r3262514 r3450808  
    3939                        var priceForAll = 0;
    4040                        jQuery(".product_check").each(function(index, value) {
    41                             if(jQuery(this).is(":checked")) {
     41                            if(jQuery(this).is(":checked") && !jQuery(this).is(":disabled")) {
    4242                                $price = jQuery(this).attr('price');
    4343                                priceForAll = priceForAll + $price * 1;
     
    7979                    var priceForAll = 0;
    8080                    jQuery(".product_check").each(function(index, value) {
    81                         if(jQuery(this).is(":checked")) {
     81                        if(jQuery(this).is(":checked") && !jQuery(this).is(":disabled")) {
    8282                            $price = jQuery(this).attr('price');
    8383                            priceForAll = priceForAll + $price * 1;
     
    9595    var total_items = jQuery(".product_check:checked").length;
    9696
    97     if(jQuery(".layout").val() == "layout1") {
    98         jQuery(".product .single_add_to_cart_button").html(fbtpfw_OBJECT.add_to_cart_text+"("+total_items+")");
    99     } else {
    100         jQuery(".occp_add_cart_button").val(fbtpfw_OBJECT.add_to_cart_text+"("+total_items+")");
    101     }
    102 
     97    // if(jQuery(".layout").val() == "layout1") {
     98    //  jQuery(".product .single_add_to_cart_button").html(fbtpfw_OBJECT.add_to_cart_text+"("+total_items+")");
     99    // } else {
     100    //  jQuery(".occp_add_cart_button").val(fbtpfw_OBJECT.add_to_cart_text+"("+total_items+")");
     101    // }
     102    //
     103    jQuery(function($){
     104        $(document).on('change', '.product_check', function() {
     105            var total_items = $('.product_check:checked').length;
     106
     107            if (total_items > 0) {
     108                $(".single_add_to_cart_button")
     109                    .html(fbtpfw_OBJECT.add_to_cart_text + " (" + total_items + ")");
     110            } else {
     111                $(".single_add_to_cart_button")
     112                    .html(fbtpfw_OBJECT.add_to_cart_text);
     113            }
     114        });
     115    });
    103116
    104117    jQuery(".product_check").change(function() {
     
    126139
    127140
    128             if(jQuery(this).is(":checked")) {
     141            if(jQuery(this).is(":checked") && !jQuery(this).is(":disabled")) {
    129142                $price = jQuery(this).attr('price');
    130143                priceForAll = priceForAll + $price * 1;
     
    147160
    148161    });
     162   
     163    jQuery(function($){
     164        // Hook on the Add to Cart button click BEFORE WooCommerce AJAX runs
     165        $(document).on('click', '.single_add_to_cart_button', function() {
     166            var form = $(this).closest('form.cart');
     167            var current_prod_id = $(this).val();
     168            var selected = [];
     169
     170            // collect all checked product IDs
     171            jQuery('.product_check:checked').each(function(){
     172                var prod_id = $(this).val();
     173                var prod_price = $(this).attr('price');
     174                selected.push({prod_id: prod_id, prod_price: prod_price, parent_prod_id: current_prod_id});
     175            });
     176
     177            // update hidden fields inside the form
     178            form.find('input[name="fbtpfw_related"]').val(JSON.stringify(selected));
     179            form.find('input[name="fbtpfw_buyall_flag"]').val(selected.length > 0 ? '1' : '0');
     180
     181            console.log("Updated hidden inputs:", {
     182                related: form.find('input[name="fbtpfw_related"]').val(),
     183                flag: form.find('input[name="fbtpfw_buyall_flag"]').val()
     184            });
     185        });
     186    });
     187
     188    function updateButtonLabel() {
     189        var total_items = jQuery('.product_check:checked').length;
     190
     191        if (total_items > 0) {
     192            jQuery(".single_add_to_cart_button")
     193                .html(fbtpfw_OBJECT.add_to_cart_text + " (" + total_items + ")");
     194        } else {
     195            jQuery(".single_add_to_cart_button")
     196                .html(fbtpfw_OBJECT.add_to_cart_text);
     197        }
     198    }
     199
     200    // Run once when the page loads
     201    updateButtonLabel();
     202
     203    // Run every time a checkbox is toggled
     204    jQuery(document).on('change', '.product_check', function() {
     205        updateButtonLabel();
     206    });
     207
     208
     209    // block cart item name append
     210    const waitForBlocks = setInterval(() => {
     211        // Check if blocksCheckout is available
     212        if (window.wc && window.wc.blocksCheckout && window.wc.blocksCheckout.registerCheckoutFilters) {
     213            clearInterval(waitForBlocks); // stop waiting
     214
     215            const { registerCheckoutFilters } = window.wc.blocksCheckout;
     216
     217            registerCheckoutFilters('custom-extension', {
     218                itemName: (defaultValue, extensions, args) => {
     219                    const cartItem = args.cartItem;
     220                   
     221                    var cart_item_content = JSON.parse(fbtpfw_OBJECT.cart_item_content ?? []);
     222                    // console.log('fbtpfw_OBJECT: ', cart_item_content);
     223                   
     224                    if (cart_item_content[cartItem.key]) {
     225                        return `${defaultValue} ${cart_item_content[cartItem.key]}`;
     226                    }
     227                    return defaultValue;
     228                }
     229            });
     230        }
     231    }, 100); // check every 100ms until available
     232
    149233});
     234
     235
  • frequently-bought-together-product-for-woocommerce/trunk/main/backend/fbtpfw-backend.php

    r3262514 r3450808  
    11<?php
     2if ( ! defined( 'ABSPATH' ) ) exit;
     3
    24add_action( 'admin_menu',  'fbtpfw_submenu_page');
    35function fbtpfw_submenu_page() {
    46    add_menu_page('Frequently Bought Together Setting', 'Frequently Bought Together', 'manage_options', 'fbtpfw_custom', 'fbtpfw_callback');
     7}
     8
     9add_action( 'admin_enqueue_scripts', 'fbtpfw_admin_scripts' );
     10
     11function fbtpfw_admin_scripts( $hook ) {
     12    // Load only on your plugin settings page
     13    if ( $hook !== 'toplevel_page_fbtpfw_custom' ) {
     14        return;
     15    }
     16
     17    wp_add_inline_script( 'jquery-core', "
     18        document.addEventListener('DOMContentLoaded', function () {
     19            var layoutSelect = document.getElementById('fbtpfw_comman_layout');
     20            var positionRow  = document.getElementById('position_tr');
     21            if (!layoutSelect || !positionRow) return;
     22
     23            function toggleRow() {
     24                let msg = document.getElementById('noLayoutMsg');
     25                if (layoutSelect.value === 'none') {
     26                    positionRow.style.display = 'none';
     27                    if (!msg) {
     28                        msg = document.createElement('div');
     29                        msg.id = 'noLayoutMsg';
     30                        msg.style.color = '#bc2b2b';
     31                        msg.style.marginTop = '7px';
     32                        msg.innerHTML = 'No layout selected. Use <code>[Woo_Frequently_added isshowbutton=\"no\"]</code> to manually display the section.<br>Set <code>isshowbutton=\"yes\"</code> if you also want an extra Add to Cart button.';
     33                        layoutSelect.parentNode.appendChild(msg);
     34                    } else {
     35                        msg.style.display = 'block';
     36                    }
     37                } else {
     38                    positionRow.style.display = '';
     39                    if (msg) msg.style.display = 'none';
     40                }
     41            }
     42            layoutSelect.addEventListener('change', toggleRow);
     43            toggleRow();
     44        });
     45    ");
    546}
    647
     
    1253        <form method="post">
    1354            <?php wp_nonce_field( 'fbtpfw_meta_save', 'fbtpfw_meta_save_nounce' ); ?>
    14              <?php if(isset($_REQUEST['message'])  && $_REQUEST['message'] == 'success'){ ?>
     55            <?php if(isset($_REQUEST['message'])  && $_REQUEST['message'] == 'success'){ ?>
    1556            <div class="notice notice-success is-dismissible">
    1657                <p><strong>Record updated successfully.</strong></p>
     
    2263                    <p>
    2364                        <a class="button-primary button" title="Support Frequently Bought Together Product" target="_blank" href="https://www.plugin999.com/support/">Support</a>
    24                         <a class="button-primary button" title="Rate Frequently Bought Together Product" target="_blank" href="https://wordpress.org/support/plugin/frequently-bought-together-product-for-woocommerce/reviews/?filter=5">Rate the plugin ★★★★★</a>
     65                        <a class="button-primary button" title="Rate Frequently Bought Together Product" target="_blank" href="https://wordpress.org/support/plugin/frequently-bought-together-product-for-woocommerce/reviews/">Rate the plugin ★★★★★</a>
    2566                    </p>
    2667                </div>
     
    3172                    <div class="inside">
    3273                        <table class="data_table">
    33                              <tbody>
    34                                 <tr>
    35                                     <th>
    36                                         <label>Positions for layout 1</label>
    37                                     </th>
    38                                     <td>
    39                                         <?php $single_pro_positions_l1 = $fbtpfw_comman['single_pro_positions']; ?>
     74                            <tbody>
     75                                <tr>
     76                                    <th>
     77                                        <label>Layout</label>
     78                                    </th>
     79                                    <td>
     80                                        <?php $layout = $fbtpfw_comman['layout']; ?>
     81                                        <select name="fbtpfw_comman[layout]" id="fbtpfw_comman_layout" class="regular-text">
     82                                            <option value="layout1" <?php if($layout == 'layout1'){echo "selected";}?>>Layout 1</option>
     83                                            <option value="layout2" <?php if($layout == 'layout2'){echo "selected";}?> disabled>Layout 2</option>
     84                                            <option value="none" <?php if($layout == 'none'){echo "selected";}?> disabled>None</option>
     85                                        </select>
     86                                        <label class="fbtpfw_common_link">This option is only available in <a href="https://www.plugin999.com/plugin/frequently-bought-together-product-for-woocommerce/" target="_blank">pro version</a></label>
     87                                    </td>
     88                                </tr>
     89                                <tr id="position_tr">
     90                                    <th>
     91                                        <label>Positions for layout</label>
     92                                    </th>
     93                                    <td id="position_td">
     94                                        <?php $single_pro_positions = $fbtpfw_comman['single_pro_positions']; ?>
    4095                                        <select name="fbtpfw_comman[single_pro_positions]" class="regular-text">
    41                                             <option value="before_adtcart" <?php if($single_pro_positions_l1 == 'before_adtcart'){echo "selected";}?>>Before add to cart</option>
    42                                             <option value="after_adtcart" <?php if($single_pro_positions_l1 == 'after_adtcart'){echo "selected";}?>>After add to cart</option>
     96                                            <!-- <option value="before_title" <?php //if($single_pro_positions == 'before_title'){echo "selected";}?>>Before Title</option> -->
     97                                            <option value="before_atc" <?php if($single_pro_positions == 'before_atc'){echo "selected";}?>>Before add to cart</option>
     98                                            <option value="after_atc" <?php if($single_pro_positions == 'after_atc'){echo "selected";}?> disabled>After add to cart</option>
     99                                            <!-- <option value="after_summary" <?php //if($single_pro_positions == 'after_summary'){echo "selected";}?>>After Summary</option> -->
    43100                                        </select>
    44                                     </td>
    45                                 </tr>
    46                                 <tr>
    47                                     <th>
    48                                         <label>Positions for layout 2</label>
    49                                     </th>
    50                                     <td>
    51                                         <?php $single_pro_positionsl2 = $fbtpfw_comman['single_pro_positionsl2']; ?>
    52                                         <select name="fbtpfw_comman[single_pro_positionsl2]" class="regular-text">
    53                                             <option value="before_title" <?php if($single_pro_positionsl2 == 'before_title'){echo "selected";}?>>Before Title</option>
    54                                             <option value="before_atc" <?php if($single_pro_positionsl2 == 'before_atc'){echo "selected";}?>>Before add to cart</option>
    55                                             <option value="after_atc" <?php if($single_pro_positionsl2 == 'after_atc'){echo "selected";}?>>After add to cart</option>
    56                                             <option value="after_summary" <?php if($single_pro_positionsl2 == 'after_summary'){echo "selected";}?>>After Summary</option>
    57                                         </select>
     101                                        <label class="fbtpfw_common_link">This option is only available in <a href="https://www.plugin999.com/plugin/frequently-bought-together-product-for-woocommerce/" target="_blank">pro version</a></label>
     102                                    </td>
     103                                </tr>
     104                                <tr>
     105                                    <th>
     106                                        <label>Associated Text</label>
     107                                    </th>
     108                                    <td>
     109                                        <?php $Associated_text = $fbtpfw_comman['Associated_text']; ?>
     110                                        <input type="text" class="ocwg_elimsg regular-text" name="fbtpfw_comman[Associated_text]" value="<?php echo esc_attr($Associated_text); ?>" readonly>
     111                                        <label class="fbtpfw_common_link">This option is only available in <a href="https://www.plugin999.com/plugin/frequently-bought-together-product-for-woocommerce/" target="_blank">pro version</a></label>
     112                                    </td>
     113                                </tr>
     114                                <tr>
     115                                    <th>
     116                                        <label>Heading Text</label>
     117                                    </th>
     118                                    <td>
     119                                        <?php $Heading_text = $fbtpfw_comman['Heading_text']; ?>
     120                                        <input type="text" class="ocwg_elimsg regular-text" name="fbtpfw_comman[Heading_text]" value="<?php echo esc_attr($Heading_text); ?>" readonly>
     121                                        <label class="fbtpfw_common_link">This option is only available in <a href="https://www.plugin999.com/plugin/frequently-bought-together-product-for-woocommerce/" target="_blank">pro version</a></label>
    58122                                    </td>
    59123                                </tr>
     
    66130                                        <select name="fbtpfw_comman[default_products]" class="regular-text">
    67131                                            <option value="none" <?php if($default_products == 'none'){echo "selected";}?>>None</option>
    68                                             <option value="upsells" <?php if($default_products == 'upsells'){echo "selected";}?>>Upsells products</option>
    69                                             <option value="related" <?php if($default_products == 'related'){echo "selected";}?>>Related products</option>
     132                                            <option value="upsells" <?php if($default_products == 'upsells'){echo "selected";}?> disabled>Upsells products</option>
     133                                            <option value="related" <?php if($default_products == 'related'){echo "selected";}?> disabled>Related products</option>
    70134                                        </select>
    71                                     </td>
    72                                 </tr>
     135                                        <label class="fbtpfw_common_link">This option is only available in <a href="https://www.plugin999.com/plugin/frequently-bought-together-product-for-woocommerce/" target="_blank">pro version</a></label>
     136                                    </td>
     137                                </tr>
     138                                <tr>
    73139                                    <th>
    74140                                        <label>Check products default</label>
     
    123189                                    </th>
    124190                                    <td>
    125                                         <?php $fbtpfw_product_color = $fbtpfw_comman['fbtpfw_product_color'];
    126                                             /*if(!empty($fbtpfw_comman['fbtpfw_product_color'])){
    127                                                 $fbtpfw_product_color = '#000000';
    128                                             }else{
    129                                                 $fbtpfw_product_color = '';
    130                                             }*/
    131                                         ?>
     191                                        <?php $fbtpfw_product_color = $fbtpfw_comman['fbtpfw_product_color']; ?>
    132192                                        <input type="text" class="color-picker" data-alpha="true" data-default-color="#000000" name="fbtpfw_comman[fbtpfw_product_color]" value="<?php echo esc_attr($fbtpfw_product_color); ?>"/>
    133193                                    </td>
     
    138198                                    </th>
    139199                                    <td>
    140                                         <?php $price_all_text_color = $fbtpfw_comman['price_all_text_color']; 
    141                                             /*if(!empty($fbtpfw_comman['price_all_text_color'])){
    142                                                 $price_all_text_color = '#000000';
    143                                             }else{
    144                                                 $price_all_text_color = '';
    145                                             }*/
    146                                         ?>
     200                                        <?php $price_all_text_color = $fbtpfw_comman['price_all_text_color']; ?>
    147201                                        <input type="text" class="color-picker" data-alpha="true" data-default-color="#000000" name="fbtpfw_comman[price_all_text_color]" value="<?php echo esc_attr($price_all_text_color); ?>"/>
    148202                                    </td>
     
    153207                                    </th>
    154208                                    <td>
    155                                         <?php $addtional_amount_text_color = $fbtpfw_comman['addtional_amount_text_color'];   
    156                                             /*if(!empty($fbtpfw_comman['addtional_amount_text_color'])){
    157                                                 $addtional_amount_text_color = '#000000';
    158                                             }else{
    159                                                 $addtional_amount_text_color = '';
    160                                             }*/
    161                                         ?>
     209                                        <?php $addtional_amount_text_color = $fbtpfw_comman['addtional_amount_text_color']; ?>
    162210                                        <input type="text" class="color-picker" data-alpha="true" data-default-color="#000000" name="fbtpfw_comman[addtional_amount_text_color]" value="<?php echo esc_attr($addtional_amount_text_color); ?>"/>
    163211                                    </td>
     
    165213                                <tr>
    166214                                    <th>
    167                                         <label>Add to cart background color</label>
    168                                     </th>
    169                                     <td>
    170                                         <?php $add_cart_back_color = $fbtpfw_comman['add_cart_back_color'];
    171                                             /*if(!empty($fbtpfw_comman['add_cart_back_color'])){
    172                                                 $add_cart_back_color = '#000000';
    173                                             }else{
    174                                                 $add_cart_back_color = '';
    175                                             }*/
    176                                         ?>
    177                                         <?php $add_cart_back_color = $fbtpfw_comman['add_cart_back_color']; ?>
    178                                         <input type="text" class="color-picker" data-alpha="true" data-default-color="#000000" name="fbtpfw_comman[add_cart_back_color]" value="<?php echo esc_attr($add_cart_back_color); ?>"/>
    179                                     </td>
    180                                 </tr>
    181                                 <tr>
    182                                     <th>
    183                                         <label>Add to cart text color</label>
    184                                     </th>
    185                                     <td>
    186                                         <?php $add_cart_text_color = $fbtpfw_comman['add_cart_text_color'];
    187                                             /*if(!empty($fbtpfw_comman['add_cart_text_color'])){
    188                                                 $add_cart_text_color = '#ffffff';
    189                                             }else{
    190                                                 $add_cart_text_color = '';
    191                                             }*/
    192                                         ?>
    193                                         <?php $add_cart_text_color = $fbtpfw_comman['add_cart_text_color']; ?>
    194                                         <input type="text" class="color-picker" data-alpha="true" data-default-color="#ffffff" name="fbtpfw_comman[add_cart_text_color]" value="<?php echo esc_attr($add_cart_text_color); ?>"/>
    195                                     </td>
    196                                 </tr>
    197                                 <tr>
    198                                     <th>
    199215                                        <label>Discount Badge text color</label>
    200216                                    </th>
    201217                                    <td>
    202                                         <?php $discount_badge_text_color = $fbtpfw_comman['discount_badge_text_color'];
    203                                         /*if(!empty($fbtpfw_comman['discount_badge_text_color'])){
    204                                                 $discount_badge_text_color = '#ffffff';
    205                                             }else{
    206                                                 $discount_badge_text_color = '';
    207                                             }*/
    208                                         ?>
     218                                        <?php $discount_badge_text_color = $fbtpfw_comman['discount_badge_text_color']; ?>
    209219                                        <input type="text" class="color-picker" data-alpha="true" data-default-color="#ffffff" name="fbtpfw_comman[discount_badge_text_color]" value="<?php echo esc_attr($discount_badge_text_color); ?>"/>
    210220                                    </td>
     
    215225                                    </th>
    216226                                    <td>
    217                                         <?php $discount_badge_back_color = $fbtpfw_comman['discount_badge_back_color'];
    218                                         /*if(!empty($fbtpfw_comman['discount_badge_back_color'])){
    219                                                 $discount_badge_back_color = '#ff0000';
    220                                             }else{
    221                                                 $discount_badge_back_color = '';
    222                                             }*/
    223                                         ?>
     227                                        <?php $discount_badge_back_color = $fbtpfw_comman['discount_badge_back_color']; ?>
    224228                                        <input type="text" class="color-picker" data-alpha="true" data-default-color="#ff0000" name="fbtpfw_comman[discount_badge_back_color]" value="<?php echo esc_attr($discount_badge_back_color); ?>"/>
    225229                                    </td>
     
    230234                                    </th>
    231235                                    <td>
    232                                         <?php $regular_price_color = $fbtpfw_comman['regular_price_color'];
    233                                         /*if(!empty($fbtpfw_comman['regular_price_color'])){
    234                                                 $regular_price_color = '#000000';
    235                                             }else{
    236                                                 $regular_price_color = '';
    237                                             }*/
    238                                         ?>
     236                                        <?php $regular_price_color = $fbtpfw_comman['regular_price_color']; ?>
    239237                                        <input type="text" class="color-picker" data-alpha="true" data-default-color="#000000" name="fbtpfw_comman[regular_price_color]" value="<?php echo esc_attr($regular_price_color); ?>"/>
    240238                                    </td>
     
    265263            } else {
    266264
    267                
    268                     foreach ($_REQUEST['fbtpfw_comman'] as $key_fbtpfw_comman => $value_fbtpfw_comman) {
    269                       update_option($key_fbtpfw_comman, sanitize_text_field($value_fbtpfw_comman), 'yes');
    270                     }   
    271 
    272                     wp_redirect( admin_url( '/admin.php?page=fbtpfw_custom' ) );
    273                     exit;
    274                    // }
    275 
    276                 // $default_products = sanitize_text_field( $_REQUEST['default_products'] );
    277                 // update_option('default_products', $default_products, 'yes');
    278 
    279                 // $check_default_pro = sanitize_text_field( $_REQUEST['check_default_pro'] );
    280                 // update_option('check_default_pro', $check_default_pro, 'yes');
    281                
    282                 // $single_pro_positions = sanitize_text_field( $_REQUEST['single_pro_positions'] );
    283                 // update_option('single_pro_positions', $single_pro_positions, 'yes');
    284 
    285                 // $single_pro_positionsl2 = sanitize_text_field( $_REQUEST['single_pro_positionsl2'] );
    286                 // update_option('single_pro_positionsl2', $single_pro_positionsl2, 'yes');
    287 
    288                 // $add_to_cart_text = sanitize_text_field( $_REQUEST['add_to_cart_text'] );
    289                 // update_option('add_to_cart_text', $add_to_cart_text, 'yes');
    290 
    291                 // $price_for_all_text = sanitize_text_field( $_REQUEST['price_for_all_text'] );
    292                 // update_option('price_for_all_text', $price_for_all_text, 'yes');
    293 
    294                 // $addtional_amount_text = sanitize_text_field( $_REQUEST['addtional_amount_text'] );
    295                 // update_option('addtional_amount_text', $addtional_amount_text, 'yes');
    296 
    297                 // $this_item_text = sanitize_text_field( $_REQUEST['this_item_text'] );
    298                 // update_option('this_item_text', $this_item_text, 'yes');
    299 
    300                 // $fbtpfw_product_color = sanitize_text_field( $_REQUEST['fbtpfw_product_color'] );
    301                 // update_option('fbtpfw_product_color', $fbtpfw_product_color, 'yes');
    302 
    303                 // $addtional_amount_text_color = sanitize_text_field( $_REQUEST['addtional_amount_text_color'] );
    304                 // update_option('addtional_amount_text_color', $addtional_amount_text_color, 'yes');
    305 
    306                 // $add_cart_back_color = sanitize_text_field( $_REQUEST['add_cart_back_color'] );
    307                 // update_option('add_cart_back_color', $add_cart_back_color, 'yes');
    308 
    309                 // $add_cart_text_color = sanitize_text_field( $_REQUEST['add_cart_text_color'] );
    310                 // update_option('add_cart_text_color', $add_cart_text_color, 'yes');
    311 
    312                 // $price_all_text_color = sanitize_text_field( $_REQUEST['price_all_text_color'] );
    313                 // update_option('price_all_text_color', $price_all_text_color, 'yes');
    314 
    315                 // $discount_badge_back_color = sanitize_text_field( $_REQUEST['discount_badge_back_color'] );
    316                 // update_option('discount_badge_back_color', $discount_badge_back_color, 'yes');
    317 
    318                 // $discount_badge_text_color = sanitize_text_field( $_REQUEST['discount_badge_text_color'] );
    319                 // update_option('discount_badge_text_color', $discount_badge_text_color, 'yes');
    320 
    321                 // $regular_price_color = sanitize_text_field( $_REQUEST['regular_price_color'] );
    322                 // update_option('regular_price_color', $regular_price_color, 'yes');
     265                foreach ($_REQUEST['fbtpfw_comman'] as $key_fbtpfw_comman => $value_fbtpfw_comman) {
     266                  update_option($key_fbtpfw_comman, sanitize_text_field($value_fbtpfw_comman), 'yes');
     267                }   
     268
     269                wp_redirect( admin_url( '/admin.php?page=fbtpfw_custom' ) );
     270                exit;
    323271               
    324272            }
     
    369317                ?>
    370318                <label>Add Product</label>
    371                 <select id="occp_select_serach_box" name="occp_select2[]" multiple="multiple" style="width:70%;max-width:25em;" except="<?php echo $to_exclude[0]; ?>">
     319                <select id="occp_select_serach_box" name="occp_select2[]" multiple="multiple" style="width:70%;max-width:25em;" except="<?php echo esc_attr($to_exclude[0]); ?>">
    372320                    <?php
    373 
    374321                        $product = get_post_meta( get_the_ID(), 'occp_select2', true );
    375322                       
     
    378325
    379326                        if (is_array($product) || is_object($product)){
    380                         foreach ($product as $productId) {
    381                             $product = wc_get_product( $productId );
    382                            
    383                             $occp_add_current_product_title = $product->get_title();
    384                             $occp_add_current_product_id = $product->get_id();
    385                             $occp_add_current_product_price = $product->get_price();
    386                             $occp_add_current_product_is_variation   = $product->is_type( 'variation' );
    387                             $occp_add_current_product_real_title = $occp_add_current_product_title;
     327                            foreach ($product as $productId) {
     328                                $product = wc_get_product( $productId );
     329                               
     330                                $occp_add_current_product_title = $product->get_title();
     331                                $occp_add_current_product_id = $product->get_id();
     332                                $occp_add_current_product_price = $product->get_price();
     333                                $occp_add_current_product_is_variation   = $product->is_type( 'variation' );
     334                                $occp_add_current_product_real_title = $occp_add_current_product_title;
    388335
    389336                                if( $occp_add_current_product_is_variation ) {
     
    399346                                }
    400347
    401                             $occp_add_current_product_discunt = get_post_meta( get_the_ID(), 'occp_off_per', true );
    402                             $occp_add_current_product_discunt_type = get_post_meta( get_the_ID(), 'occp_discount_type', true );
    403 
    404 
    405                             $occp_selected_product_ids[] = $occp_add_current_product_id;
    406                             $occp_selected_product_array[] = array(
    407                                 'id'=>$occp_add_current_product_id,
    408                                 'text'=>$occp_add_current_product_real_title,
    409                                 'price'=>wc_price($occp_add_current_product_price),
    410                                 'discount'=>$occp_add_current_product_discunt[$occp_add_current_product_id],
    411                                 'discount_type'=>$occp_add_current_product_discunt_type[$occp_add_current_product_id]
    412                             );
    413                            
     348                                $occp_add_current_product_discunt = get_post_meta( get_the_ID(), 'occp_off_per', true );
     349                                $occp_add_current_product_discunt_type = get_post_meta( get_the_ID(), 'occp_discount_type', true );
     350
     351                                $occp_selected_product_ids[] = $occp_add_current_product_id;
     352                                $occp_selected_product_array[] = array(
     353                                    'id'=>$occp_add_current_product_id,
     354                                    'text'=>$occp_add_current_product_real_title,
     355                                    'price'=>wc_price($occp_add_current_product_price),
     356                                    'raw_price' => $occp_add_current_product_price,
     357                                    'discount'=>$occp_add_current_product_discunt[$occp_add_current_product_id],
     358                                    'discount_type'=>$occp_add_current_product_discunt_type[$occp_add_current_product_id]
     359                                );
     360                            }
    414361                        }
    415                         }
    416 
    417362                    ?>
    418363                </select>
     
    441386                                    $occp_drag_current_product_discunt = get_post_meta( get_the_ID(), 'occp_off_per', true );
    442387                                    $occp_drag_current_product_discunt_type = get_post_meta( get_the_ID(), 'occp_discount_type', true );
    443 
    444388                                    ?>
    445389                                    <li class="ui-state-default" id="<?php echo esc_attr($occp_drag_current_product_id); ?>">
    446390                                        <span class="occp-draggble-icon"></span>
    447391                                        <span class="product-attributes-drop">
    448                                             <?php echo esc_attr($occp_drag_current_product_title) ;                         
     392                                            <?php
     393                                                echo esc_attr($occp_drag_current_product_title) ;                         
    449394                                                if( $occp_drag_current_product_is_variation ) {
    450395                                                    $attributes = $product->get_variation_attributes();
     
    458403                                                    echo ' &ndash; ' . esc_attr(implode( ', ', $variations )) ;
    459404                                                }
    460                                             echo ' (' . wc_price($occp_drag_current_product_price) .')';
     405                                                echo wp_kses_post( ' (' . wc_price( $occp_drag_current_product_price ) . ')' );
    461406                                            ?>
    462407                                        </span>
    463408                                        <div class="occp_qty_box">
     409                                            <?php
     410                                            $max_value = $occp_drag_current_product_price;
     411                                            if(!empty($occp_drag_current_product_discunt_type)){
     412                                                foreach($occp_drag_current_product_discunt_type as $key => $val){
     413                                                    if($key == $occp_drag_current_product_id && $val == "percentage"){
     414                                                        $max_value = 100;
     415                                                    }
     416                                                }
     417                                            }
     418                                            ?>
    464419                                            <input type="hidden" name="occp_drag_ids[]" value="<?php echo esc_attr($occp_drag_current_product_id); ?>">
    465                                             <input type="number" name="occp_off_per[<?php echo $occp_drag_current_product_id ?>]" value="<?php foreach($occp_drag_current_product_discunt as $key => $val){ if($key == $occp_drag_current_product_id){ echo $val; } } ?>" max="<?php echo esc_attr($occp_drag_current_product_price); ?>">
    466                                             <select name="occp_discount_type[<?php echo $occp_drag_current_product_id ?>]">
    467                                                 <option value="fixed" <?php if(!empty($occp_drag_current_product_discunt_type)){foreach($occp_drag_current_product_discunt_type as $key => $val){ if($key == $occp_drag_current_product_id && $val == "fixed"){ echo "selected"; } } }?>>
     420                                            <!-- <input type="hidden" id="occp_max_value" name="occp_max_value" value="<?php // echo esc_attr($max_value); ?>"> -->
     421                                            <input type="number"
     422                                                name="occp_off_per[<?php echo esc_attr($occp_drag_current_product_id) ?>]" value="<?php foreach($occp_drag_current_product_discunt as $key => $val){ if($key == $occp_drag_current_product_id){ echo esc_attr($val); } } ?>" max="<?php echo esc_attr($max_value); ?>"
     423                                                min="0"
     424                                                data-price="<?php echo esc_attr($occp_drag_current_product_price); ?>">
     425                                            <select name="occp_discount_type[<?php echo esc_attr($occp_drag_current_product_id) ?>]">
     426                                                <option value="fixed" <?php if(!empty($occp_drag_current_product_discunt_type)){foreach($occp_drag_current_product_discunt_type as $key => $val){ if($key == $occp_drag_current_product_id && $val == "fixed"){ echo "selected"; } } } ?> >
    468427                                                    Fixed
    469428                                                </option>
    470                                                 <option value="percentage" <?php if(!empty($occp_drag_current_product_discunt_type)){foreach($occp_drag_current_product_discunt_type as $key => $val){ if($key == $occp_drag_current_product_id && $val == "percentage"){ echo "selected"; } } } ?>>
     429                                                <option value="percentage" <?php if(!empty($occp_drag_current_product_discunt_type)){foreach($occp_drag_current_product_discunt_type as $key => $val){ if($key == $occp_drag_current_product_id && $val == "percentage"){ echo "selected"; } } } ?> >
    471430                                                    Percentage
    472431                                                </option>
     
    481440                </div>
    482441            </div>
    483             <p class='form-field'>
    484                 <label>Layout</label>
    485                 <input type="radio" name="rdlayout" value="layout1" <?php if(get_post_meta( get_the_ID(), 'occp_layout', true ) == "layout1"){ echo "checked"; } ?>>   Layout1
    486                 <input type="radio" name="rdlayout" value="layout2" <?php if(get_post_meta( get_the_ID(), 'occp_layout', true ) == "layout2" || empty(get_post_meta( get_the_ID(), 'occp_layout', true ))){ echo "checked"; } ?>>   Layout2
    487                 <input type="radio" name="rdlayout" value="none" <?php if(get_post_meta( get_the_ID(), 'occp_layout', true ) == "none"){ echo "checked"; } ?>>   None <strong>None Stand for </strong>not showing any layout if you want to  use custom place on product page it than you can use <strong>[Woo_Frequently_added]</strong><?php echo __(' this shortcode)','frequently-bought-together-product-for-woocommmerce');?>
    488             </p>
    489442            <p class='form-field width_div' style="display: none;">
    490443                <label>Block Width</label>
    491444                <input type="number" name="occp_block_width" value="<?php if(!empty(get_post_meta( get_the_ID(), 'occp_block_width', true ))){ echo esc_attr(get_post_meta( get_the_ID(), 'occp_block_width', true )); }  ?>">
    492445            </p>
    493             <p class='form-field'>
     446            <!-- <p class='form-field'>
    494447                <label>Associated Text</label>
    495                 <input type="text" name="occp_btassociated_txt" value="<?php if(!empty(get_post_meta( get_the_ID(), 'occp_btassociated_txt', true ))){ echo esc_attr(get_post_meta( get_the_ID(), 'occp_btassociated_txt', true )); } else { echo '(bought together %s)'; }  ?>">
     448                <input type="text" name="occp_btassociated_txt" value="<?php //if(!empty(get_post_meta( get_the_ID(), 'occp_btassociated_txt', true ))){ echo esc_attr(get_post_meta( get_the_ID(), 'occp_btassociated_txt', true )); } else { echo '(bought together %s)'; }  ?>">
    496449                <span class="description">Additional text in title for additional bought together products. Use "%s" for the main product name.</span>
    497             </p>
    498             <p class='form-field'>
     450            </p> -->
     451            <!-- <p class='form-field'>
    499452                <label>Heading Text</label>
    500                 <input type="text" name="occp_head_txt" value="<?php if(!empty(get_post_meta( get_the_ID(), 'occp_head_txt', true ))){ echo esc_attr(get_post_meta( get_the_ID(), 'occp_head_txt', true )); }  ?>">
    501             </p>
     453                <input type="text" name="occp_head_txt" value="<?php //if(!empty(get_post_meta( get_the_ID(), 'occp_head_txt', true ))){ echo esc_attr(get_post_meta( get_the_ID(), 'occp_head_txt', true )); }  ?>">
     454            </p> -->
    502455        </div>
    503456    </div>
     
    539492                    $title = $search_results->post->post_title;
    540493                    $price = $productc->get_price_html();
    541                     $return[] = array( $search_results->post->ID, $title, $price);
     494                    $raw_price = $productc->get_price();
     495                    $return[] = array( $search_results->post->ID, $title, $price, $raw_price);
    542496                }
    543497            }
     
    569523    }
    570524
    571     $fbtflayout = sanitize_text_field( $_POST['rdlayout'] );
     525    /*$fbtflayout = sanitize_text_field( $_POST['rdlayout'] );
    572526    update_post_meta( $post_id, 'occp_layout', $fbtflayout );
    573527
     
    579533
    580534    $fbtfhead = sanitize_text_field( $_POST['occp_head_txt'] );
    581     update_post_meta( $post_id, 'occp_head_txt', $fbtfhead );
     535    update_post_meta( $post_id, 'occp_head_txt', $fbtfhead );*/
    582536
    583537    if(isset($_REQUEST['occp_off_per'])) {
  • frequently-bought-together-product-for-woocommerce/trunk/main/backend/fbtpfw-comman.php

    r3262514 r3450808  
    1010   
    1111    $optionget = array(
    12         'single_pro_positions' => 'before_adtcart',
    13         'single_pro_positionsl2' => 'after_summary',
     12        'layout' => 'layout1',
     13        'single_pro_positions' => 'before_atc',
     14        // 'single_pro_positionsl2' => 'after_summary',
     15        'Associated_text' => '(bought together %s)',
     16        'Heading_text' => 'Frequently Bought Together',
    1417        'default_products' => 'none',
    1518        'check_default_pro' => 'yes',
  • frequently-bought-together-product-for-woocommerce/trunk/main/frontend/fbtpfw-front.php

    r3262514 r3450808  
    11<?php
     2if ( ! defined( 'ABSPATH' ) ) exit;
     3
    24function fbtpfw_localization( $key = '', $default = '' ) {
    35    $str = '';
     
    1315}
    1416
    15 add_action('wp_ajax_variation_switch_cus', 'fbtpfw_variation_switch_cus' );
    16 add_action('wp_ajax_nopriv_variation_switch_cus', 'fbtpfw_variation_switch_cus');
    17 function fbtpfw_variation_switch_cus(){
    18     if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'fbtpfw_ajax_nonce' ) ) {
    19         wp_die( 'Security check failed. Nonce is invalid.' );
    20     }
    21 
     17// add to cart text
     18add_filter( 'woocommerce_product_add_to_cart_text', 'oc_change_add_to_cart_text' );
     19add_filter( 'woocommerce_product_single_add_to_cart_text', 'oc_change_add_to_cart_text' );
     20function oc_change_add_to_cart_text( $text ) {
    2221    global $fbtpfw_comman;
    23     if (isset($_REQUEST['attrs'])) {
    24         $product_id = sanitize_text_field($_REQUEST['curproid']);
    25         $match_attributes = sanitize_text_field($_REQUEST['attrs']);
    26         $data_store   = WC_Data_Store::load( 'product' );
    27         $variation_id = $data_store->find_matching_product_variation(
    28             new \WC_Product( $product_id),$match_attributes
    29         );
    30         update_post_meta($variation_id,'attr_cus',$match_attributes);
    31         $main_product = wc_get_product( $variation_id );
    32         $image_array = wp_get_attachment_image_src($main_product->image_id, 'thumbnail');
    33         $image_src = $image_array[0];
    34         $this_item_text = $fbtpfw_comman['this_item_text'];
    35         $regular_price_color = $fbtpfw_comman['regular_price_color'];
    36         $price_html = '<span class="fbtpfw_price_new" style="color:'.$regular_price_color.';">('.$main_product->get_price_html().')</span>';
    37         $responce['var_id'] = $variation_id;
    38         $responce['var_price'] = $main_product->get_price();
    39         $responce['var_price_html'] = $price_html;
    40         $responce['var_image'] = $image_src;
    41         $responce['var_name'] = $this_item_text.': '.$main_product->get_name();
    42     }
    43     echo wp_send_json($responce);
    44     die();
    45 }
    46 
    47 add_action('wp_ajax_variation_switch',  'fbtpfw_variation_switch' );
    48 add_action('wp_ajax_nopriv_variation_switch',  'fbtpfw_variation_switch');
    49 function fbtpfw_variation_switch(){
    50     if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'fbtpfw_ajax_nonce' ) ) {
    51         wp_die( 'Security check failed. Nonce is invalid.' );
    52     }
    53    
    54     $main_product = wc_get_product( sanitize_text_field($_REQUEST['var_id']) );
    55     $image_array = wp_get_attachment_image_src($main_product->image_id, 'thumbnail');
    56     $image_src = $image_array[0];
    57     $this_item_text = $fbtpfw_comman['this_item_text'];
    58     $regular_price_color = $fbtpfw_comman['regular_price_color'];
    59     $price_html = '<span class="fbtpfw_price_new" style="color:'.$regular_price_color.';">('.$main_product->get_price_html().')</span>';
    60     $responce['var_price'] = $main_product->get_price();
    61     $responce['var_price_html'] = $price_html;
    62     $responce['var_image'] = $image_src;
    63     $responce['var_name'] = $this_item_text.': '.$main_product->get_name();
    64     echo wp_send_json($responce);
    65     die();
     22    $add_to_cart_text = $fbtpfw_comman['add_to_cart_text'];
     23    return $add_to_cart_text;
     24}
     25
     26// 1) Print hidden inputs in the add-to-cart form (inside the form)
     27add_action( 'woocommerce_after_add_to_cart_button', 'fbtpfw_add_hidden_inputs' );
     28function fbtpfw_add_hidden_inputs() {
     29    global $product, $fbtpfw_comman;
     30
     31    // just ensure the product has some related IDs
     32    $related = get_post_meta( $product->get_id(), 'occp_select2', true );
     33    $default_products = $fbtpfw_comman['default_products'];
     34    if ( empty( $related ) && (empty($default_products) || $default_products == "none") ) return;
     35
     36    // don’t output all IDs – JS will handle it
     37    echo '<input type="hidden" name="fbtpfw_buyall_flag" value="1">';
     38    echo '<input type="hidden" name="fbtpfw_related" value="">';
     39}
     40
     41// 2) Capture the POST data and attach as cart_item_data (so it's available later)
     42if ( ! function_exists( 'fbtpfw_add_cart_item_data' ) ) {
     43    add_filter( 'woocommerce_add_cart_item_data', 'fbtpfw_add_cart_item_data', 10, 2 );
     44    function fbtpfw_add_cart_item_data( $cart_item_data, $product_id ) {
     45        if ( ! empty( $_POST['fbtpfw_buyall_flag'] ) && ! empty( $_POST['fbtpfw_related'] ) ) {
     46            $raw = wp_unslash( $_POST['fbtpfw_related'] );
     47            $related = json_decode( $raw, true );
     48
     49            if ( json_last_error() === JSON_ERROR_NONE && is_array( $related ) && ! empty( $related ) ) {
     50                // mark this cart item as the parent and store related IDs + prices
     51                $cart_item_data['is_fbtpfw_parent'] = true;
     52                $cart_item_data['fbtpfw_related'] = $related;
     53            }
     54        }
     55
     56        return $cart_item_data;
     57    }
     58}
     59
     60// 3) After the parent product is added to cart, add the related products (only once)
     61add_action( 'woocommerce_add_to_cart', 'fbtpfw_add_related_products', 10, 6 );
     62function fbtpfw_add_related_products( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) {
     63    // only run for items flagged as the parent
     64    if ( empty( $cart_item_data['is_fbtpfw_parent'] ) ) {
     65        return;
     66    }
     67
     68    // prevent recursion: remove hook while we add children
     69    remove_action( 'woocommerce_add_to_cart', 'fbtpfw_add_related_products', 10, 6 );
     70
     71    $related_ids = $cart_item_data['fbtpfw_related'] ?? array();
     72
     73    if ( is_array( $related_ids ) && ! empty( $related_ids ) ) {
     74        foreach ( $related_ids as $rel_prod ) {
     75            $rel_id = intval( $rel_prod['prod_id'] );
     76            $rel_price  = floatval( $rel_prod['prod_price'] );
     77            $rel_parent_prod_id  = intval( $rel_prod['parent_prod_id'] );
     78
     79            if ( ! $rel_id || $rel_id === $product_id ) {
     80                continue;
     81            }
     82
     83            $occp_product = wc_get_product( $rel_id );
     84            if ( ! $occp_product ) continue;
     85            if ( ! $occp_product->is_purchasable() || ! $occp_product->is_in_stock() ) continue;
     86
     87            // add the child product to cart; you can pass parent info if needed
     88            // WC()->cart->add_to_cart( $rel_id, 1 );
     89            WC()->cart->add_to_cart( $rel_id, $quantity = 1, $variation_id = 0, $variation = array(), $cart_item_data = array('fbtpfw_custom_price' => $rel_price, 'fbtpfw_parent_id' => $rel_parent_prod_id) );
     90
     91            // $child_key = WC()->cart->add_to_cart( $rel_id, 1 );
     92
     93            // if ( $child_key ) {
     94            //     // attach a reference in the parent cart item data for later use (optional)
     95            //     WC()->cart->cart_contents[ $cart_item_key ]['fbtpfw_child_keys'][] = $child_key;
     96            // }
     97        }
     98    }
     99
     100    // reattach the hook
     101    add_action( 'woocommerce_add_to_cart', 'fbtpfw_add_related_products', 10, 6 );
     102}
     103
     104// add discounted price when bought together
     105add_action( 'woocommerce_before_calculate_totals', function( $cart ) {
     106    foreach ( $cart->get_cart() as $cart_item ) {
     107        if ( isset( $cart_item['fbtpfw_custom_price'] ) ) {
     108            $cart_item['data']->set_price( $cart_item['fbtpfw_custom_price'] );
     109        }
     110    }
     111});
     112
     113add_action( 'woocommerce_cart_item_removed', 'fbtpfw_remove_related_items', 10, 2 );
     114function fbtpfw_remove_related_items( $cart_item_key, $cart ) {
     115
     116    $removed_item = $cart->removed_cart_contents[ $cart_item_key ] ?? null;
     117    if ( ! $removed_item ) {
     118        return;
     119    }
     120
     121    // ✅ If parent removed → remove children
     122    if ( ! empty( $removed_item['is_fbtpfw_parent'] ) && ! empty( $removed_item['fbtpfw_related'] ) ) {
     123        foreach ( $cart->get_cart() as $key => $item ) {
     124            if ( isset( $item['fbtpfw_parent_id'] ) && intval( $item['fbtpfw_parent_id'] ) === intval( $removed_item['product_id'] ) ) {
     125                $cart->remove_cart_item( $key );
     126            }
     127        }
     128    }
     129
     130    // ✅ If child removed → optional: remove parent too
     131    /*if ( isset( $removed_item['fbtpfw_parent_id'] ) ) {
     132        foreach ( $cart->get_cart() as $key => $item ) {
     133            if ( ! empty( $item['fbtpfw_parent_id'] ) && intval( $item['product_id'] ) === intval( $removed_item['fbtpfw_parent_id'] ) ) {
     134                $cart->remove_cart_item( $key );
     135            }
     136        }
     137    }*/
    66138}
    67139
     
    73145        if($page_security->post_type == "product") {
    74146            $product_id = $page_security->ID;
    75             $layout     = get_post_meta($product_id , 'occp_layout', true );
     147            // $layout     = get_post_meta($product_id , 'occp_layout', true );
     148            $layout = $fbtpfw_comman['layout'];
    76149            $single_pro_positions = $fbtpfw_comman['single_pro_positions'];
    77150            if( $layout == "layout1" ) {
     
    80153                    add_action( 'woocommerce_before_add_to_cart_button',  'fbtpfw_layout1'  );
    81154                }else{
    82                     if ($single_pro_positions == 'before_adtcart') {
    83                         add_action( 'woocommerce_before_add_to_cart_quantity', 'fbtpfw_layout1' , 1 );
    84                     }elseif ($single_pro_positions == 'after_adtcart') {
    85                         add_action( 'woocommerce_after_add_to_cart_button', 'fbtpfw_layout1' , 1 );
     155                    $single_pro_positions = $fbtpfw_comman['single_pro_positions'];
     156                    if($single_pro_positions == 'before_title'){
     157                        add_action( 'woocommerce_single_product_summary',  'fbtpfw_layout1', 1 );
     158                    }elseif($single_pro_positions == 'before_atc'){
     159                        add_action( 'woocommerce_before_add_to_cart_form', 'fbtpfw_layout1' , 1 );
     160                    }elseif($single_pro_positions == 'after_atc'){
     161                        add_action( 'woocommerce_after_add_to_cart_form', 'fbtpfw_layout1' , 1 );
     162                    }elseif($single_pro_positions == 'after_summary'){
     163                        add_filter( 'woocommerce_after_single_product_summary', 'fbtpfw_layout1', 5);
    86164                    }
    87165                }     
    88166            }elseif( $layout == "layout2" ) {
    89                 $single_pro_positionsl2 = $fbtpfw_comman['single_pro_positionsl2'];
    90                 if($single_pro_positionsl2 == 'before_title'){
     167                $single_pro_positions = $fbtpfw_comman['single_pro_positions'];
     168                if($single_pro_positions == 'before_title'){
    91169                    add_action( 'woocommerce_single_product_summary',  'fbtpfw_layout2', 1 );
    92                 }elseif($single_pro_positionsl2 == 'before_atc'){
     170                }elseif($single_pro_positions == 'before_atc'){
    93171                    add_action( 'woocommerce_before_add_to_cart_form', 'fbtpfw_layout2' , 1 );
    94                 }elseif($single_pro_positionsl2 == 'after_atc'){
     172                }elseif($single_pro_positions == 'after_atc'){
    95173                    add_action( 'woocommerce_after_add_to_cart_form', 'fbtpfw_layout2' , 1 );
    96                 }elseif($single_pro_positionsl2 == 'after_summary'){
     174                }elseif($single_pro_positions == 'after_summary'){
    97175                    add_filter( 'woocommerce_after_single_product_summary', 'fbtpfw_layout2', 5);
    98176                }
     
    106184    echo do_shortcode( '[Woo_Frequently_added]' );
    107185 }*/
    108 function fbtpfw_add_display_default_product($product){
     186
     187/**
     188 * Renders the HTML for a list of default products (related or upsells).
     189 *
     190 * @param array  $product_list Array of product objects or IDs.
     191 * @param string $layout       The layout to render ('layout1' or 'layout2').
     192 * @param bool   $is_related   True if the products are related, false for upsells.
     193 * @return string The rendered HTML.
     194 */
     195
     196/*design for shortcode*/
     197add_shortcode( 'Woo_Frequently_added', 'fbtpfw_woo_combo' );
     198function fbtpfw_woo_combo( $atts, $content = null ) {
    109199    global $fbtpfw_comman;
    110     $count  = 0;
    111     $badge ='';
    112     $product_details = '';
    113     $total= 0;
    114     $images = '';
    115     // echo "<pre>";
    116     // print_r($product);
    117     // echo "</pre>";
    118     // exit;
    119     $layout     = get_post_meta(get_the_ID() , 'occp_layout', true );
    120     $default_products = $fbtpfw_comman['default_products'];
    121     if( $layout == "layout1" ) {
    122         if ($default_products == 'related') {
    123             foreach ($product as $productsdata) {
    124                 $product = wc_get_product( $productsdata->ID );
    125                 $current_product_link =  $product->get_permalink();
    126                 $current_product_image = $product->get_image();
    127                 $current_product_title = $product->get_title();
    128                 $current_product_price = $product->get_price();
    129                 $current_product_id = $product->get_id();
    130                 $current_product_is_variation   = $product->is_type( 'variation' );
    131                 $current_product_discount='';
    132                 $current_product_discount_type='';
    133                 if(!empty($occp_discunt[$current_product_id])) {
    134                     $current_product_discount = $occp_discunt[$current_product_id];
    135                 }
    136                 if(!empty($occp_discunt_type[$current_product_id])) {
    137                     $current_product_discount_type = $occp_discunt_type[$current_product_id];
    138                 }
    139                
    140 
    141                 $current_product_exact_price = fbtpfw_get_price($current_product_price, $current_product_discount, $current_product_discount_type);
    142                 if($count == 0) {
    143                     $current_product_exact_prices = 0;
    144                 } else {
    145                     $current_product_exact_prices = $current_product_exact_price;
    146                 }
    147                
    148                 $dis_type = get_post_meta( get_the_ID(), 'occp_discount_type' );
    149                 $dis_amt = get_post_meta( get_the_ID(), 'occp_off_per' );
    150                 $discount_badge_text_color =$fbtpfw_comman['discount_badge_text_color'];
    151                 $discount_badge_back_color = $fbtpfw_comman['discount_badge_back_color'];;
    152 
    153                 if(!empty($dis_amt[0][$current_product_id])) {
    154                     if(get_option('woocommerce_currency_pos') == 'left' || get_option('woocommerce_currency_pos') == 'left_space'){
    155                         if($dis_type[0][$current_product_id] == "percentage") {
    156                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].' %</span></div>';
    157                         }else if($dis_type[0][$current_product_id] == "fixed") {
    158                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.get_woocommerce_currency_symbol().$dis_amt[0][$current_product_id].'</span></div>';
    159                         }
    160                     }else{
    161                         if($dis_type[0][$current_product_id] == "percentage") {
    162                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].' %</span></div>';
    163                         }else if($dis_type[0][$current_product_id] == "fixed") {
    164                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].get_woocommerce_currency_symbol(). '</span></div>';
    165                         }
     200
     201    // shortcode attributes...
     202    $atts = shortcode_atts(
     203        array(
     204            'isshowbutton' => 'no',
     205        ),
     206        $atts,
     207        'Woo_Frequently_added'
     208    );
     209
     210    $show_button = $atts['isshowbutton'];
     211
     212    $page_security = get_queried_object();
     213    // if ( get_post_meta( $page_security->ID, 'occp_layout', true ) == "none" ) {
     214    if ( $fbtpfw_comman['layout'] == "none" ) {
     215        $product = get_post_meta( get_the_ID(), 'occp_select2', true );
     216        if ( empty( $product ) ) {
     217            $pro_id = get_the_ID();
     218            return relared_upsells_common_func( $pro_id );
     219        }
     220
     221        $occp_count  = count( $product );
     222        $occp_badge  = 'true';
     223        if ( wp_is_mobile() && $occp_count > 2 ) {
     224            $occp_badge = 'false';
     225        }
     226
     227        $occp_discunt      = get_post_meta( get_the_ID(), 'occp_off_per', true );
     228        $occp_discunt_type = get_post_meta( get_the_ID(), 'occp_discount_type', true );
     229
     230        if ( empty( $product ) ) {
     231            return '';
     232        }
     233
     234        $main_product = wc_get_product( get_the_ID() );
     235        if ( $main_product->has_child() ) {
     236            $product_variable = new WC_Product_Variable( get_the_ID() );
     237            $variations       = $product_variable->get_available_variations();
     238            $vari             = 0;
     239            foreach ( $variations as $variation ) {
     240                $vari++;
     241                if ( $vari == 1 ) {
     242                    if ( ! in_array( $variation['variation_id'], $product ) ) {
     243                        array_unshift( $product, $variation['variation_id'] );
    166244                    }
    167245                }
    168 
    169                 $images .= '<td class="fbtpfw_img" image_pro_id="'.$current_product_id.'"><div class="fbtpfw_img_div"><a href="' . $current_product_link . '">' . $current_product_image . '</a>'.$badge.'</div></td>';
    170                 ob_start();
    171                 $check_default_pro =  $fbtpfw_comman['check_default_pro'];
    172                 ?>
    173                 <div class="fbtpfw_each_item <?php if($count == 0) { echo 'fbtpfw_each_curprod'; } ?>">
    174                     <div class="fbtpfw_product_check">
    175                         <input type="checkbox" name="proID[]" id="proID_<?php echo esc_attr($count); ?>" class="product_check" value="<?php echo esc_attr($current_product_id); ?>" price="<?php echo esc_attr($current_product_exact_price) ; ?>" <?php if($count == 0){ echo "checked disabled"; }elseif($check_default_pro == 'yes'){echo "checked";} ?>/>
    176                     </div>
    177 
    178                     <div class="fbtpfw_product_image">
    179                         <?php echo $product->get_image();?>
    180                     </div>
    181 
    182                     <div class="fbtpfw_product_title">
    183                         <?php $this_item_text = $fbtpfw_comman['this_item_text']; ?>
    184                         <span>
    185                             <?php
    186                             if($count == 0) {
    187                                 echo esc_attr($this_item_text).': '.esc_attr($current_product_title);
    188                             } else {
    189                                 echo '<a href="'.esc_url($current_product_link).'">'.esc_attr($current_product_title).'</a>';
    190                             }
    191                             ?>
    192                         </span>
    193                         <?php
    194                             if( $current_product_is_variation ) {
    195                                 $attributes = $product->get_variation_attributes();
    196                                 $variations = array();
    197 
    198                                 foreach( $attributes as $key => $attribute ) {
    199                                     $variations[] = $attribute;
    200                                 }
    201 
    202                                 if( ! empty( $variations ) )
    203                                 echo '<span class="product-attributes"> &ndash; ' . esc_attr(implode( ', ', $variations )) . '</span>';
    204                             }
    205                         ?>
    206                     </div>
    207 
    208                     <div class="fbtpfw_product_price">
    209                         <?php
    210                             if(!empty($product->get_sale_price())) {
    211                                 $price = wc_price($product->get_regular_price());
    212                             }elseif(!empty($current_product_exact_price)){
    213                                 $price = wc_price($product->get_regular_price());
    214                             }else {
    215                                 $price = "";
    216                             }
    217                             $regular_price_color = $fbtpfw_comman['regular_price_color'];
    218                             echo '<span class="fbtpfw_price_old">' . $price . '</span><span class="fbtpfw_price_new" style="color:'.esc_attr($regular_price_color).';">('. wc_price($current_product_exact_price) .')</span>';
    219                         ?>
    220                     </div>
     246            }
     247        } else {
     248            array_unshift( $product, get_the_ID() );
     249        }
     250
     251        $count           = 0;
     252        $product_details = '';
     253        $total           = 0;
     254        $images          = '';
     255
     256        foreach ( $product as $productId ) {
     257            $product_obj                = wc_get_product( $productId );
     258            $current_product_link        = $product_obj->get_permalink();
     259            $current_product_image       = $product_obj->get_image();
     260            $current_product_title       = $product_obj->get_title();
     261            $current_product_price       = $product_obj->get_price();
     262            $current_product_id          = $product_obj->get_id();
     263            $current_product_is_variation = $product_obj->is_type( 'variation' );
     264
     265            $current_product_discount     = ! empty( $occp_discunt[ $current_product_id ] ) ? $occp_discunt[ $current_product_id ] : '';
     266            $current_product_discount_type = ! empty( $occp_discunt_type[ $current_product_id ] ) ? $occp_discunt_type[ $current_product_id ] : '';
     267
     268            $current_product_exact_price = fbtpfw_get_price( $current_product_price, $current_product_discount, $current_product_discount_type );
     269
     270            // Badge
     271            $badge                        = '';
     272            $dis_type                     = get_post_meta( get_the_ID(), 'occp_discount_type' );
     273            $dis_amt                      = get_post_meta( get_the_ID(), 'occp_off_per' );
     274            $discount_badge_text_color    = $fbtpfw_comman['discount_badge_text_color'];
     275            $discount_badge_back_color    = $fbtpfw_comman['discount_badge_back_color'];
     276
     277            if ( ! empty( $dis_amt[0][ $current_product_id ] ) ) {
     278                $value = $dis_amt[0][ $current_product_id ];
     279                if ( $dis_type[0][ $current_product_id ] == "percentage" ) {
     280                    $badge = '<div class="fbtpfw_badge" style="border:2px solid ' . $discount_badge_back_color . ';"><span style="color:' . $discount_badge_text_color . ';background:' . $discount_badge_back_color . ';"><p>off</p>- ' . $value . ' %</span></div>';
     281                } elseif ( $dis_type[0][ $current_product_id ] == "fixed" ) {
     282                    $badge = '<div class="fbtpfw_badge" style="border:2px solid ' . $discount_badge_back_color . ';"><span style="color:' . $discount_badge_text_color . ';background:' . $discount_badge_back_color . ';"><p>off</p>- ' . get_woocommerce_currency_symbol() . $value . '</span></div>';
     283                }
     284            }
     285            if ( $occp_badge != 'true' ) {
     286                $badge = '';
     287            }
     288
     289            // Images
     290            $images .= '<div class="fbtpfw_img" image_pro_id="'.$current_product_id.'">
     291                <div class="fbtpfw_img_div">
     292                    <a href="' . $current_product_link . '">' . $current_product_image . '</a>
     293                    '.$badge.'
    221294                </div>
    222                 <?php
    223                 $product_details .= ob_get_clean();
    224                 // increment total
    225                 $total += floatval( $current_product_exact_prices );
    226                 $count++;
    227             }
    228             ?>
    229 
    230             <input type="hidden" name="formate" value="<?php echo esc_attr(get_woocommerce_currency_symbol()); ?>" class="formate">
    231             <input type="hidden" name="layout" value="layout1" class="layout">
    232             <div class="fbtpfw_main layout1">
    233                  <?php $fbtpfw_product_color = $fbtpfw_comman['fbtpfw_product_color']; ?>
    234                 <h3 style="color:<?php echo esc_attr($fbtpfw_product_color); ?>"><?php echo esc_attr(get_post_meta( get_the_ID(), 'occp_head_txt', true )); ?></h3>
    235                 <div class="fbtpfw_div">
    236                     <?php echo $product_details;?>
    237                 </div>
    238                 <div class="fbtpfw_cart_div">
    239                     <div class="fbtpfw_price">
    240                          <?php $addtional_amount_text_color = $fbtpfw_comman['addtional_amount_text_color']; ?>
    241                         <span class="fbtpfw_price_label" style="color: <?php echo esc_attr($addtional_amount_text_color); ?>;">
    242                             <?php $addtional_amount_text = $fbtpfw_comman['addtional_amount_text']; ?>
    243                             <?php echo esc_attr($addtional_amount_text)." : "; ?>
    244                         </span>
    245                         &nbsp;
    246                         <span class="fbtpfw_price_total" data-total="<?php echo esc_attr($total) ?>">
    247                             <?php echo wc_price( $total ); ?>
    248                         </span>
    249                     </div>
    250                 </div>
    251             </div>
    252             <?php
    253         }elseif ($default_products == 'upsells') {
    254             foreach ($product as $productsdata) {
    255                 $product = wc_get_product( $productsdata );
    256                 $current_product_link =  $product->get_permalink();
    257                 $current_product_image = $product->get_image();
    258                 $current_product_title = $product->get_title();
    259                 $current_product_price = $product->get_price();
    260                 $current_product_id = $product->get_id();
    261                 $current_product_is_variation   = $product->is_type( 'variation' );
    262                 $current_product_discount='';
    263                 $current_product_discount_type='';
    264                 if(!empty($occp_discunt[$current_product_id])) {
    265                     $current_product_discount = $occp_discunt[$current_product_id];
    266                 }
    267                 if(!empty($occp_discunt_type[$current_product_id])) {
    268                     $current_product_discount_type = $occp_discunt_type[$current_product_id];
    269                 }
    270                
    271 
    272                 $current_product_exact_price = fbtpfw_get_price($current_product_price, $current_product_discount, $current_product_discount_type);
    273                 if($count == 0) {
    274                     $current_product_exact_prices = 0;
    275                 } else {
    276                     $current_product_exact_prices = $current_product_exact_price;
    277                 }
    278                
    279                 $dis_type = get_post_meta( get_the_ID(), 'occp_discount_type' );
    280                 $dis_amt = get_post_meta( get_the_ID(), 'occp_off_per' );
    281                 $discount_badge_text_color =$fbtpfw_comman['discount_badge_text_color'];
    282                 $discount_badge_back_color = $fbtpfw_comman['discount_badge_back_color'];;
    283 
    284                 if(!empty($dis_amt[0][$current_product_id])) {
    285                     if(get_option('woocommerce_currency_pos') == 'left' || get_option('woocommerce_currency_pos') == 'left_space'){
    286                         if($dis_type[0][$current_product_id] == "percentage") {
    287                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].' %</span></div>';
    288                         }else if($dis_type[0][$current_product_id] == "fixed") {
    289                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.get_woocommerce_currency_symbol().$dis_amt[0][$current_product_id].'</span></div>';
    290                         }
    291                     }else{
    292                         if($dis_type[0][$current_product_id] == "percentage") {
    293                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].' %</span></div>';
    294                         }else if($dis_type[0][$current_product_id] == "fixed") {
    295                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].get_woocommerce_currency_symbol(). '</span></div>';
    296                         }
    297                     }
    298                 }
    299 
    300                 $images .= '<td class="fbtpfw_img" image_pro_id="'.$current_product_id.'"><div class="fbtpfw_img_div"><a href="' . $current_product_link . '">' . $current_product_image . '</a>'.$badge.'</div></td>';
    301                 ob_start();
    302                 $check_default_pro =  $fbtpfw_comman['check_default_pro'];
    303                 ?>
    304                 <div class="fbtpfw_each_item <?php if($count == 0) { echo 'fbtpfw_each_curprod'; } ?>">
    305                     <div class="fbtpfw_product_check">
    306                         <input type="checkbox" name="proID[]" id="proID_<?php echo esc_attr($count); ?>" class="product_check" value="<?php echo esc_attr($current_product_id); ?>" price="<?php echo esc_attr($current_product_exact_price) ; ?>" <?php if($count == 0){ echo "checked disabled"; }elseif($check_default_pro == 'yes'){echo "checked";} ?>/>
    307                     </div>
    308 
    309                     <div class="fbtpfw_product_image">
    310                         <?php echo $product->get_image();?>
    311                     </div>
    312 
    313                     <div class="fbtpfw_product_title">
    314                         <?php $this_item_text = $fbtpfw_comman['this_item_text']; ?>
    315                         <span>
    316                             <?php
    317                             if($count == 0) {
    318                                 echo esc_attr($this_item_text).': '.esc_attr($current_product_title);
    319                             } else {
    320                                 echo '<a href="'.esc_url($current_product_link).'">'.esc_attr($current_product_title).'</a>';
    321                             }
    322                             ?>
    323                         </span>
    324                         <?php
    325                             if( $current_product_is_variation ) {
    326                                 $attributes = $product->get_variation_attributes();
    327                                 $variations = array();
    328 
    329                                 foreach( $attributes as $key => $attribute ) {
    330                                     $variations[] = $attribute;
    331                                 }
    332 
    333                                 if( ! empty( $variations ) )
    334                                 echo '<span class="product-attributes"> &ndash; ' . esc_attr(implode( ', ', $variations )) . '</span>';
    335                             }
    336                         ?>
    337                     </div>
    338 
    339                     <div class="fbtpfw_product_price">
    340                         <?php
    341                             if(!empty($product->get_sale_price())) {
    342                                 $price = wc_price($product->get_regular_price());
    343                             }elseif(!empty($current_product_exact_price)){
    344                                 $price = wc_price($product->get_regular_price());
    345                             }else {
    346                                 $price = "";
    347                             }
    348                             $regular_price_color = $fbtpfw_comman['regular_price_color'];
    349                             echo '<span class="fbtpfw_price_old">' . $price . '</span><span class="fbtpfw_price_new" style="color:'.esc_attr($regular_price_color).';">('. wc_price($current_product_exact_price) .')</span>';
    350                         ?>
    351                     </div>
    352                 </div>
    353                 <?php
    354                 $product_details .= ob_get_clean();
    355                 // increment total
    356                 $total += floatval( $current_product_exact_prices );
    357                 $count++;
    358             }
    359             ?>
    360 
    361             <input type="hidden" name="formate" value="<?php echo esc_attr(get_woocommerce_currency_symbol()); ?>" class="formate">
    362             <input type="hidden" name="layout" value="layout1" class="layout">
    363             <div class="fbtpfw_main layout1">
    364                  <?php $fbtpfw_product_color = $fbtpfw_comman['fbtpfw_product_color']; ?>
    365                 <h3 style="color:<?php echo esc_attr($fbtpfw_product_color); ?>"><?php echo esc_attr(get_post_meta( get_the_ID(), 'occp_head_txt', true )); ?></h3>
    366                 <div class="fbtpfw_div">
    367                     <?php echo $product_details;?>
    368                 </div>
    369                 <div class="fbtpfw_cart_div">
    370                     <div class="fbtpfw_price">
    371                          <?php $addtional_amount_text_color = $fbtpfw_comman['addtional_amount_text_color']; ?>
    372                         <span class="fbtpfw_price_label" style="color: <?php echo esc_attr($addtional_amount_text_color); ?>;">
    373                             <?php $addtional_amount_text = $fbtpfw_comman['addtional_amount_text']; ?>
    374                             <?php echo esc_attr($addtional_amount_text)." : "; ?>
    375                         </span>
    376                         &nbsp;
    377                         <span class="fbtpfw_price_total" data-total="<?php echo esc_attr($total) ?>">
    378                             <?php echo wc_price( $total ); ?>
    379                         </span>
    380                     </div>
    381                 </div>
    382             </div>
    383             <?php
    384         }
    385     }elseif ($layout == "layout2") {
    386         $occp_count = count((array)$product);
    387         $occp_badge = 'true';
    388 
    389         if(wp_is_mobile()) {
    390             if($occp_count > 2) {
    391                 $occp_badge = 'false';
    392             }
    393         }
    394 
    395         $occp_discunt = get_post_meta( get_the_ID(), 'occp_off_per', true );
    396         $occp_discunt_type = get_post_meta( get_the_ID(), 'occp_discount_type', true );
    397         $count = 0;
    398         $badge = '';
    399         $product_details = '';
    400         $total= 0;
    401         $images = '';
    402 
    403         if ($default_products == 'related') {
    404             foreach ($product as $productId) {
    405                 $product = wc_get_product( $productId->ID );
    406                 $current_product_link = $product->get_permalink();
    407                 $current_product_image = $product->get_image();
    408                 $current_product_title = $product->get_title();
    409                 $current_product_price = $product->get_price();
    410                 $current_product_id = $product->get_id();
    411                 $current_product_is_variation   = $product->is_type( 'variation' );
    412                 $current_product_discount='';
    413                 $current_product_discount_type='';
    414                 if(!empty($occp_discunt[$current_product_id])) {
    415                     $current_product_discount = $occp_discunt[$current_product_id];
    416                 }
    417                 if(!empty($occp_discunt_type[$current_product_id])) {
    418                     $current_product_discount_type = $occp_discunt_type[$current_product_id];
    419                 }
    420                
    421                 $current_product_exact_price = fbtpfw_get_price($current_product_price, $current_product_discount, $current_product_discount_type);
    422 
    423                 $dis_type = get_post_meta( get_the_ID(), 'occp_discount_type' );
    424                 $dis_amt = get_post_meta( get_the_ID(), 'occp_off_per' );
    425                 $discount_badge_text_color = $fbtpfw_comman['discount_badge_text_color'];
    426                 $discount_badge_back_color = $fbtpfw_comman['discount_badge_back_color'];;
    427                                
    428                 if(!empty($dis_amt[0][$current_product_id])) {
    429                     if(get_option('woocommerce_currency_pos') == 'left' || get_option('woocommerce_currency_pos') == 'left_space'){
    430                         if($dis_type[0][$current_product_id] == "percentage") {
    431                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].' %</span></div>';
    432                         }else if($dis_type[0][$current_product_id] == "fixed") {
    433                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.get_woocommerce_currency_symbol().$dis_amt[0][$current_product_id].'</span></div>';
    434                         }
    435                     }else{
    436                         if($dis_type[0][$current_product_id] == "percentage") {
    437                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].' %</span></div>';
    438                         }else if($dis_type[0][$current_product_id] == "fixed") {
    439                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].get_woocommerce_currency_symbol(). '</span></div>';
    440                         }
    441                     }
    442                 }
    443 
    444                 if($occp_badge == 'true') {
    445                     $badge = $badge;
    446                 } else {
    447                     $badge = '';
    448                 }
    449 
    450                 $images .= '<td class="fbtpfw_img" image_pro_id="'.$current_product_id.'"><div class="fbtpfw_img_div"><a href="' . $current_product_link . '">' . $current_product_image . '</a>'.$badge.'</div></td>';
    451 
    452                 if( $count < $occp_count ) {
    453                     $isimplfirst = '';
    454                     if($count == 0) {
    455                         $isimplfirst = 'fbtpfw_img_plus_first';
    456                     }
    457                     $images .= '<td class="fbtpfw_img_plus '.$isimplfirst.'" fbtpfw_imgpls_id="'.$current_product_id.'">+</td>';
    458                 }
    459                
    460                 ob_start();
    461                 $check_default_pro = $fbtpfw_comman['check_default_pro'];
    462                 ?>
    463                 <li class="fbtpfw_each_item">
    464                     <input type="checkbox" name="proID[]" id="proID_<?php echo esc_attr($count) ?>" class="product_check" value="<?php echo esc_attr($current_product_id); ?>" price="<?php echo esc_attr($current_product_exact_price); ?>" <?php if($count == 0) { echo 'checked style="opacity: .6;pointer-events: none;"'; }elseif($check_default_pro == 'yes'){echo "checked";} ?> />
    465                     <span class="fbtpfw_product_title">
    466                         <?php $this_item_text = $fbtpfw_comman['this_item_text']; ?>
    467                         <?php
    468                         if($count == 0) {
    469                             echo esc_attr($this_item_text.' : '.$current_product_title);
    470                         } else {
    471                             echo '<a href="'.esc_url($current_product_link).'">'.esc_attr($current_product_title).'</a>';
    472                         }
    473                         ?>
    474                     </span>
    475                     <?php
    476                         if( $current_product_is_variation ) {
    477                             $attributes = $product->get_variation_attributes();
    478                             $variations = array();
    479 
    480                             foreach( $attributes as $key => $attribute ) {
    481                                 $variations[] = $attribute;
    482                             }
    483 
    484                             if( ! empty( $variations ) ){
    485                                 echo '<span class="product-attributes"> &ndash; ' . esc_attr(implode( ', ', $variations )) . '</span>';
    486                             }
    487 
    488                         }
    489                        
    490                         if(!empty($product->get_price())) {
    491                             $price = wc_price($product->get_price());
    492                         }else {
    493                             $price = wc_price(0);
    494                         }
    495                         if(!empty($product->get_sale_price())) {
    496                             $price = wc_price($product->get_regular_price());
    497                         }elseif(!empty($current_product_exact_price)){
    498                             $price = wc_price($product->get_regular_price());
    499                         }else {
    500                             $price = "";
    501                         }
    502                         $regular_price_color = $fbtpfw_comman['regular_price_color'];
    503                         echo ' &ndash; <span class="fbtpfw_price_old">' . $price. '</span><span class="fbtpfw_price_new" style="color:'.esc_attr($regular_price_color).';">('. wc_price($current_product_exact_price) .')</span>';
    504 
    505                         $productaaaaa = wc_get_product( get_the_ID() );
    506                         if($productaaaaa->get_type() == 'variable'){
    507                             $attributesqwqww = $productaaaaa->get_variation_attributes();
    508                             $available_variations = $productaaaaa->get_available_variations();
    509                             if( $current_product_is_variation ) {
    510                                 if ( is_array( $attributesqwqww ) && ( count( $attributesqwqww ) > 0 ) ) {
    511                                     echo "<div class='oc_cust_variation' currentproid=".get_the_id().">";
    512 
    513                                     if ( is_array( $attributes ) && ( count( $attributes ) > 0 ) ) {
    514                                         echo '<div class="variations_form" data-product_id="' . absint( get_the_id() ) . '" data-product_variations="' . htmlspecialchars( wp_json_encode( $available_variations ) ) . '">';
    515                                         echo '<div class="variations">';
    516                                         foreach ( $attributesqwqww as $attribute_name => $options ) { ?>
    517                                             <div class="variation">
    518                                                 <div class="label">
    519                                                     <?php echo wc_attribute_label( $attribute_name ); ?>
    520                                                 </div>
    521                                                 <div class="select">
    522                                                     <?php
    523                                                     $selected = isset( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ? wc_clean( stripslashes( urldecode( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ) ) : $productaaaaa->get_variation_default_attribute( $attribute_name );
    524                                                         wc_dropdown_variation_attribute_options( array(
    525                                                             'options'          => $options,
    526                                                             'attribute'        => $attribute_name,
    527                                                             'product'          => $productaaaaa,
    528                                                             'selected'         => $selected,
    529                                                         ) );
    530                                                     ?>
    531                                                 </div>
    532                                             </div>
    533                                         <?php }
    534                                         echo '<div class="reset">' . apply_filters( 'woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . fbtpfw_localization( 'clear', esc_html__( 'Clear', 'frequently-bought-together-product-for-woocommmerce' ) ) . '</a>' ) . '</div>';
    535                                         echo '</div>';
    536                                         echo '</div>';
    537                                         echo "</div>";
    538                                     }
    539                                 }
    540                             }
    541                         }
    542                     ?>
    543                 </li>
    544                 <?php
    545                 $product_details .= ob_get_clean();
    546                 // increment total
    547                 $total += floatval( $current_product_exact_price );
    548                 $badge = '';
    549                 $count++;
    550             }
    551             ?>
    552             <input type="hidden" name="formate" value="<?php echo esc_attr(get_woocommerce_currency_symbol()); ?>" class="formate">
    553             <input type="hidden" name="layout" value="layout2" class="layout">
    554             <div class="fbtpfw_main layout2">
    555                 <form class="fbtpfw_product_form" method="post" action="">
    556                     <?php $fbtpfw_product_color = $fbtpfw_comman['fbtpfw_product_color']; ?>
    557                     <h3 style="color:<?php echo esc_attr($fbtpfw_product_color); ?>" ><?php echo esc_attr(get_post_meta( get_the_ID(), 'occp_head_txt', true )); ?></h3>
    558                     <table class="fbtpfw_product_images">
    559                         <tbody>
    560                             <tr>
    561                                 <?php echo $images;  ?>
    562                                
    563                             </tr>
    564                         </tbody>
    565                     </table>
    566                     <div class="fbtpfw_cart_div">
    567                         <div class="fbtpfw_price">
    568                              <?php $price_all_text_color = $fbtpfw_comman['price_all_text_color']; ?>
    569                             <span class="fbtpfw_price_label" style="color:<?php echo esc_attr($price_all_text_color);  ?>">
    570                                 <?php $price_for_all_text = $fbtpfw_comman['price_for_all_text']; ?>
    571                                 <?php echo esc_attr($price_for_all_text)." : ";
    572                                 ?>
    573                             </span>
    574                             &nbsp;
    575                             <span class="fbtpfw_price_total" data-total="<?php echo esc_attr($total); ?>">
    576                                 <?php echo wc_price( $total ); ?>
    577                             </span>
    578                         </div>
    579                         <?php $add_to_cart_text =$fbtpfw_comman['add_to_cart_text']; ?>
    580                         <?php $add_cart_back_color =  $fbtpfw_comman['add_cart_back_color']; ?>
    581                         <?php $add_cart_text_color = $fbtpfw_comman['add_cart_text_color']; ?>
    582                         <input type="submit" style="color:<?php echo esc_attr($add_cart_text_color); ?>;background: <?php echo esc_attr($add_cart_back_color); ?>" class="occp_add_cart_button button" value="<?php echo esc_attr($add_to_cart_text); ?>" name="occp_add_to_cart">
    583                     </div>
    584 
    585                     <ul class="fbtpfw_ul">
    586                         <?php echo $product_details;  ?>
    587                     </ul>       
    588                 </form>
    589             </div>
    590             <?php
    591         }elseif ($default_products == 'upsells') {
    592             foreach ($product as $productId) {
    593                 $product = wc_get_product( $productId );
    594                 $current_product_link = $product->get_permalink();
    595                 $current_product_image = $product->get_image();
    596                 $current_product_title = $product->get_title();
    597                 $current_product_price = $product->get_price();
    598                 $current_product_id = $product->get_id();
    599                 $current_product_is_variation   = $product->is_type( 'variation' );
    600                 $current_product_discount='';
    601                 $current_product_discount_type='';
    602                 if(!empty($occp_discunt[$current_product_id])) {
    603                     $current_product_discount = $occp_discunt[$current_product_id];
    604                 }
    605                 if(!empty($occp_discunt_type[$current_product_id])) {
    606                     $current_product_discount_type = $occp_discunt_type[$current_product_id];
    607                 }
    608                
    609                 $current_product_exact_price = fbtpfw_get_price($current_product_price, $current_product_discount, $current_product_discount_type);
    610 
    611                 $dis_type = get_post_meta( get_the_ID(), 'occp_discount_type' );
    612                 $dis_amt = get_post_meta( get_the_ID(), 'occp_off_per' );
    613                 $discount_badge_text_color = $fbtpfw_comman['discount_badge_text_color'];
    614                 $discount_badge_back_color = $fbtpfw_comman['discount_badge_back_color'];;
    615                                
    616                 if(!empty($dis_amt[0][$current_product_id])) {
    617                     if(get_option('woocommerce_currency_pos') == 'left' || get_option('woocommerce_currency_pos') == 'left_space'){
    618                         if($dis_type[0][$current_product_id] == "percentage") {
    619                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].' %</span></div>';
    620                         }else if($dis_type[0][$current_product_id] == "fixed") {
    621                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.get_woocommerce_currency_symbol().$dis_amt[0][$current_product_id].'</span></div>';
    622                         }
    623                     }else{
    624                         if($dis_type[0][$current_product_id] == "percentage") {
    625                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].' %</span></div>';
    626                         }else if($dis_type[0][$current_product_id] == "fixed") {
    627                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].get_woocommerce_currency_symbol(). '</span></div>';
    628                         }
    629                     }
    630                 }
    631 
    632                 if($occp_badge == 'true') {
    633                     $badge = $badge;
    634                 } else {
    635                     $badge = '';
    636                 }
    637 
    638                 $images .= '<td class="fbtpfw_img" image_pro_id="'.$current_product_id.'"><div class="fbtpfw_img_div"><a href="' . $current_product_link . '">' . $current_product_image . '</a>'.$badge.'</div></td>';
    639 
    640                 if( $count < $occp_count ) {
    641                     $isimplfirst = '';
    642                     if($count == 0) {
    643                         $isimplfirst = 'fbtpfw_img_plus_first';
    644                     }
    645                     $images .= '<td class="fbtpfw_img_plus '.$isimplfirst.'" fbtpfw_imgpls_id="'.$current_product_id.'">+</td>';
    646                 }
    647                
    648                 ob_start();
    649                 $check_default_pro = $fbtpfw_comman['check_default_pro'];
    650                 ?>
    651                 <li class="fbtpfw_each_item">
    652                     <input type="checkbox" name="proID[]" id="proID_<?php echo esc_attr($count) ?>" class="product_check" value="<?php echo esc_attr($current_product_id); ?>" price="<?php echo esc_attr($current_product_exact_price); ?>" <?php if($count == 0) { echo 'checked style="opacity: .6;pointer-events: none;"'; }elseif($check_default_pro == 'yes'){echo "checked";} ?> />
    653                     <span class="fbtpfw_product_title">
    654                         <?php $this_item_text = $fbtpfw_comman['this_item_text']; ?>
    655                         <?php
    656                         if($count == 0) {
    657                             echo esc_attr($this_item_text.' : '.$current_product_title);
    658                         } else {
    659                             echo '<a href="'.esc_url($current_product_link).'">'.esc_attr($current_product_title).'</a>';
    660                         }
    661                         ?>
    662                     </span>
    663                     <?php
    664                         if( $current_product_is_variation ) {
    665                             $attributes = $product->get_variation_attributes();
    666                             $variations = array();
    667 
    668                             foreach( $attributes as $key => $attribute ) {
    669                                 $variations[] = $attribute;
    670                             }
    671 
    672                             if( ! empty( $variations ) ){
    673                                 echo '<span class="product-attributes"> &ndash; ' . esc_attr(implode( ', ', $variations )) . '</span>';
    674                             }
    675 
    676                         }
    677                        
    678                         if(!empty($product->get_price())) {
    679                             $price = wc_price($product->get_price());
    680                         }else {
    681                             $price = wc_price(0);
    682                         }
    683                         if(!empty($product->get_sale_price())) {
    684                             $price = wc_price($product->get_regular_price());
    685                         }elseif(!empty($current_product_exact_price)){
    686                             $price = wc_price($product->get_regular_price());
    687                         }else {
    688                             $price = "";
    689                         }
    690                         $regular_price_color = $fbtpfw_comman['regular_price_color'];
    691                         echo ' &ndash; <span class="fbtpfw_price_old">' . $price. '</span><span class="fbtpfw_price_new" style="color:'.esc_attr($regular_price_color).';">('. wc_price($current_product_exact_price) .')</span>';
    692 
    693                         $productaaaaa = wc_get_product( get_the_ID() );
    694                         if($productaaaaa->get_type() == 'variable'){
    695                             $attributesqwqww = $productaaaaa->get_variation_attributes();
    696                             $available_variations = $productaaaaa->get_available_variations();
    697                             if( $current_product_is_variation ) {
    698                                 if ( is_array( $attributesqwqww ) && ( count( $attributesqwqww ) > 0 ) ) {
    699                                     echo "<div class='oc_cust_variation' currentproid=".get_the_id().">";
    700 
    701                                     if ( is_array( $attributes ) && ( count( $attributes ) > 0 ) ) {
    702                                         echo '<div class="variations_form" data-product_id="' . absint( get_the_id() ) . '" data-product_variations="' . htmlspecialchars( wp_json_encode( $available_variations ) ) . '">';
    703                                         echo '<div class="variations">';
    704                                         foreach ( $attributesqwqww as $attribute_name => $options ) { ?>
    705                                             <div class="variation">
    706                                                 <div class="label">
    707                                                     <?php echo wc_attribute_label( $attribute_name ); ?>
    708                                                 </div>
    709                                                 <div class="select">
    710                                                     <?php
    711                                                     $selected = isset( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ? wc_clean( stripslashes( urldecode( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ) ) : $productaaaaa->get_variation_default_attribute( $attribute_name );
    712                                                         wc_dropdown_variation_attribute_options( array(
    713                                                             'options'          => $options,
    714                                                             'attribute'        => $attribute_name,
    715                                                             'product'          => $productaaaaa,
    716                                                             'selected'         => $selected,
    717                                                         ) );
    718                                                     ?>
    719                                                 </div>
    720                                             </div>
    721                                         <?php }
    722                                         echo '<div class="reset">' . apply_filters( 'woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . fbtpfw_localization( 'clear', esc_html__( 'Clear', 'frequently-bought-together-product-for-woocommmerce' ) ) . '</a>' ) . '</div>';
    723                                         echo '</div>';
    724                                         echo '</div>';
    725                                         echo "</div>";
    726                                     }
    727                                 }
    728                             }
    729                         }
    730                     ?>
    731                 </li>
    732                 <?php
    733                 $product_details .= ob_get_clean();
    734                 // increment total
    735                 $total += floatval( $current_product_exact_price );
    736                 $badge = '';
    737                 $count++;
    738             }
    739             ?>
    740             <input type="hidden" name="formate" value="<?php echo esc_attr(get_woocommerce_currency_symbol()); ?>" class="formate">
    741             <input type="hidden" name="layout" value="layout2" class="layout">
    742             <div class="fbtpfw_main layout2">
    743                 <form class="fbtpfw_product_form" method="post" action="">
    744                     <?php $fbtpfw_product_color = $fbtpfw_comman['fbtpfw_product_color']; ?>
    745                     <h3 style="color:<?php echo esc_attr($fbtpfw_product_color); ?>" ><?php echo esc_attr(get_post_meta( get_the_ID(), 'occp_head_txt', true )); ?></h3>
    746                     <table class="fbtpfw_product_images">
    747                         <tbody>
    748                             <tr>
    749                                 <?php echo $images;  ?>
    750                                
    751                             </tr>
    752                         </tbody>
    753                     </table>
    754                     <div class="fbtpfw_cart_div">
    755                         <div class="fbtpfw_price">
    756                              <?php $price_all_text_color = $fbtpfw_comman['price_all_text_color']; ?>
    757                             <span class="fbtpfw_price_label" style="color:<?php echo esc_attr($price_all_text_color);  ?>">
    758                                 <?php $price_for_all_text = $fbtpfw_comman['price_for_all_text']; ?>
    759                                 <?php echo esc_attr($price_for_all_text)." : ";
    760                                 ?>
    761                             </span>
    762                             &nbsp;
    763                             <span class="fbtpfw_price_total" data-total="<?php echo esc_attr($total); ?>">
    764                                 <?php echo wc_price( $total ); ?>
    765                             </span>
    766                         </div>
    767                         <?php $add_to_cart_text =$fbtpfw_comman['add_to_cart_text']; ?>
    768                         <?php $add_cart_back_color =  $fbtpfw_comman['add_cart_back_color']; ?>
    769                         <?php $add_cart_text_color = $fbtpfw_comman['add_cart_text_color']; ?>
    770                         <input type="submit" style="color:<?php echo esc_attr($add_cart_text_color); ?>;background: <?php echo esc_attr($add_cart_back_color); ?>" class="occp_add_cart_button button" value="<?php echo esc_attr($add_to_cart_text); ?>" name="occp_add_to_cart">
    771                     </div>
    772 
    773                     <ul class="fbtpfw_ul">
    774                         <?php echo $product_details;  ?>
    775                     </ul>       
    776                 </form>
    777             </div>
    778             <?php
    779         }
    780     }
    781    
    782    
    783 }
    784 
    785 function relared_upsells_common_func($pro_id){
    786     global $fbtpfw_comman;
    787     $default_products = $fbtpfw_comman['default_products'];
    788     if ($default_products == 'upsells') {
    789         $productaaa = new WC_Product($pro_id);
    790         $upsells = $productaaa->get_upsell_ids();
    791         if (!$upsells){
    792             return;
    793         }
    794         $meta_query = WC()->query->get_meta_query();
    795         $args = array(
    796             'post_type' => 'product',
    797             'ignore_sticky_posts' => 1,
    798             'no_found_rows' => 1,
    799             'posts_per_page' => -1,
    800             'post__in' => $upsells,
    801             'post__not_in' => array($productaaa->id),
    802             'meta_query' => $meta_query
    803         );
    804         $products = new WP_Query($args);
    805         $product = $products->posts;
    806         //$main_productpost = get_post( get_the_ID() );
    807         array_unshift($product, get_the_ID());
    808         echo fbtpfw_add_display_default_product($product);
    809     }elseif ($default_products == 'related') {
    810         $terms = wp_get_post_terms( $pro_id, 'product_cat' );
    811         foreach ( $terms as $term ) {
    812             $children = get_term_children( $term->term_id, 'product_cat' );
    813             if ( !sizeof( $children ) )
    814             $cats_array[] = $term->term_id;
    815         }
    816         $args = apply_filters( 'woocommerce_related_products_args', array(
    817             'post_type' => 'product',
    818             'post__not_in' => array( $pro_id ),
    819             'ignore_sticky_posts' => 1,
    820             'no_found_rows' => 1,
    821             'posts_per_page' => -1,
    822             'tax_query' => array(
    823                 array(
    824                     'taxonomy' => 'product_cat',
    825                     'field' => 'id',
    826                     'terms' => $cats_array
    827                 ),
    828             )
    829         ));
    830         $products = new WP_Query( $args );
    831         $product = $products->posts;
    832         $main_productpost = get_post( get_the_ID() );
    833         array_unshift($product, $main_productpost);
    834         echo fbtpfw_add_display_default_product($product);
    835     }elseif ($default_products == 'none'){
    836         $product = '';
    837     }
    838 }
    839 
    840 /*design for shortcode*/
    841 add_shortcode( 'Woo_Frequently_added', 'fbtpfw_woo_combo');
    842 function fbtpfw_woo_combo($atts, $content = null) {
    843       global $fbtpfw_comman;
    844     ob_start();
    845 
    846     $page_security = get_queried_object();
    847     if(get_post_meta( $page_security->ID, 'occp_layout', true ) == "none"){
    848         $product = get_post_meta( get_the_ID(), 'occp_select2', true );
    849         if (empty($product)) {
    850             $pro_id = get_the_ID();
    851             echo relared_upsells_common_func($pro_id);
    852         }
    853 
    854         $occp_count = count($product);
    855         $occp_badge = 'true';
    856 
    857         if(wp_is_mobile()) {
    858             if($occp_count > 2) {
    859                 $occp_badge = 'false';
    860             }
    861         }
    862 
    863         $occp_discunt = get_post_meta( get_the_ID(), 'occp_off_per', true );
    864         $occp_discunt_type = get_post_meta( get_the_ID(), 'occp_discount_type', true );
    865 
    866         if(empty($product)) {
    867             return;
    868         }
    869 
    870         $main_product = wc_get_product( get_the_ID() );
    871         if( $main_product->has_child() ) {
    872             $product_variable = new WC_Product_Variable( get_the_ID() );
    873             $variations = $product_variable->get_available_variations();
    874             $vari = 0;
    875             foreach ($variations as $variation) {
    876                 $vari++;
    877                 if($vari == 1){
    878                     if (in_array($variation['variation_id'], $product)){
    879                
    880                     }else{
    881                         array_unshift($product,$variation['variation_id']);
    882                     }
    883                 }
    884             }
    885         } else {
    886             array_unshift($product, get_the_ID());
    887         }
    888         $count = 0;
    889         $badge = '';
    890         $product_details = '';
    891         $total= 0;
    892         $images = '';
    893 
    894         foreach ($product as $productId) {
    895             $product = wc_get_product( $productId );
    896             $current_product_link = $product->get_permalink();
    897             $current_product_image = $product->get_image();
    898             $current_product_title = $product->get_title();
    899             $current_product_price = $product->get_price();
    900             $current_product_id = $product->get_id();
    901             $current_product_is_variation   = $product->is_type( 'variation' );
    902             $current_product_discount='';
    903             $current_product_discount_type='';
    904             if(!empty($occp_discunt[$current_product_id])) {
    905                 $current_product_discount = $occp_discunt[$current_product_id];
    906             }
    907             if(!empty($occp_discunt_type[$current_product_id])) {
    908                 $current_product_discount_type = $occp_discunt_type[$current_product_id];
    909             }
     295            </div>';
    910296           
    911             $current_product_exact_price = fbtpfw_get_price($current_product_price, $current_product_discount, $current_product_discount_type);
    912 
    913             $dis_type = get_post_meta( get_the_ID(), 'occp_discount_type' );
    914             $dis_amt = get_post_meta( get_the_ID(), 'occp_off_per' );
    915             $discount_badge_text_color = $fbtpfw_comman['discount_badge_text_color'];
    916             $discount_badge_back_color = $fbtpfw_comman['discount_badge_back_color'];;
    917                            
    918             if(!empty($dis_amt[0][$current_product_id])) {
    919                 if(get_option('woocommerce_currency_pos') == 'left' || get_option('woocommerce_currency_pos') == 'left_space'){
    920                     if($dis_type[0][$current_product_id] == "percentage") {
    921                         $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].' %</span></div>';
    922                     }else if($dis_type[0][$current_product_id] == "fixed") {
    923                         $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.get_woocommerce_currency_symbol().$dis_amt[0][$current_product_id].'</span></div>';
    924                     }
    925                 }else{
    926                     if($dis_type[0][$current_product_id] == "percentage") {
    927                         $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].' %</span></div>';
    928                     }else if($dis_type[0][$current_product_id] == "fixed") {
    929                         $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].get_woocommerce_currency_symbol(). '</span></div>';
    930                     }
    931                 }
    932             }
    933 
    934             if($occp_badge == 'true') {
    935                 $badge = $badge;
     297
     298            if ( $count < $occp_count ) {
     299                $isimplfirst = ( $count == 0 ) ? 'fbtpfw_img_plus_first' : '';
     300                $images     .= '<div class="fbtpfw_img_plus ' . $isimplfirst . '" fbtpfw_imgpls_id="' . esc_attr( $current_product_id ) . '">+</div>';
     301            }
     302
     303            // Product details list item
     304            $item_html  = '<li class="fbtpfw_each_item">';
     305            $item_html .= '<input type="checkbox" name="proID[]" id="proID_' . esc_attr( $count ) . '" class="product_check" value="' . esc_attr( $current_product_id ) . '" price="' . esc_attr( $current_product_exact_price ) . '"';
     306
     307            $check_default_pro = $fbtpfw_comman['check_default_pro'];
     308            if ( $count == 0 ) {
     309                $item_html .= ' checked style="opacity:.6;pointer-events:none;"';
     310            } elseif ( $check_default_pro == 'yes' ) {
     311                $item_html .= ' checked';
     312            }
     313            $item_html .= ' />';
     314
     315            $item_html .= '<span class="fbtpfw_product_title">';
     316            $this_item_text = $fbtpfw_comman['this_item_text'];
     317            if ( $count == 0 ) {
     318                $item_html .= esc_html( $this_item_text . ' : ' . $current_product_title );
    936319            } else {
    937                 $badge = '';
    938             }
    939 
    940             $images .= '<td class="fbtpfw_img" image_pro_id="'.$current_product_id.'"><div class="fbtpfw_img_div"><a href="' . $current_product_link . '">' . $current_product_image . '</a>'.$badge.'</div></td>';
    941 
    942             if( $count < $occp_count ) {
    943                 $isimplfirst = '';
    944                 if($count == 0) {
    945                     $isimplfirst = 'fbtpfw_img_plus_first';
    946                 }
    947                 $images .= '<td class="fbtpfw_img_plus '.$isimplfirst.'" fbtpfw_imgpls_id="'.$current_product_id.'">+</td>';
    948             }
    949            
    950             ob_start();
    951             $check_default_pro = $fbtpfw_comman['check_default_pro'];
    952             ?>
    953             <li class="fbtpfw_each_item">
    954                 <input type="checkbox" name="proID[]" id="proID_<?php echo esc_attr($count) ?>" class="product_check" value="<?php echo esc_attr($current_product_id); ?>" price="<?php echo esc_attr($current_product_exact_price); ?>" <?php if($count == 0) { echo 'checked style="opacity: .6;pointer-events: none;"'; }elseif($check_default_pro == 'yes'){echo "checked";} ?> />
    955                 <span class="fbtpfw_product_title">
    956                     <?php $this_item_text = $fbtpfw_comman['this_item_text'];  ?>
    957                     <?php
    958                     if($count == 0) {
    959                         echo esc_attr($this_item_text.' : '.$current_product_title);
    960                     } else {
    961                         echo '<a href="'.esc_url($current_product_link).'">'.esc_attr($current_product_title).'</a>';
    962                     }
    963                     ?>
    964                 </span>
    965                 <?php
    966                     if( $current_product_is_variation ) {
    967                         $attributes = $product->get_variation_attributes();
    968                         $variations = array();
    969 
    970                         foreach( $attributes as $key => $attribute ) {
    971                             $variations[] = $attribute;
    972                         }
    973 
    974                         if( ! empty( $variations ) ){
    975                             echo '<span class="product-attributes"> &ndash; ' . esc_attr(implode( ', ', $variations )) . '</span>';
    976                         }
    977 
    978                     }
    979                    
    980                     if(!empty($product->get_price())) {
    981                         $price = wc_price($product->get_price());
    982                     }else {
    983                         $price = wc_price(0);
    984                     }
    985                     if(!empty($product->get_sale_price())) {
    986                         $price = wc_price($product->get_regular_price());
    987                     }elseif(!empty($current_product_exact_price)){
    988                         $price = wc_price($product->get_regular_price());
    989                     }else {
    990                         $price = "";
    991                     }
    992                     $regular_price_color =$fbtpfw_comman['regular_price_color'];
    993                     echo ' &ndash; <span class="fbtpfw_price_old">' . $price . '</span><span class="fbtpfw_price_new" style="color:'.esc_attr($regular_price_color).';">('. wc_price($current_product_exact_price) .')</span>';
    994 
    995                     $productaaaaa = wc_get_product( get_the_ID() );
    996                     if($productaaaaa->get_type() == 'variable'){
    997                         $attributesqwqww = $productaaaaa->get_variation_attributes();
    998                         $available_variations = $productaaaaa->get_available_variations();
    999                         if( $current_product_is_variation ) {
    1000                             if ( is_array( $attributesqwqww ) && ( count( $attributesqwqww ) > 0 ) ) {
    1001                                 echo "<div class='oc_cust_variation' currentproid=".get_the_id().">";
    1002 
    1003                                 if ( is_array( $attributes ) && ( count( $attributes ) > 0 ) ) {
    1004                                     echo '<div class="variations_form" data-product_id="' . absint( get_the_id() ) . '" data-product_variations="' . htmlspecialchars( wp_json_encode( $available_variations ) ) . '">';
    1005                                     echo '<div class="variations">';
    1006                                     foreach ( $attributesqwqww as $attribute_name => $options ) { ?>
    1007                                         <div class="variation">
    1008                                             <div class="label">
    1009                                                 <?php echo wc_attribute_label( $attribute_name ); ?>
    1010                                             </div>
    1011                                             <div class="select">
    1012                                                 <?php
    1013                                                 $selected = isset( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ? wc_clean( stripslashes( urldecode( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ) ) : $productaaaaa->get_variation_default_attribute( $attribute_name );
    1014                                                     wc_dropdown_variation_attribute_options( array(
    1015                                                         'options'          => $options,
    1016                                                         'attribute'        => $attribute_name,
    1017                                                         'product'          => $productaaaaa,
    1018                                                         'selected'         => $selected,
    1019                                                     ) );
    1020                                                 ?>
    1021                                             </div>
    1022                                         </div>
    1023                                     <?php }
    1024                                     echo '<div class="reset">' . apply_filters( 'woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' .fbtpfw_localization( 'clear', esc_html__( 'Clear', 'frequently-bought-together-product-for-woocommmerce' ) ) . '</a>' ) . '</div>';
    1025                                     echo '</div>';
    1026                                     echo '</div>';
    1027                                     echo "</div>";
    1028                                 }
    1029                             }
    1030                         }
    1031                     }
    1032                 ?>
    1033             </li>
    1034             <?php
    1035             $product_details .= ob_get_clean();
    1036             // increment total
     320                $item_html .= '<a href="' . esc_url( $current_product_link ) . '">' . esc_html( $current_product_title ) . '</a>';
     321            }
     322            $item_html .= '</span>';
     323
     324            // Price
     325            $regular_price_color = $fbtpfw_comman['regular_price_color'];
     326            $price_old           = ( $product_obj->get_sale_price() || $current_product_exact_price ) ? wc_price( $product_obj->get_regular_price() ) : '';
     327            $item_html          .= ' &ndash; <span class="fbtpfw_price_old">' . $price_old . '</span><span class="fbtpfw_price_new" style="color:' . esc_attr( $regular_price_color ) . ';">(' . wc_price( $current_product_exact_price ) . ')</span>';
     328
     329            $item_html .= '</li>';
     330
     331            $product_details .= $item_html;
     332
    1037333            $total += floatval( $current_product_exact_price );
    1038             $badge = '';
    1039334            $count++;
    1040335        }
    1041         ?>
    1042         <input type="hidden" name="formate" value="<?php echo esc_attr(get_woocommerce_currency_symbol()); ?>" class="formate">
    1043         <input type="hidden" name="layout" value="layout2" class="layout">
    1044         <div class="fbtpfw_main layout2">
    1045             <form class="fbtpfw_product_form" method="post" action="">
    1046                 <?php $fbtpfw_product_color = $fbtpfw_comman['fbtpfw_product_color']; ?>
    1047                 <h3 style="color:<?php echo esc_attr($fbtpfw_product_color); ?>" ><?php echo esc_attr(get_post_meta( get_the_ID(), 'occp_head_txt', true )); ?></h3>
    1048                 <table class="fbtpfw_product_images">
    1049                     <tbody>
    1050                         <tr>
    1051                             <?php echo esc_attr($images);?>
    1052                            
    1053                         </tr>
    1054                     </tbody>
    1055                 </table>
    1056                 <div class="fbtpfw_cart_div">
    1057                     <div class="fbtpfw_price">
    1058                          <?php $addtional_amount_text_color = $fbtpfw_comman['addtional_amount_text_color']; ?>
    1059                         <span class="fbtpfw_price_label" style="color:<?php echo esc_attr($addtional_amount_text_color);  ?>">
    1060                             <?php $price_for_all_text = $fbtpfw_comman['price_for_all_text']; ?>
    1061                             <?php echo esc_attr($price_for_all_text)." : ";
    1062                             ?>
    1063                         </span>
    1064                         &nbsp;
    1065                         <span class="fbtpfw_price_total" data-total="<?php echo esc_attr($total); ?>">
    1066                             <?php echo wc_price( $total ); ?>
    1067                         </span>
    1068                     </div>
    1069                     <?php $add_to_cart_text = $fbtpfw_comman['add_to_cart_text']; ?>
    1070                     <?php $add_cart_back_color =  $fbtpfw_comman['add_cart_back_color']; ?>
    1071                     <?php $add_cart_text_color = $fbtpfw_comman['add_cart_text_color']; ?>
    1072                     <input type="submit" style="color:<?php echo esc_attr($add_cart_text_color); ?>;background: <?php echo esc_attr($add_cart_back_color); ?>" class="occp_add_cart_button button" value="<?php echo esc_attr($add_to_cart_text); ?>" name="occp_add_to_cart">
    1073                 </div>
    1074 
    1075                 <ul class="fbtpfw_ul">
    1076                     <?php echo $product_details;?>
    1077                 </ul>       
    1078             </form>
    1079         </div>
    1080         <?php
    1081         }
    1082         $content = ob_get_clean();
    1083         return $content;
     336
     337        // Final HTML
     338        $output  = '<input type="hidden" name="formate" value="' . esc_attr( get_woocommerce_currency_symbol() ) . '" class="formate">';
     339        $output .= '<input type="hidden" name="layout" value="layout2" class="layout">';
     340
     341        $output .= '<div class="fbtpfw_main layout2">';
     342        $output .= '<form class="fbtpfw_product_form" method="post" action="">';
     343        // $output .= '<h3 style="color:' . esc_attr( $fbtpfw_comman['fbtpfw_product_color'] ) . '">' . esc_html( get_post_meta( get_the_ID(), 'occp_head_txt', true ) ) . '</h3>';
     344        $output .= '<h3 style="color:' . esc_attr( $fbtpfw_comman['fbtpfw_product_color'] ) . '">' . esc_html($fbtpfw_comman['Heading_text']) . '</h3>';
     345
     346        // $output .= '<table class="fbtpfw_product_images"><tbody><tr>' . $images . '</tr></tbody></table>';
     347        $output .= '<div class="fbtpfw_product_images">';
     348        $output .= $images;
     349        $output .= '</div>';
     350
     351        $output .= '<div class="fbtpfw_cart_div">';
     352        $output .= '<div class="fbtpfw_price">';
     353        $output .= '<span class="fbtpfw_price_label" style="color:' . esc_attr( $fbtpfw_comman['price_all_text_color'] ) . '">' . esc_html( $fbtpfw_comman['price_for_all_text'] ) . ' :&nbsp;</span>';
     354        $output .= '<span class="fbtpfw_price_total" data-total="' . esc_attr( $total ) . '">' . wc_price( $total ) . '</span>';
     355        $output .= '</div>';
     356        if ( $show_button === 'yes' ){
     357            // $output .= '<input type="submit" style="color:' . esc_attr( $fbtpfw_comman['add_cart_text_color'] ) . ';background:' . esc_attr( $fbtpfw_comman['add_cart_back_color'] ) . '" class="occp_add_cart_button button" value="' . esc_attr( $fbtpfw_comman['add_to_cart_text'] ) . '" name="occp_add_to_cart">';
     358            $output .= '<button type="submit" name="occp_add_to_cart" class="single_add_to_cart_button button alt wp-element-button">' . esc_html( $fbtpfw_comman['add_to_cart_text'] ) . '</button>';
     359        }
     360        $output .= '</div>';
     361
     362        $output .= '<ul class="fbtpfw_ul">' . $product_details . '</ul>';
     363
     364        $output .= '</form></div>';
     365
     366        return $output;
     367    }
     368
     369    return '';
    1084370}
    1085371
     
    1103389
    1104390
    1105 add_filter( 'woocommerce_add_cart_item_data',  'fbtpfw_add_cart_item_data', 10, 3 );
    1106 function fbtpfw_add_cart_item_data( $cart_item_data, $product_id ) {
    1107     if(isset($_POST['proID']) && !empty($_POST['proID'])) {
    1108         $fbtpfw_combo_ids =  fbtpfw_recursive_sanitize_text_field($_POST['proID']);
    1109     }
     391// add_filter( 'woocommerce_add_cart_item_data',  'fbtpfw_add_cart_item_data', 10, 3 );
     392// function fbtpfw_add_cart_item_data( $cart_item_data, $product_id ) {
     393//     if(isset($_POST['proID']) && !empty($_POST['proID'])) {
     394//         $fbtpfw_combo_ids =  fbtpfw_recursive_sanitize_text_field($_POST['proID']);
     395//     }
    1110396   
    1111     if( empty( $fbtpfw_combo_ids ) ) {
    1112         return;
    1113     }
     397//     if( empty( $fbtpfw_combo_ids ) ) {
     398//         return;
     399//     }
    1114400   
    1115     if ( ! empty( $fbtpfw_combo_ids ) ) {
    1116         $cart_item_data['combo_ids'] = $fbtpfw_combo_ids;
    1117     }
    1118 
    1119     return $cart_item_data;
    1120 }
     401//     if ( ! empty( $fbtpfw_combo_ids ) ) {
     402//         $cart_item_data['combo_ids'] = $fbtpfw_combo_ids;
     403//     }
     404
     405//     return $cart_item_data;
     406// }
    1121407
    1122408
    1123409/*add to cart for layout1*/
    1124 add_action( 'woocommerce_add_to_cart', 'fbtpfw_add_to_cart' , 10, 6 );
    1125 function fbtpfw_add_to_cart( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) {
     410// add_action( 'woocommerce_add_to_cart', 'fbtpfw_add_to_cart' , 10, 6 );
     411// function fbtpfw_add_to_cart( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) {
    1126412   
    1127     if ( isset( $cart_item_data['combo_ids'] ) && $cart_item_data['combo_ids'] != '' ) {
    1128 
    1129         $fbtpfwitems = $cart_item_data['combo_ids'];
    1130 
    1131         remove_action( 'woocommerce_add_to_cart', 'fbtpfw_add_to_cart', 10, 6 );
    1132 
    1133         foreach ($fbtpfwitems as $keya => $valuea) {
    1134             $occp_product = wc_get_product( $valuea );
    1135             if ( $occp_product && $occp_product->is_in_stock() && $occp_product->is_purchasable() ) {
    1136                 $cart_item_keya = WC()->cart->add_to_cart($valuea, 1, 0, array(), array("fbtpfw_parent_id" => $product_id, "fbtpfw_parent_key" => $cart_item_key) );
    1137                 if ( $cart_item_keya ) {
    1138                     WC()->cart->cart_contents[ $cart_item_key ]['fbtpfw_child_keys'][] = $cart_item_keya;
    1139                 }
    1140             }
    1141         }
    1142     }
    1143 }
     413//     if ( isset( $cart_item_data['combo_ids'] ) && $cart_item_data['combo_ids'] != '' ) {
     414
     415//         $fbtpfwitems = $cart_item_data['combo_ids'];
     416
     417//         remove_action( 'woocommerce_add_to_cart', 'fbtpfw_add_to_cart', 10, 6 );
     418
     419//         foreach ($fbtpfwitems as $keya => $valuea) {
     420//             $occp_product = wc_get_product( $valuea );
     421//             if ( $occp_product && $occp_product->is_in_stock() && $occp_product->is_purchasable() ) {
     422//                 $cart_item_keya = WC()->cart->add_to_cart($valuea, 1, 0, array(), array("fbtpfw_parent_id" => $product_id, "fbtpfw_parent_key" => $cart_item_key) );
     423//                 if ( $cart_item_keya ) {
     424//                     WC()->cart->cart_contents[ $cart_item_key ]['fbtpfw_child_keys'][] = $cart_item_keya;
     425//                 }
     426//             }
     427//         }
     428//     }
     429// }
    1144430
    1145431
     
    1249535add_filter( 'woocommerce_order_item_name', 'fbtpfw_bought_together_item_name', 10, 2 );
    1250536function fbtpfw_bought_together_item_name( $item_name, $item ) {
     537    global $fbtpfw_comman;
    1251538
    1252539    if ( isset( $item['fbtpfw_parent_id'] ) && ! empty( $item['fbtpfw_parent_id'] ) ) {
    1253540
    1254         $occp_btassociated_txt = get_post_meta( $item['fbtpfw_parent_id'], 'occp_btassociated_txt', true );
     541        // $occp_btassociated_txt = get_post_meta( $item['fbtpfw_parent_id'], 'occp_btassociated_txt', true );
     542        $occp_btassociated_txt = $fbtpfw_comman['Associated_text'];
    1255543
    1256544        if($occp_btassociated_txt != '') {
    1257             $fbtpfw_btogether_text = esc_html__( $occp_btassociated_txt, 'fbtpfw' );
     545            $fbtpfw_btogether_text = esc_html( $occp_btassociated_txt );
    1258546        } else {
    1259             $fbtpfw_btogether_text = esc_html__( '(bought together %s)', 'fbtpfw' );
     547            /* translators: %s: number of products bought together */
     548            $fbtpfw_btogether_text = esc_html__( '(bought together %s)', 'frequently-bought-together-product-for-woocommmerce' );
    1260549        }
    1261550
     
    1273562
    1274563
    1275 add_action( 'woocommerce_cart_item_removed', 'fbtpfw_cart_item_removed' , 10, 2 );
     564add_filter( 'woocommerce_rest_prepare_cart_item', function( $response, $cart_item, $request ) {
     565    // Add your custom data under extensions
     566    if ( ! empty( $cart_item['fbtpfw_parent_id'] ) ) {
     567        $response->data['extensions']['fbtpfw_parent_name'] = get_the_title( $cart_item['fbtpfw_parent_id'] );
     568    }
     569    return $response;
     570}, 10, 3 );
     571
     572
     573
     574/*add_action( 'woocommerce_cart_item_removed', 'fbtpfw_cart_item_removed' , 10, 2 );
    1276575function fbtpfw_cart_item_removed( $cart_item_key, $cart ) {
    1277576    if ( isset( $cart->removed_cart_contents[ $cart_item_key ]['fbtpfw_child_keys'] ) ) {
     
    1281580        }
    1282581    }
    1283 }
    1284 
    1285    
    1286  
     582}*/
  • frequently-bought-together-product-for-woocommerce/trunk/main/frontend/fbtpfw-layout-1.php

    r2877015 r3450808  
    11<?php
     2if ( ! defined( 'ABSPATH' ) ) exit;
     3
    24function fbtpfw_layout1() {
    3       global $fbtpfw_comman;
    4             $product = get_post_meta( get_the_ID(), 'occp_select2', true );
     5    global $fbtpfw_comman;
     6    $product = get_post_meta( get_the_ID(), 'occp_select2', true );
    57
    6             if (empty($product)) {
    7                 $pro_id = get_the_ID();
    8                 echo relared_upsells_common_func($pro_id);
     8    if (empty($product)) {
     9        $pro_id = get_the_ID();
     10        echo relared_upsells_common_func($pro_id);
     11    }
     12
     13    $occp_discunt = get_post_meta( get_the_ID(), 'occp_off_per', true );
     14    $occp_discunt_type = get_post_meta( get_the_ID(), 'occp_discount_type', true );
     15    if(empty($product)) {
     16      return;
     17    }
     18    $main_product = wc_get_product( get_the_ID() );
     19    array_unshift($product, get_the_ID());
     20    $count  = 0;
     21    $badge ='';
     22    $product_details = '';
     23    $total= 0;
     24    $images = '';
     25    foreach ($product as $productId) {
     26        $product = wc_get_product( $productId );
     27
     28        $current_product_link =  $product->get_permalink();
     29        $current_product_image = $product->get_image();
     30        $current_product_title = $product->get_title();
     31        $current_product_price = $product->get_price();
     32        $current_product_id = $product->get_id();
     33        $current_product_is_variation   = $product->is_type( 'variation' );
     34        $current_product_discount='';
     35        $current_product_discount_type='';
     36        if(!empty($occp_discunt[$current_product_id])) {
     37            $current_product_discount = $occp_discunt[$current_product_id];
     38        }
     39        if(!empty($occp_discunt_type[$current_product_id])) {
     40            $current_product_discount_type = $occp_discunt_type[$current_product_id];
     41        }
     42       
     43
     44        $current_product_exact_price = fbtpfw_get_price($current_product_price, $current_product_discount, $current_product_discount_type);
     45        if($count == 0) {
     46            $current_product_exact_prices = 0;
     47        } else {
     48            $current_product_exact_prices = $current_product_exact_price;
     49        }
     50       
     51        $dis_type = get_post_meta( get_the_ID(), 'occp_discount_type' );
     52        $dis_amt = get_post_meta( get_the_ID(), 'occp_off_per' );
     53        $discount_badge_text_color =$fbtpfw_comman['discount_badge_text_color'];
     54        $discount_badge_back_color = $fbtpfw_comman['discount_badge_back_color'];;
     55
     56        if(!empty($dis_amt[0][$current_product_id])) {
     57            if(get_option('woocommerce_currency_pos') == 'left' || get_option('woocommerce_currency_pos') == 'left_space'){
     58                if($dis_type[0][$current_product_id] == "percentage") {
     59                    $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].' %</span></div>';
     60                }else if($dis_type[0][$current_product_id] == "fixed") {
     61                    $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.get_woocommerce_currency_symbol().$dis_amt[0][$current_product_id].'</span></div>';
     62                }
     63            }else{
     64                if($dis_type[0][$current_product_id] == "percentage") {
     65                    $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].' %</span></div>';
     66                }else if($dis_type[0][$current_product_id] == "fixed") {
     67                    $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].get_woocommerce_currency_symbol(). '</span></div>';
     68                }
    969            }
     70        }
    1071
    11             $occp_discunt = get_post_meta( get_the_ID(), 'occp_off_per', true );
    12             $occp_discunt_type = get_post_meta( get_the_ID(), 'occp_discount_type', true );
    13             if(empty($product)) {
    14               return;
    15             }
    16             $main_product = wc_get_product( get_the_ID() );
    17             array_unshift($product, get_the_ID());
    18             $count  = 0;
    19             $badge ='';
    20             $product_details = '';
    21             $total= 0;
    22             $images = '';
    23             foreach ($product as $productId) {
    24                 $product = wc_get_product( $productId );
     72        $images .= '<td class="fbtpfw_img" image_pro_id="'.$current_product_id.'"><div class="fbtpfw_img_div"><a href="' . $current_product_link . '">' . $current_product_image . '</a>'.$badge.'</div></td>';
     73        ob_start();
     74        $check_default_pro =  $fbtpfw_comman['check_default_pro'];
     75        ?>
     76        <div class="fbtpfw_each_item <?php if($count == 0) { echo 'fbtpfw_each_curprod'; } ?>">
     77            <div class="fbtpfw_product_check">
     78                <input type="checkbox" name="proID[]" id="proID_<?php echo esc_attr($count); ?>" class="product_check" value="<?php echo esc_attr($current_product_id); ?>" price="<?php echo esc_attr($current_product_exact_price) ; ?>" <?php if($count == 0){ echo "checked disabled"; }elseif($check_default_pro == 'yes'){echo "checked";} ?>/>
     79            </div>
    2580
    26                 $current_product_link =  $product->get_permalink();
    27                 $current_product_image = $product->get_image();
    28                 $current_product_title = $product->get_title();
    29                 $current_product_price = $product->get_price();
    30                 $current_product_id = $product->get_id();
    31                 $current_product_is_variation   = $product->is_type( 'variation' );
    32                 $current_product_discount='';
    33                 $current_product_discount_type='';
    34                 if(!empty($occp_discunt[$current_product_id])) {
    35                     $current_product_discount = $occp_discunt[$current_product_id];
    36                 }
    37                 if(!empty($occp_discunt_type[$current_product_id])) {
    38                     $current_product_discount_type = $occp_discunt_type[$current_product_id];
    39                 }
    40                
     81            <div class="fbtpfw_product_image">
     82                <?php echo wp_kses_post($product->get_image()); ?>
     83            </div>
    4184
    42                 $current_product_exact_price = fbtpfw_get_price($current_product_price, $current_product_discount, $current_product_discount_type);
    43                 if($count == 0) {
    44                     $current_product_exact_prices = 0;
    45                 } else {
    46                     $current_product_exact_prices = $current_product_exact_price;
    47                 }
    48                
    49                 $dis_type = get_post_meta( get_the_ID(), 'occp_discount_type' );
    50                 $dis_amt = get_post_meta( get_the_ID(), 'occp_off_per' );
    51                 $discount_badge_text_color =$fbtpfw_comman['discount_badge_text_color'];
    52                 $discount_badge_back_color = $fbtpfw_comman['discount_badge_back_color'];;
     85            <div class="fbtpfw_product_title">
     86                <?php $this_item_text = $fbtpfw_comman['this_item_text']; ?>
     87                <span>
     88                    <?php
     89                        if($count == 0) {
     90                            echo esc_attr($this_item_text).': '.esc_attr($current_product_title);
     91                        } else {
     92                            echo '<a href="'.esc_url($current_product_link).'">'.esc_attr($current_product_title).'</a>';
     93                        }
     94                    ?>
     95                </span>
     96                <?php
     97                    if( $current_product_is_variation ) {
     98                        $attributes = $product->get_variation_attributes();
     99                        $variations = array();
    53100
    54                 if(!empty($dis_amt[0][$current_product_id])) {
    55                     if(get_option('woocommerce_currency_pos') == 'left' || get_option('woocommerce_currency_pos') == 'left_space'){
    56                         if($dis_type[0][$current_product_id] == "percentage") {
    57                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].' %</span></div>';
    58                         }else if($dis_type[0][$current_product_id] == "fixed") {
    59                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.get_woocommerce_currency_symbol().$dis_amt[0][$current_product_id].'</span></div>';
     101                        foreach( $attributes as $key => $attribute ) {
     102                            $variations[] = $attribute;
    60103                        }
    61                     }else{
    62                         if($dis_type[0][$current_product_id] == "percentage") {
    63                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].' %</span></div>';
    64                         }else if($dis_type[0][$current_product_id] == "fixed") {
    65                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].get_woocommerce_currency_symbol(). '</span></div>';
    66                         }
     104
     105                        if( ! empty( $variations ) )
     106                        echo '<span class="product-attributes"> &ndash; ' . esc_attr(implode( ', ', $variations )) . '</span>';
    67107                    }
    68                 }
     108                ?>
     109            </div>
    69110
    70                 $images .= '<td class="fbtpfw_img" image_pro_id="'.$current_product_id.'"><div class="fbtpfw_img_div"><a href="' . $current_product_link . '">' . $current_product_image . '</a>'.$badge.'</div></td>';
    71                 ob_start();
    72                 $check_default_pro =  $fbtpfw_comman['check_default_pro'];
     111            <div class="fbtpfw_product_price">
     112                <?php
     113                    if(!empty($product->get_sale_price())) {
     114                        $price = wc_price($product->get_regular_price());
     115                    }elseif(!empty($current_product_exact_price)){
     116                        $price = wc_price($product->get_regular_price());
     117                    }else {
     118                        $price = "";
     119                    }
     120                    $regular_price_color = $fbtpfw_comman['regular_price_color'];
     121                    echo '<span class="fbtpfw_price_old">' . wp_kses_post($price) . '</span><span class="fbtpfw_price_new" style="color:'.esc_attr($regular_price_color).';">('. wp_kses_post(wc_price($current_product_exact_price)) .')</span>';
    73122                ?>
    74                 <div class="fbtpfw_each_item <?php if($count == 0) { echo 'fbtpfw_each_curprod'; } ?>">
    75                     <div class="fbtpfw_product_check">
    76                         <input type="checkbox" name="proID[]" id="proID_<?php echo esc_attr($count); ?>" class="product_check" value="<?php echo esc_attr($current_product_id); ?>" price="<?php echo esc_attr($current_product_exact_price) ; ?>" <?php if($count == 0){ echo "checked disabled"; }elseif($check_default_pro == 'yes'){echo "checked";} ?>/>
    77                     </div>
     123            </div>
     124        </div>
     125        <?php
     126        $product_details .= ob_get_clean();
     127        // increment total
     128        $total += floatval( $current_product_exact_prices );
     129        $count++;
     130    }
     131    ?>
    78132
    79                     <div class="fbtpfw_product_image">
    80                         <?php echo $product->get_image();?>
    81                     </div>
    82 
    83                     <div class="fbtpfw_product_title">
    84                         <?php $this_item_text = $fbtpfw_comman['this_item_text']; ?>
    85                         <span>
    86                             <?php
    87                             if($count == 0) {
    88                                 echo esc_attr($this_item_text).': '.esc_attr($current_product_title);
    89                             } else {
    90                                 echo '<a href="'.esc_url($current_product_link).'">'.esc_attr($current_product_title).'</a>';
    91                             }
    92                             ?>
    93                         </span>
    94                         <?php
    95                             if( $current_product_is_variation ) {
    96                                 $attributes = $product->get_variation_attributes();
    97                                 $variations = array();
    98 
    99                                 foreach( $attributes as $key => $attribute ) {
    100                                     $variations[] = $attribute;
    101                                 }
    102 
    103                                 if( ! empty( $variations ) )
    104                                 echo '<span class="product-attributes"> &ndash; ' . esc_attr(implode( ', ', $variations )) . '</span>';
    105                             }
    106                         ?>
    107                     </div>
    108 
    109                     <div class="fbtpfw_product_price">
    110                         <?php
    111                             if(!empty($product->get_sale_price())) {
    112                                 $price = wc_price($product->get_regular_price());
    113                             }elseif(!empty($current_product_exact_price)){
    114                                 $price = wc_price($product->get_regular_price());
    115                             }else {
    116                                 $price = "";
    117                             }
    118                             $regular_price_color = $fbtpfw_comman['regular_price_color'];
    119                             echo '<span class="fbtpfw_price_old">' . $price . '</span><span class="fbtpfw_price_new" style="color:'.esc_attr($regular_price_color).';">('. wc_price($current_product_exact_price) .')</span>';
    120                         ?>
    121                     </div>
    122                 </div>
    123                 <?php
    124                 $product_details .= ob_get_clean();
    125                 // increment total
    126                 $total += floatval( $current_product_exact_prices );
    127                 $count++;
    128             }
    129             ?>
    130 
    131             <input type="hidden" name="formate" value="<?php echo esc_attr(get_woocommerce_currency_symbol()); ?>" class="formate">
    132             <input type="hidden" name="layout" value="layout1" class="layout">
    133             <div class="fbtpfw_main layout1">
    134                  <?php $fbtpfw_product_color = $fbtpfw_comman['fbtpfw_product_color']; ?>
    135                 <h3 style="color:<?php echo esc_attr($fbtpfw_product_color); ?>"><?php echo esc_attr(get_post_meta( get_the_ID(), 'occp_head_txt', true )); ?></h3>
    136                 <div class="fbtpfw_div">
    137                     <?php echo $product_details;?>
    138                 </div>
    139                 <div class="fbtpfw_cart_div">
    140                     <div class="fbtpfw_price">
    141                          <?php $addtional_amount_text_color = $fbtpfw_comman['addtional_amount_text_color']; ?>
    142                         <span class="fbtpfw_price_label" style="color: <?php echo esc_attr($addtional_amount_text_color); ?>;">
    143                             <?php $addtional_amount_text = $fbtpfw_comman['addtional_amount_text']; ?>
    144                             <?php echo esc_attr($addtional_amount_text)." : "; ?>
    145                         </span>
    146                         &nbsp;
    147                         <span class="fbtpfw_price_total" data-total="<?php echo esc_attr($total) ?>">
    148                             <?php echo wc_price( $total ); ?>
    149                         </span>
    150                     </div>
    151                 </div>
     133    <input type="hidden" name="formate" value="<?php echo esc_attr(get_woocommerce_currency_symbol()); ?>" class="formate">
     134    <input type="hidden" name="layout" value="layout1" class="layout">
     135    <div class="fbtpfw_main layout1">
     136         <?php $fbtpfw_product_color = $fbtpfw_comman['fbtpfw_product_color']; ?>
     137        <!-- <h3 style="color:<?php // echo esc_attr($fbtpfw_product_color); ?>"><?php // echo esc_attr(get_post_meta( get_the_ID(), 'occp_head_txt', true )); ?></h3> -->
     138        <h3 style="color:<?php echo esc_attr($fbtpfw_product_color); ?>"><?php echo esc_html($fbtpfw_comman['Heading_text']); ?></h3>
     139        <div class="fbtpfw_div">
     140            <?php echo $product_details; ?>
     141        </div>
     142        <div class="fbtpfw_cart_div">
     143            <div class="fbtpfw_price">
     144                <?php $addtional_amount_text_color = $fbtpfw_comman['addtional_amount_text_color']; ?>
     145                <span class="fbtpfw_price_label" style="color: <?php echo esc_attr($addtional_amount_text_color); ?>;">
     146                    <?php $addtional_amount_text = $fbtpfw_comman['addtional_amount_text']; ?>
     147                    <?php echo esc_attr($addtional_amount_text)." : "; ?>
     148                </span>
     149                &nbsp;
     150                <span class="fbtpfw_price_total" data-total="<?php echo esc_attr($total) ?>">
     151                    <?php echo wp_kses_post(wc_price( $total )); ?>
     152                </span>
    152153            </div>
    153             <?php   
    154         }
     154        </div>
     155    </div>
     156    <?php   
     157}
  • frequently-bought-together-product-for-woocommerce/trunk/main/frontend/fbtpfw-layout-2.php

    r3262514 r3450808  
    11<?php
     2if ( ! defined( 'ABSPATH' ) ) exit;
     3
    24function fbtpfw_layout2() {
    3        global $fbtpfw_comman;
    4             $product = get_post_meta( get_the_ID(), 'occp_select2', true );
    5 
    6             if (empty($product)) {
    7                 $pro_id = get_the_ID();
    8                 echo relared_upsells_common_func($pro_id);
     5   global $fbtpfw_comman;
     6   
     7    $product = get_post_meta( get_the_ID(), 'occp_select2', true );
     8
     9    if (empty($product)) {
     10        $pro_id = get_the_ID();
     11        echo relared_upsells_common_func($pro_id);
     12    }
     13
     14    $occp_count = count((array)$product);
     15    $occp_badge = 'true';
     16
     17    if(wp_is_mobile()) {
     18        if($occp_count > 2) {
     19            $occp_badge = 'false';
     20        }
     21    }
     22
     23    $occp_discunt = get_post_meta( get_the_ID(), 'occp_off_per', true );
     24    $occp_discunt_type = get_post_meta( get_the_ID(), 'occp_discount_type', true );
     25
     26    if(empty($product)) {
     27        return;
     28    }
     29
     30    $main_product = wc_get_product( get_the_ID() );
     31    if( $main_product->has_child() ) {
     32        $product_variable = new WC_Product_Variable( get_the_ID() );
     33        $variations = $product_variable->get_available_variations();
     34        $vari = 0;
     35        foreach ($variations as $variation) {
     36            $vari++;
     37            if($vari == 1){
     38                if (in_array($variation['variation_id'], $product)){
     39           
     40                }else{
     41                    array_unshift($product,$variation['variation_id']);
     42                }
     43            }
     44        }
     45    } else {
     46        array_unshift($product, get_the_ID());
     47    }
     48    $count = 0;
     49    $badge = '';
     50    $product_details = '';
     51    $total= 0;
     52    $images = '';
     53
     54    foreach ($product as $productId) {
     55        $product = wc_get_product( $productId );
     56        $current_product_link = $product->get_permalink();
     57        $current_product_image = $product->get_image();
     58        $current_product_title = $product->get_title();
     59        $current_product_price = $product->get_price();
     60        $current_product_id = $product->get_id();
     61        $current_product_is_variation   = $product->is_type( 'variation' );
     62        $current_product_discount='';
     63        $current_product_discount_type='';
     64        if(!empty($occp_discunt[$current_product_id])) {
     65            $current_product_discount = $occp_discunt[$current_product_id];
     66        }
     67        if(!empty($occp_discunt_type[$current_product_id])) {
     68            $current_product_discount_type = $occp_discunt_type[$current_product_id];
     69        }
     70       
     71        $current_product_exact_price = fbtpfw_get_price($current_product_price, $current_product_discount, $current_product_discount_type);
     72
     73        $dis_type = get_post_meta( get_the_ID(), 'occp_discount_type' );
     74        $dis_amt = get_post_meta( get_the_ID(), 'occp_off_per' );
     75        $discount_badge_text_color = $fbtpfw_comman['discount_badge_text_color'];
     76        $discount_badge_back_color = $fbtpfw_comman['discount_badge_back_color'];;
     77                       
     78        if(!empty($dis_amt[0][$current_product_id])) {
     79            if(get_option('woocommerce_currency_pos') == 'left' || get_option('woocommerce_currency_pos') == 'left_space'){
     80                if($dis_type[0][$current_product_id] == "percentage") {
     81                    $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].' %</span></div>';
     82                }else if($dis_type[0][$current_product_id] == "fixed") {
     83                    $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.get_woocommerce_currency_symbol().$dis_amt[0][$current_product_id].'</span></div>';
     84                }
     85            }else{
     86                if($dis_type[0][$current_product_id] == "percentage") {
     87                    $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].' %</span></div>';
     88                }else if($dis_type[0][$current_product_id] == "fixed") {
     89                    $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].get_woocommerce_currency_symbol(). '</span></div>';
     90                }
    991            }
    10 
    11             $occp_count = count((array)$product);
    12             $occp_badge = 'true';
    13 
    14             if(wp_is_mobile()) {
    15                 if($occp_count > 2) {
    16                     $occp_badge = 'false';
    17                 }
     92        }
     93
     94        if($occp_badge == 'true') {
     95            $badge = $badge;
     96        } else {
     97            $badge = '';
     98        }
     99
     100        $images .= '<div class="fbtpfw_img" image_pro_id="'.$current_product_id.'">
     101        <div class="fbtpfw_img_div">
     102            <a href="' . $current_product_link . '">' . $current_product_image . '</a>
     103            '.$badge.'
     104        </div>
     105        </div>';
     106
     107        if( $count < $occp_count ) {
     108            $isimplfirst = '';
     109            if($count == 0) {
     110                $isimplfirst = 'fbtpfw_img_plus_first';
    18111            }
    19 
    20             $occp_discunt = get_post_meta( get_the_ID(), 'occp_off_per', true );
    21             $occp_discunt_type = get_post_meta( get_the_ID(), 'occp_discount_type', true );
    22 
    23             if(empty($product)) {
    24                 return;
    25             }
    26 
    27             $main_product = wc_get_product( get_the_ID() );
    28             if( $main_product->has_child() ) {
    29                 $product_variable = new WC_Product_Variable( get_the_ID() );
    30                 $variations = $product_variable->get_available_variations();
    31                 $vari = 0;
    32                 foreach ($variations as $variation) {
    33                     $vari++;
    34                     if($vari == 1){
    35                         if (in_array($variation['variation_id'], $product)){
    36                    
    37                         }else{
    38                             array_unshift($product,$variation['variation_id']);
    39                         }
    40                     }
    41                 }
    42             } else {
    43                 array_unshift($product, get_the_ID());
    44             }
    45             $count = 0;
    46             $badge = '';
    47             $product_details = '';
    48             $total= 0;
    49             $images = '';
    50 
    51             foreach ($product as $productId) {
    52                 $product = wc_get_product( $productId );
    53                 $current_product_link = $product->get_permalink();
    54                 $current_product_image = $product->get_image();
    55                 $current_product_title = $product->get_title();
    56                 $current_product_price = $product->get_price();
    57                 $current_product_id = $product->get_id();
    58                 $current_product_is_variation   = $product->is_type( 'variation' );
    59                 $current_product_discount='';
    60                 $current_product_discount_type='';
    61                 if(!empty($occp_discunt[$current_product_id])) {
    62                     $current_product_discount = $occp_discunt[$current_product_id];
    63                 }
    64                 if(!empty($occp_discunt_type[$current_product_id])) {
    65                     $current_product_discount_type = $occp_discunt_type[$current_product_id];
    66                 }
    67                
    68                 $current_product_exact_price = fbtpfw_get_price($current_product_price, $current_product_discount, $current_product_discount_type);
    69 
    70                 $dis_type = get_post_meta( get_the_ID(), 'occp_discount_type' );
    71                 $dis_amt = get_post_meta( get_the_ID(), 'occp_off_per' );
    72                 $discount_badge_text_color = $fbtpfw_comman['discount_badge_text_color'];
    73                 $discount_badge_back_color = $fbtpfw_comman['discount_badge_back_color'];;
    74                                
    75                 if(!empty($dis_amt[0][$current_product_id])) {
    76                     if(get_option('woocommerce_currency_pos') == 'left' || get_option('woocommerce_currency_pos') == 'left_space'){
    77                         if($dis_type[0][$current_product_id] == "percentage") {
    78                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].' %</span></div>';
    79                         }else if($dis_type[0][$current_product_id] == "fixed") {
    80                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.get_woocommerce_currency_symbol().$dis_amt[0][$current_product_id].'</span></div>';
    81                         }
    82                     }else{
    83                         if($dis_type[0][$current_product_id] == "percentage") {
    84                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].' %</span></div>';
    85                         }else if($dis_type[0][$current_product_id] == "fixed") {
    86                             $badge = '<div class="fbtpfw_badge" style="border:2px solid '.$discount_badge_back_color.';"><span style="color:'.$discount_badge_text_color.';background:'.$discount_badge_back_color.';"><p>off</p>- '.$dis_amt[0][$current_product_id].get_woocommerce_currency_symbol(). '</span></div>';
     112            $images .= '<div class="fbtpfw_img_plus '.$isimplfirst.'" fbtpfw_imgpls_id="'.$current_product_id.'">+</div>';
     113        }
     114       
     115        ob_start();
     116        $check_default_pro = $fbtpfw_comman['check_default_pro'];
     117        ?>
     118        <li class="fbtpfw_each_item">
     119            <input type="checkbox" name="proID[]" id="proID_<?php echo esc_attr($count) ?>" class="product_check" value="<?php echo esc_attr($current_product_id); ?>" price="<?php echo esc_attr($current_product_exact_price); ?>" <?php if($count == 0) { echo 'checked style="opacity: .6;pointer-events: none;"'; }elseif($check_default_pro == 'yes'){echo "checked";} ?> />
     120            <span class="fbtpfw_product_title">
     121                <?php $this_item_text = $fbtpfw_comman['this_item_text']; ?>
     122                <?php
     123                if($count == 0) {
     124                    echo esc_attr($this_item_text.' : '.$current_product_title);
     125                } else {
     126                    echo '<a href="'.esc_url($current_product_link).'">'.esc_attr($current_product_title).'</a>';
     127                }
     128                ?>
     129            </span>
     130            <?php
     131                if( $current_product_is_variation ) {
     132                    $attributes = $product->get_variation_attributes();
     133                    $variations = array();
     134
     135                    foreach( $attributes as $key => $attribute ) {
     136                        $variations[] = $attribute;
     137                    }
     138
     139                    if( ! empty( $variations ) ){
     140                        echo '<span class="product-attributes"> &ndash; ' . esc_attr(implode( ', ', $variations )) . '</span>';
     141                    }
     142                }
     143               
     144                if(!empty($product->get_price())) {
     145                    $price = wc_price($product->get_price());
     146                }else {
     147                    $price = wc_price(0);
     148                }
     149                if(!empty($product->get_sale_price())) {
     150                    $price = wc_price($product->get_regular_price());
     151                }elseif(!empty($current_product_exact_price)){
     152                    $price = wc_price($product->get_regular_price());
     153                }else {
     154                    $price = "";
     155                }
     156                $regular_price_color = $fbtpfw_comman['regular_price_color'];
     157                echo ' &ndash; <span class="fbtpfw_price_old">' . wp_kses_post($price). '</span><span class="fbtpfw_price_new" style="color:'.esc_attr($regular_price_color).';">('. wp_kses_post(wc_price($current_product_exact_price)) .')</span>';
     158
     159                $productaaaaa = wc_get_product( get_the_ID() );
     160                if($productaaaaa->get_type() == 'variable'){
     161                    $attributesqwqww = $productaaaaa->get_variation_attributes();
     162                    $available_variations = $productaaaaa->get_available_variations();
     163                    if( $current_product_is_variation ) {
     164                        if ( is_array( $attributesqwqww ) && ( count( $attributesqwqww ) > 0 ) ) {
     165                            echo "<div class='oc_cust_variation' currentproid=".esc_attr(get_the_id()).">";
     166
     167                            if ( is_array( $attributes ) && ( count( $attributes ) > 0 ) ) {
     168                                echo '<div class="variations_form" data-product_id="' . absint( get_the_id() ) . '" data-product_variations="' . esc_attr( wp_json_encode( $available_variations ) ) . '">';
     169                                echo '<div class="variations">';
     170                                foreach ( $attributesqwqww as $attribute_name => $options ) { ?>
     171                                    <div class="variation">
     172                                        <div class="label">
     173                                            <?php echo esc_html(wc_attribute_label( $attribute_name )); ?>
     174                                        </div>
     175                                        <div class="select">
     176                                            <?php
     177                                            $selected = isset( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ? wc_clean( stripslashes( urldecode( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ) ) : $productaaaaa->get_variation_default_attribute( $attribute_name );
     178                                                wc_dropdown_variation_attribute_options( array(
     179                                                    'options'          => $options,
     180                                                    'attribute'        => $attribute_name,
     181                                                    'product'          => $productaaaaa,
     182                                                    'selected'         => $selected,
     183                                                ) );
     184                                            ?>
     185                                        </div>
     186                                    </div>
     187                                <?php }
     188                                echo '<div class="reset">' . apply_filters( 'woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . fbtpfw_localization( 'clear', esc_html__( 'Clear', 'frequently-bought-together-product-for-woocommmerce' ) ) . '</a>' ) . '</div>';
     189                                echo '</div>';
     190                                echo '</div>';
     191                                echo "</div>";
     192                            }
    87193                        }
    88194                    }
    89195                }
    90 
    91                 if($occp_badge == 'true') {
    92                     $badge = $badge;
    93                 } else {
    94                     $badge = '';
    95                 }
    96 
    97                 $images .= '<td class="fbtpfw_img" image_pro_id="'.$current_product_id.'"><div class="fbtpfw_img_div"><a href="' . $current_product_link . '">' . $current_product_image . '</a>'.$badge.'</div></td>';
    98 
    99                 if( $count < $occp_count ) {
    100                     $isimplfirst = '';
    101                     if($count == 0) {
    102                         $isimplfirst = 'fbtpfw_img_plus_first';
    103                     }
    104                     $images .= '<td class="fbtpfw_img_plus '.$isimplfirst.'" fbtpfw_imgpls_id="'.$current_product_id.'">+</td>';
    105                 }
    106                
    107                 ob_start();
    108                 $check_default_pro = $fbtpfw_comman['check_default_pro'];
    109                 ?>
    110                 <li class="fbtpfw_each_item">
    111                     <input type="checkbox" name="proID[]" id="proID_<?php echo esc_attr($count) ?>" class="product_check" value="<?php echo esc_attr($current_product_id); ?>" price="<?php echo esc_attr($current_product_exact_price); ?>" <?php if($count == 0) { echo 'checked style="opacity: .6;pointer-events: none;"'; }elseif($check_default_pro == 'yes'){echo "checked";} ?> />
    112                     <span class="fbtpfw_product_title">
    113                         <?php $this_item_text = $fbtpfw_comman['this_item_text']; ?>
    114                         <?php
    115                         if($count == 0) {
    116                             echo esc_attr($this_item_text.' : '.$current_product_title);
    117                         } else {
    118                             echo '<a href="'.esc_url($current_product_link).'">'.esc_attr($current_product_title).'</a>';
    119                         }
     196            ?>
     197        </li>
     198        <?php
     199        $product_details .= ob_get_clean();
     200        // increment total
     201        $total += floatval( $current_product_exact_price );
     202        $badge = '';
     203        $count++;
     204    }
     205    ?>
     206    <input type="hidden" name="formate" value="<?php echo esc_attr(get_woocommerce_currency_symbol()); ?>" class="formate">
     207    <input type="hidden" name="layout" value="layout2" class="layout">
     208    <div class="fbtpfw_main layout2">
     209        <!-- <form class="fbtpfw_product_form" method="post" action=""> -->
     210            <?php $fbtpfw_product_color = $fbtpfw_comman['fbtpfw_product_color']; ?>
     211            <!-- <h3 style="color:<?php //echo esc_attr($fbtpfw_product_color); ?>" ><?php// echo esc_attr(get_post_meta( get_the_ID(), 'occp_head_txt', true )); ?></h3> -->
     212            <h3 style="color:<?php echo esc_attr($fbtpfw_product_color); ?>" ><?php echo esc_html($fbtpfw_comman['Heading_text']); ?></h3>
     213            <div class ="fbtpfw_product_images">
     214                <?php echo wp_kses_post($images); ?>
     215            </div>
     216            <div class="fbtpfw_cart_div">
     217                <div class="fbtpfw_price">
     218                     <?php $price_all_text_color = $fbtpfw_comman['price_all_text_color']; ?>
     219                    <span class="fbtpfw_price_label" style="color:<?php echo esc_attr($price_all_text_color);  ?>">
     220                        <?php $price_for_all_text = $fbtpfw_comman['price_for_all_text']; ?>
     221                        <?php echo esc_attr($price_for_all_text)." : ";
    120222                        ?>
    121223                    </span>
    122                     <?php
    123                         if( $current_product_is_variation ) {
    124                             $attributes = $product->get_variation_attributes();
    125                             $variations = array();
    126 
    127                             foreach( $attributes as $key => $attribute ) {
    128                                 $variations[] = $attribute;
    129                             }
    130 
    131                             if( ! empty( $variations ) ){
    132                                 echo '<span class="product-attributes"> &ndash; ' . esc_attr(implode( ', ', $variations )) . '</span>';
    133                             }
    134 
    135                         }
    136                        
    137                         if(!empty($product->get_price())) {
    138                             $price = wc_price($product->get_price());
    139                         }else {
    140                             $price = wc_price(0);
    141                         }
    142                         if(!empty($product->get_sale_price())) {
    143                             $price = wc_price($product->get_regular_price());
    144                         }elseif(!empty($current_product_exact_price)){
    145                             $price = wc_price($product->get_regular_price());
    146                         }else {
    147                             $price = "";
    148                         }
    149                         $regular_price_color = $fbtpfw_comman['regular_price_color'];
    150                         echo ' &ndash; <span class="fbtpfw_price_old">' . $price. '</span><span class="fbtpfw_price_new" style="color:'.esc_attr($regular_price_color).';">('. wc_price($current_product_exact_price) .')</span>';
    151 
    152                         $productaaaaa = wc_get_product( get_the_ID() );
    153                         if($productaaaaa->get_type() == 'variable'){
    154                             $attributesqwqww = $productaaaaa->get_variation_attributes();
    155                             $available_variations = $productaaaaa->get_available_variations();
    156                             if( $current_product_is_variation ) {
    157                                 if ( is_array( $attributesqwqww ) && ( count( $attributesqwqww ) > 0 ) ) {
    158                                     echo "<div class='oc_cust_variation' currentproid=".get_the_id().">";
    159 
    160                                     if ( is_array( $attributes ) && ( count( $attributes ) > 0 ) ) {
    161                                         echo '<div class="variations_form" data-product_id="' . absint( get_the_id() ) . '" data-product_variations="' . htmlspecialchars( wp_json_encode( $available_variations ) ) . '">';
    162                                         echo '<div class="variations">';
    163                                         foreach ( $attributesqwqww as $attribute_name => $options ) { ?>
    164                                             <div class="variation">
    165                                                 <div class="label">
    166                                                     <?php echo wc_attribute_label( $attribute_name ); ?>
    167                                                 </div>
    168                                                 <div class="select">
    169                                                     <?php
    170                                                     $selected = isset( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ? wc_clean( stripslashes( urldecode( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ) ) : $productaaaaa->get_variation_default_attribute( $attribute_name );
    171                                                         wc_dropdown_variation_attribute_options( array(
    172                                                             'options'          => $options,
    173                                                             'attribute'        => $attribute_name,
    174                                                             'product'          => $productaaaaa,
    175                                                             'selected'         => $selected,
    176                                                         ) );
    177                                                     ?>
    178                                                 </div>
    179                                             </div>
    180                                         <?php }
    181                                         echo '<div class="reset">' . apply_filters( 'woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . fbtpfw_localization( 'clear', esc_html__( 'Clear', 'frequently-bought-together-product-for-woocommmerce' ) ) . '</a>' ) . '</div>';
    182                                         echo '</div>';
    183                                         echo '</div>';
    184                                         echo "</div>";
    185                                     }
    186                                 }
    187                             }
    188                         }
    189                     ?>
    190                 </li>
     224                    &nbsp;
     225                    <span class="fbtpfw_price_total" data-total="<?php echo esc_attr($total); ?>">
     226                        <?php echo wp_kses_post(wc_price( $total )); ?>
     227                    </span>
     228                </div>
    191229                <?php
    192                 $product_details .= ob_get_clean();
    193                 // increment total
    194                 $total += floatval( $current_product_exact_price );
    195                 $badge = '';
    196                 $count++;
    197             }
    198             ?>
    199             <input type="hidden" name="formate" value="<?php echo esc_attr(get_woocommerce_currency_symbol()); ?>" class="formate">
    200             <input type="hidden" name="layout" value="layout2" class="layout">
    201             <div class="fbtpfw_main layout2">
    202                 <form class="fbtpfw_product_form" method="post" action="">
    203                     <?php $fbtpfw_product_color = $fbtpfw_comman['fbtpfw_product_color']; ?>
    204                     <h3 style="color:<?php echo esc_attr($fbtpfw_product_color); ?>" ><?php echo esc_attr(get_post_meta( get_the_ID(), 'occp_head_txt', true )); ?></h3>
    205                     <table class="fbtpfw_product_images">
    206                         <tbody>
    207                             <tr>
    208                                 <?php echo $images;  ?>
    209                                
    210                             </tr>
    211                         </tbody>
    212                     </table>
    213                     <div class="fbtpfw_cart_div">
    214                         <div class="fbtpfw_price">
    215                              <?php $price_all_text_color = $fbtpfw_comman['price_all_text_color']; ?>
    216                             <span class="fbtpfw_price_label" style="color:<?php echo esc_attr($price_all_text_color);  ?>">
    217                                 <?php $price_for_all_text = $fbtpfw_comman['price_for_all_text']; ?>
    218                                 <?php echo esc_attr($price_for_all_text)." : ";
    219                                 ?>
    220                             </span>
    221                             &nbsp;
    222                             <span class="fbtpfw_price_total" data-total="<?php echo esc_attr($total); ?>">
    223                                 <?php echo wc_price( $total ); ?>
    224                             </span>
    225                         </div>
    226                         <?php $add_to_cart_text =$fbtpfw_comman['add_to_cart_text']; ?>
    227                         <?php $add_cart_back_color =  $fbtpfw_comman['add_cart_back_color']; ?>
    228                         <?php $add_cart_text_color = $fbtpfw_comman['add_cart_text_color']; ?>
    229                         <input type="submit" style="color:<?php echo esc_attr($add_cart_text_color); ?>;background: <?php echo esc_attr($add_cart_back_color); ?>" class="occp_add_cart_button button" value="<?php echo esc_attr($add_to_cart_text); ?>" name="occp_add_to_cart">
    230                     </div>
    231 
    232                     <ul class="fbtpfw_ul">
    233                         <?php echo $product_details;  ?>
    234                     </ul>       
    235                 </form>
    236             </div>
    237             <?php
    238         }
     230                $add_to_cart_text =$fbtpfw_comman['add_to_cart_text'];
     231                $add_cart_back_color =  $fbtpfw_comman['add_cart_back_color'];
     232                $add_cart_text_color = $fbtpfw_comman['add_cart_text_color']; ?>
     233                <!-- <input type="submit" style="color:<?php //echo esc_attr($add_cart_text_color); ?>;background: <?php //echo esc_attr($add_cart_back_color); ?>" class="occp_add_cart_button button" value="<?php //echo esc_attr($add_to_cart_text); ?>" name="occp_add_to_cart"> -->
     234            </div>
     235
     236            <ul class="fbtpfw_ul">
     237                <?php echo $product_details;  ?>
     238            </ul>       
     239        </form>
     240    </div>
     241    <?php
     242}
  • frequently-bought-together-product-for-woocommerce/trunk/main/resources/fbtpfw-installation-require.php

    r2798797 r3450808  
    11<?php
     2if ( ! defined( 'ABSPATH' ) ) exit;
    23
    34// Error returns when woocommerce is not installed
  • frequently-bought-together-product-for-woocommerce/trunk/main/resources/fbtpfw-load-js-css.php

    r3262514 r3450808  
    11<?php
     2if ( ! defined( 'ABSPATH' ) ) exit;
    23
    34/* admin style and script */
     
    3031
    3132function FBTPFW_load_script_style() {
    32     wp_enqueue_script('jquery', false, array(), false, false);
     33    wp_enqueue_script('jquery');
    3334    wp_enqueue_style( 'FBTPFW-front-style', FBTPFW_PLUGIN_DIR . '/includes/css/front-style.css', false, '1.0.0' );
    34     wp_enqueue_script( 'FBTPFW-front-script', FBTPFW_PLUGIN_DIR . '/includes/js/front-script.js', false, '1.0.0' );
     35    wp_enqueue_script( 'FBTPFW-front-script', FBTPFW_PLUGIN_DIR . '/includes/js/front-script.js', [ 'wc-blocks-registry', 'wp-hooks', 'wp-element' ], '1.0.0', true );
     36
     37    $cart_item_content = [];
     38    global $fbtpfw_comman;
     39    if ( WC()->cart->get_cart_contents_count() > 0 ) :
     40        foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
     41            if ( isset( $cart_item['fbtpfw_parent_id'] ) && ! empty( $cart_item['fbtpfw_parent_id'] ) ) {
     42                $occp_btassociated_txt = $fbtpfw_comman['Associated_text'];
     43
     44                if($occp_btassociated_txt != '') {
     45                    $fbtpfw_btogether_text = esc_html( $occp_btassociated_txt );
     46                } else {
     47                    /* translators: %s: number of products bought together */
     48                    $fbtpfw_btogether_text = esc_html__( '(bought together %s)', 'frequently-bought-together-product-for-woocommmerce' );
     49                }
     50
     51                $name = sprintf( $fbtpfw_btogether_text, get_the_title( $cart_item['fbtpfw_parent_id'] ) );
     52               
     53                $cart_item_content[$cart_item_key] = ' <span class="fbtpfw_parent_name">' . apply_filters( 'fbtpfw_parent_name', $name, $cart_item ) . '</span>';
     54            }
     55        }
     56    endif;
     57
    3558    wp_localize_script( 'FBTPFW-front-script', 'fbtpfw_OBJECT',
    3659        array(
    3760            'add_to_cart_text' => get_option('add_to_cart_text','Add to Cart'),
    3861            'ajaxurl' => admin_url( 'admin-ajax.php' ),
    39             'ajaxnonce' => wp_create_nonce( 'fbtpfw_ajax_nonce' )
     62            'ajaxnonce' => wp_create_nonce( 'fbtpfw_ajax_nonce' ),
     63            'cart_item_content' => json_encode($cart_item_content)
    4064        )
    4165    );
  • frequently-bought-together-product-for-woocommerce/trunk/readme.txt

    r3286079 r3450808  
    22Tags:frequently bought together, bought together, Woocommerce
    33Requires at least: 5.5
    4 Tested up to: 6.8
     4Tested up to: 6.9
    55Stable tag: 1.2
    66License: GPLv2 or later
     
    2525* Multiple Layout
    2626* Option to enable/disable Frequently Bought Together Plugin
    27 * Custom Place on working
    2827* Price Discount In Bulk
    2928* Ordering of Product Group
    3029* Creating bundles from product variations
    31 * Custom Position
    32 * Default products, check default products options.
    3330* Some text translate options.
    3431* Change all color options.
     
    4037
    4138*🌟 [Documentation](https://www.plugin999.com/docs/frequently-bought-together-product-for-woocommerce/)* | *🌟 [Demo](https://plugin999.com/demo/frequently-bought-together-product-for-woocommerce/product/t-shirt-with-logo/)* | *🌟 [Support](https://www.plugin999.com/support/)*
     39
     40<h3>FEATURES FOR PREMIUM:</h3>
     41
     42<ul>
     43<li>Enable Multiple Layout</li>
     44<li>Custom Place on working</li>
     45<li>Custom Position</li>
     46<li>Default products, check default products options.</li>
     47<li>set Associated and Heading texttranslate options.</li>
     48</ul>
    4249
    4350== CONTRIBUTE AND TRANSLATE ==
Note: See TracChangeset for help on using the changeset viewer.