<?php
/**
 * @package   @package productive-commerce
 */
    
function productive_commerce_get_button_radius_css( $shape = 'sharp_corners' ) {
    $css_radius = '';
    switch ($shape) {
        case 'round_corners':
            $css_radius = '7px';
            break;
        case 'oval':
            $css_radius = '50%';
            break;
        default:
            $css_radius = '0';
            break;
    }
    return $css_radius;
}

function productive_commerce_get_button_radius_shapes() {
    return array (
        'sharp_corners' => esc_html__( 'Sharp Corners', 'productive-commerce' ),
        'round_corners' => esc_html__( 'Round Corners', 'productive-commerce' ),
        'oval' => esc_html__( 'Oval', 'productive-commerce' ),
    );
}

function productive_commerce_get_product_page_button_formats() {
    return array (
        'icon_only' => esc_html__( 'Icon Only', 'productive-commerce' ),
        'text_only' => esc_html__( 'Text Only', 'productive-commerce' ),
        'icon_and_text' => esc_html__( 'Both Icon and Text', 'productive-commerce' ),
    );
}

function productive_commerce_get_popup_transition_easings() {
    return array (
        '--ease' => esc_html__( 'Ease', 'productive-commerce' ),
        '--ease-in' => esc_html__( 'Ease In', 'productive-commerce' ),
        '--ease-out' => esc_html__( 'Ease Out', 'productive-commerce' ),
        '--ease-in-out' => esc_html__( 'Ease In/Out', 'productive-commerce' ),
        '--linear' => esc_html__( 'Linear', 'productive-commerce' ),
        '--cubic-bezier-1' => esc_html__( 'Cubic Bezier Style 1', 'productive-commerce' ),
        '--cubic-bezier-2' => esc_html__( 'Cubic Bezier Style 2', 'productive-commerce' ),
    );
}

function productive_commerce_get_popup_transition_directions() {
    return array (
        'slideFromTop' => esc_html__( 'Top', 'productive-commerce' ),
        'slideFromBottom' => esc_html__( 'Bottom', 'productive-commerce' ),
        'slideFromLeft' => esc_html__( 'Left', 'productive-commerce' ),
        'slideFromRight' => esc_html__( 'Right', 'productive-commerce' ),
    );
}

function productive_commerce_get_popup_transition_styles() {
    return array (
        'slide' => esc_html__( 'Slide', 'productive-commerce' ),
        'fade' => esc_html__( 'Fade', 'productive-commerce' ),
        'flip' => esc_html__( 'Flip', 'productive-commerce' ),
        'cards' => esc_html__( 'Cards', 'productive-commerce' ),
    );
}

function productive_commerce_get_popup_transition_delays() {
    return array (
        '1000' => esc_html__( '1 second', 'productive-commerce' ),
        '2000' => esc_html__( '2 seconds', 'productive-commerce' ),
        '3000' => esc_html__( '3 seconds', 'productive-commerce' ),
        '4000' => esc_html__( '4 seconds', 'productive-commerce' ),
        '5000' => esc_html__( '5 seconds', 'productive-commerce' ),
        '7500' => esc_html__( '7.5 seconds', 'productive-commerce' ),
        '10000' => esc_html__( '10 seconds', 'productive-commerce' ),
        '15000' => esc_html__( '15 seconds', 'productive-commerce' ),
        '20000' => esc_html__( '20 seconds', 'productive-commerce' ),
    );
}

function productive_commerce_get_popup_user_controls() {
    return array (
        'none'                      => esc_html__( 'None', 'productive-commerce' ),
        'touch_swipe'               => esc_html__( 'Touch Swipe Only', 'productive-commerce' ),
        'dots'                      => esc_html__( 'Pagination Dots Only', 'productive-commerce' ),
        'arrows'                    => esc_html__( 'Prev/Next Arrows Only', 'productive-commerce' ),
        'dots_and_arrows'           => esc_html__( 'Dots &#38; Arrows', 'productive-commerce' ),
        'touch_swipe_and_arrows'    => esc_html__( 'Touch Swipe &#38; Arrows', 'productive-commerce' ),
        'touch_swipe_and_dots'      => esc_html__( 'Touch Swipe &#38; Dots', 'productive-commerce' ),
        'all'                       => esc_html__( 'Allow All Three Actions', 'productive-commerce' ),
    );
}

function productive_commerce_get_popup_title_visibility_options() {
    return array (
        '' => esc_html__( 'Hide', 'productive-commerce' ),
        'header' => esc_html__( 'Popup Header', 'productive-commerce' ),
        'body' => esc_html__( 'Popup Body', 'productive-commerce' ),
    );
}

function productive_commerce_get_cart_icon_options($show_hide = 1) {
    $args = array();
    if( $show_hide ) {
        $args[''] = esc_html__( 'Hide', 'productive-commerce' );
    }
    $args['shopping-cart'] = esc_html__( 'Shopping Cart', 'productive-commerce' );
    $args['shopping-bag'] = esc_html__( 'Shopping Bag', 'productive-commerce' );
    
    return $args;
}

function productive_commerce_get_remove_after_add_to_cart_options() {
    return array (
        '0' => esc_html__( 'No', 'productive-commerce' ),
        '1' => esc_html__( 'Remove Automatically', 'productive-commerce' ),
    );
}

function productive_commerce_get_header_button_subtotal_positions() {
    return array (
        'hide' => esc_html__( 'Hide', 'productive-commerce' ),
        'position_top_right' => esc_html__( 'Top Right', 'productive-commerce' ),
        'position_top_left' => esc_html__( 'Top Left', 'productive-commerce' ),
        'position_bottom_right' => esc_html__( 'Bottom Right', 'productive-commerce' ),
        'position_bottom_left' => esc_html__( 'Bottom Left', 'productive-commerce' ),
    );
}

function productive_commerce_get_wishlist_icon_options($show_hide = 1) {
    $args = array();
    if( $show_hide ) {
        $args[''] = esc_html__( 'Hide', 'productive-commerce' );
    }
    $args['wishlist-o'] = esc_html__( 'Wishlist Outlined', 'productive-commerce' );
    $args['wishlist'] = esc_html__( 'Wishlist Filled', 'productive-commerce' );
    
    return $args;
}

function productive_commerce_get_compare_icon_options($show_hide = 1) {
    $args = array();
    if( $show_hide ) {
        $args[''] = esc_html__( 'Hide', 'productive-commerce' );
    }
    $args['compare'] = esc_html__( 'Exchange', 'productive-commerce' );
    $args['refresh'] = esc_html__( 'Refresh', 'productive-commerce' );
    
    return $args;
}

function productive_commerce_get_product_or_child_is_in_stock( $product, $product_or_variation_id, $product_type ) {
    $value = false;
    if( !($product instanceof WC_Product) ) {
        return $value;
    }
    if( PRODUCTIVE_COMMERCE_PLUGIN_PRODUCT_TYPE_VARIABLE == $product_type ) {
        $available_variations = $product->get_available_variations();
        foreach ( $available_variations as $available_variations ) {
            if( $product_or_variation_id == $available_variations['variation_id'] ) {
                $value = $available_variations['is_in_stock'];
                break;
            }
        }
    } else {
        $value = $product->is_in_stock();
    }
    return $value;
}

function productive_commerce_get_product_or_child_is_purchasable( $product, $product_or_variation_id, $product_type ) {
    $value = false;
    if( !($product instanceof WC_Product) ) {
        return $value;
    }
    if( PRODUCTIVE_COMMERCE_PLUGIN_PRODUCT_TYPE_VARIABLE == $product_type ) {
        $available_variations = $product->get_available_variations();
        foreach ( $available_variations as $available_variations ) {
            if( $product_or_variation_id == $available_variations['variation_id'] ) {
                $value = $available_variations['is_purchasable'];
                break;
            }
        }
    } else {
        $value = $product->is_purchasable();
    }
    return $value;
}

function productive_commerce_get_product_or_child_backorders_allowed( $product, $product_or_variation_id, $product_type ) {
    $value = false;
    if( !($product instanceof WC_Product) ) {
        return $value;
    }
    if( PRODUCTIVE_COMMERCE_PLUGIN_PRODUCT_TYPE_VARIABLE == $product_type ) {
        $available_variations = $product->get_available_variations();
        foreach ( $available_variations as $available_variations ) {
            if( $product_or_variation_id == $available_variations['variation_id'] ) {
                $value = $available_variations['backorders_allowed'];
                break;
            }
        }
    } else {
        $value = $product->backorders_allowed();
    }
    return $value;
}

function productive_commerce_get_product_or_child_is_on_sale( $product, $product_or_variation_id, $product_type ) {
    $value = false;
    if( !($product instanceof WC_Product) ) {
        return $value;
    }
    if( PRODUCTIVE_COMMERCE_PLUGIN_PRODUCT_TYPE_VARIABLE == $product_type ) {
        $available_variations = $product->get_available_variations();
        foreach ( $available_variations as $available_variations ) {
            if( $product_or_variation_id == $available_variations['variation_id'] ) {
                $display_price = $available_variations['display_price'];
                $display_regular_price = $available_variations['display_regular_price'];
                if( $display_price != $display_regular_price ) {
                   $value = true; 
                }
                break;
            }
        }
    } else {
        $value = $product->is_on_sale();
    }
    return $value;
}

function productive_commerce_get_product_or_child_sku( $product, $product_or_variation_id, $product_type ) {
    $value = '';
    if( !($product instanceof WC_Product) ) {
        return $value;
    }
    if( PRODUCTIVE_COMMERCE_PLUGIN_PRODUCT_TYPE_VARIABLE == $product_type ) {
        $available_variations = $product->get_available_variations();
        foreach ( $available_variations as $available_variations ) {
            if( $product_or_variation_id == $available_variations['variation_id'] ) {
                $value = $available_variations['sku'];
                break;
            }
        }
    } else {
        $value = $product->get_sku();
    }
    return $value;
}

function productive_commerce_get_product_or_child_display_thumbnail_url( $product, $product_or_variation_id, $product_type ) {
    $value = '';
    if( !($product instanceof WC_Product) ) {
        return $value;
    }
    if( PRODUCTIVE_COMMERCE_PLUGIN_PRODUCT_TYPE_VARIABLE == $product_type ) {
        $available_variations = $product->get_available_variations();
        foreach ( $available_variations as $available_variations ) {
            if( $product_or_variation_id == $available_variations['variation_id'] ) {
                $value = $available_variations['image']['gallery_thumbnail_src'];
                break;
            }
        }
    } else {
        $post_thumbnail_id = get_post_thumbnail_id( $product_or_variation_id );
        $value = productive_commerce_get_attachment_by_thumbnail_id( $post_thumbnail_id );
    }
    return $value;
}

function productive_commerce_get_product_or_child_display_price_value( $product, $product_or_variation_id, $product_type ) {
    $value = 0;
    if( !($product instanceof WC_Product) ) {
        return $value;
    }
    if( PRODUCTIVE_COMMERCE_PLUGIN_PRODUCT_TYPE_VARIABLE == $product_type ) {
        $available_variations = $product->get_available_variations();
        foreach ( $available_variations as $available_variations ) {
            if( $product_or_variation_id == $available_variations['variation_id'] ) {
                $value = $available_variations['display_price'];
                break;
            }
        }
    } else {
        $value = wc_get_price_excluding_tax( $product );
    }
    return $value;
}

function productive_commerce_get_product_or_child_display_price_html( $product, $product_or_variation_id, $product_type, $is_mini_format = false ) {
    $display_price = '';
    if( PRODUCTIVE_COMMERCE_PLUGIN_PRODUCT_TYPE_VARIABLE == $product_type ) {
        $available_variations = $product->get_available_variations();
        foreach ( $available_variations as $available_variations ) {
            if( $product_or_variation_id == $available_variations['variation_id'] ) {
                $display_price = $available_variations['price_html'];
                break;
            }
        }
    } else {
        if( $is_mini_format ) {
            $display_price = productive_commerce_get_product_or_child_display_price_html_mini( $product );
        } else {
            $display_price = $product->get_price_html();
        }
    }
    return $display_price;
}

function productive_commerce_get_product_or_child_display_price_html_mini( $product ) {
    $product_price = 0;
    if( null != WC()->cart ) {
        $product_price = WC()->cart->get_product_price( $product );
    } else {
        if( 'excl' == get_option( 'woocommerce_tax_display_cart' ) ) {
            $product_price = wc_get_price_excluding_tax( $product );
        } else {
            $product_price = wc_get_price_including_tax( $product );
        }
        return apply_filters( 'woocommerce_cart_product_price', wc_price( $product_price ), $product );
    }
    return $product_price;
}

function productive_commerce_get_product_or_child_parent_id( $product_db_object ) {
    $value = $product_db_object['product_id'];
    if( PRODUCTIVE_COMMERCE_PLUGIN_PRODUCT_TYPE_VARIABLE == $product_db_object['product_type'] ) {
        $value = $product_db_object['parent_id'];
    }
    return $value;
}

function productive_commerce_get_product_or_child_name( $product_object, $product_db_object ) {
    if( !($product_object instanceof WC_Product) ) {
        return '';
    }
    $product_title = $product_object->get_name();
    $product_title_attr = '';
    $attr_separator = ', ';
    if( PRODUCTIVE_COMMERCE_PLUGIN_PRODUCT_TYPE_VARIABLE == $product_db_object['product_type'] ) {
        $variation_data = $product_db_object['variation_data'];
        $variation_data_items = explode( ',', $variation_data );
        foreach( $variation_data_items as $variation_data_item ) {
            $data_array = explode( '|', $variation_data_item );
            $product_title_attr .= ucfirst( $data_array[1] ) . $attr_separator ;
        }
        $product_title .= ' - ' . rtrim( $product_title_attr, $attr_separator );
    }
    return $product_title;
}

function productive_global_get_social_media_share_image_from_products( $product_db_objects ) {
    $thumbnail_image_url = '';
    foreach ( $product_db_objects as $key => $product_db_object ) {
        $product_id = intval($product_db_object['product_id']);
        $product_object = wc_get_product( $product_id );
        if( !($product_object instanceof WC_Product) ) {
            continue;
        }
        $post_thumbnail_id = $product_object->get_image_id();
        $thumbnail_image_url = productive_commerce_get_attachment_by_thumbnail_id( $post_thumbnail_id );
        if( $post_thumbnail_id && !empty($thumbnail_image_url) ) {
            break;
        }
    }
    if( empty($thumbnail_image_url) ) {
        $thumbnail_image_url = productive_global_get_site_logo_url();
    }
    return $thumbnail_image_url;
}

// Start:: Wishlist
function productive_commerce_get_wishlist_productive_cpts_and_dates( $is_wishlist_page = 0, $is_wishlist_slug = '' ) {
    if( !empty($is_wishlist_slug) ) {
        $pwl_list = $is_wishlist_slug;
    } else {
        $pwl_list = _productive_commerce_get_wishlist_query_param();
    }
    return _productive_commerce_get_wishlist_productive_cpts_and_dates( $pwl_list, $is_wishlist_page );
}

function _productive_commerce_get_wishlist_productive_cpts_and_dates( $pwl_list, $is_wishlist_page ) {
    $wishlist_products = productive_commerce_get_wishlist_products( $pwl_list );
    $product_db_objects = array();
    $products_quantity_count = 0;
    $wishlist_subtotal_price = 0;
    
    if ( 0 < count( $wishlist_products ) ) {
        foreach ( $wishlist_products as $wishlist_product ) {
            $id = $wishlist_product['product_id'];
            $product_db_objects[$id] = $wishlist_product;
            $products_quantity_count += intval( $wishlist_product['quantity'] );
            if( $is_wishlist_page && productive_commerce_is_extra() ) {
                $wishlist_subtotal_price += _productive_commerce_get_wishlist_productive_cpts_and_dates_subtotal( $wishlist_product );
            }
        }
    }
    $current_user_id = get_current_user_id();
    $wishlist_obj_array = productive_commerce_get_wishlist_via_slug( $pwl_list );
    $wishlist_owner_user_id = 0;
    if( array_key_exists( 'user_id', $wishlist_obj_array) ) {
        $wishlist_owner_user_id = $wishlist_obj_array['user_id'];
    }
    $is_wishlist_owner = 0;
    if( ( $current_user_id && $current_user_id == $wishlist_owner_user_id ) || $pwl_list == productive_commerce_get_wishlist_in_cookie() ) {
        $is_wishlist_owner = 1;
    }
    if( ( $current_user_id && $current_user_id != $wishlist_owner_user_id ) && $pwl_list == productive_commerce_get_wishlist_in_cookie() ) {
        productive_commerce_update_wishlist_ownership( $pwl_list, $current_user_id );
    }
    return array(
        'product_db_objects'        => $product_db_objects,
        'the_wishlist_object'       => $wishlist_obj_array,
        'products_quantity_count'   => $products_quantity_count,
        'wishlist_subtotal_price'   => $wishlist_subtotal_price,
        'is_wishlist_owner'         => $is_wishlist_owner,
    );
}

function _productive_commerce_get_wishlist_query_param() {
    global $wp_query;
    $pwl_list = '';
    if( isset( $wp_query->query_vars[PRODUCTIVE_COMMERCE_PLUGIN_WISHLIST_QUERY_PARAM] ) ) {
        $pwl_list = $wp_query->query_vars[PRODUCTIVE_COMMERCE_PLUGIN_WISHLIST_QUERY_PARAM];
    } else {
        // Refresh cookie, if neccessary
        productive_commerce_unset_wishlist_cookie_if_empty();
        if( isset( $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_WISHLIST_COOKIE_PARAM] ) ) {
            $pwl_list = $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_WISHLIST_COOKIE_PARAM];
        } else {
            $pwl_list = productive_commerce_set_and_get_wishlist_cookie_from_ls();
        }
    }
    return $pwl_list;
}

function productive_commerce_set_and_get_wishlist_cookie_from_ls() {
    $secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );
 ?>
    <script>
        function productive_commerce_js_generate_wishlist_cookie_from_ls() {
            let wishlist_slug = '';
            let site = '<?php echo PRODUCTIVE_COMMERCE_LOCALSTORE_SITE_ID; ?>';
            pwlWishlists    = localStorage.getItem( 'pwlWishlists'+site );
            if( null !== pwlWishlists && '' !== pwlWishlists ) {
                pwlWishlistsData = JSON.parse( pwlWishlists );
                wishlist_slug = pwlWishlistsData[0].slug;
            }
            let name = '<?php echo PRODUCTIVE_COMMERCE_PLUGIN_WISHLIST_COOKIE_PARAM; ?>';
            let expires = parseInt( '<?php echo PRODUCTIVE_COMMERCE_PLUGIN_COOKIE_EXPIRES_IN; ?>' );
            let path = '<?php echo COOKIEPATH; ?>';
            let domain = '<?php echo COOKIE_DOMAIN; ?>';
            let secure = '<?php echo productive_commerce_get_content_to_render($secure); ?>';
            let cookie_param = name + "=" + wishlist_slug + "; expires=" + expires + "; path=" + path + "; domain=" + domain + "; secure=" + secure ;
            document.cookie = cookie_param;
        }
        productive_commerce_js_generate_wishlist_cookie_from_ls();
    </script>
<?php
    $pwl_list = '';
    if( isset( $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_WISHLIST_COOKIE_PARAM] ) ) {
        $pwl_list = $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_WISHLIST_COOKIE_PARAM];
    }
    return $pwl_list;
}

function productive_commerce_refresh_wishlist_in_cookie( $wishlist_slug ) {
    if( !isset( $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_WISHLIST_COOKIE_PARAM] ) ||
            ( isset( $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_WISHLIST_COOKIE_PARAM] ) && $wishlist_slug != $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_WISHLIST_COOKIE_PARAM] ) ) {
        productive_global_setcookie( PRODUCTIVE_COMMERCE_PLUGIN_WISHLIST_COOKIE_PARAM, $wishlist_slug, PRODUCTIVE_COMMERCE_PLUGIN_COOKIE_EXPIRES_IN);
    }
}

function productive_commerce_set_wishlist_in_cookie( $wishlist_slug ) {
    productive_global_setcookie( PRODUCTIVE_COMMERCE_PLUGIN_WISHLIST_COOKIE_PARAM, $wishlist_slug, PRODUCTIVE_COMMERCE_PLUGIN_COOKIE_EXPIRES_IN);
}

function productive_commerce_get_wishlist_in_cookie() {
    $wishlist_in_cookie = '';
    if( isset( $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_WISHLIST_COOKIE_PARAM] ) ) {
        $wishlist_in_cookie = $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_WISHLIST_COOKIE_PARAM];
    }
    return $wishlist_in_cookie;
}

function productive_commerce_set_init_activate_user_wishlist_in_cookie() {
    // Trigers logged-in user Wishlist aggregation
    productive_global_setcookie( PRODUCTIVE_COMMERCE_PLUGIN_INIT_ACTIVATE_USER_WISHLIST_COOKIE_PARAM, 
            PRODUCTIVE_COMMERCE_PLUGIN_INIT_ACTIVATE_USER_WISHLIST_COOKIE_PARAM, PRODUCTIVE_COMMERCE_PLUGIN_COOKIE_EXPIRES_IN);
}

function productive_commerce_get_init_activate_user_wishlist_in_cookie() {
    $deactivate_wishlist_in_cookie = '';
    if( isset( $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_INIT_ACTIVATE_USER_WISHLIST_COOKIE_PARAM] ) ) {
        $deactivate_wishlist_in_cookie = $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_INIT_ACTIVATE_USER_WISHLIST_COOKIE_PARAM];
    }
    return $deactivate_wishlist_in_cookie;
}

function productive_commerce_set_deactivate_user_wishlist_in_cookie() {
    // Trigers logged-out user Wishlist aggregation
    productive_global_setcookie( PRODUCTIVE_COMMERCE_PLUGIN_DEACTIVATE_USER_WISHLIST_COOKIE_PARAM, 
            PRODUCTIVE_COMMERCE_PLUGIN_DEACTIVATE_USER_WISHLIST_COOKIE_PARAM, PRODUCTIVE_COMMERCE_PLUGIN_COOKIE_EXPIRES_IN);
}

function productive_commerce_get_deactivate_user_wishlist_in_cookie() {
    $deactivate_wishlist_in_cookie = '';
    if( isset( $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_DEACTIVATE_USER_WISHLIST_COOKIE_PARAM] ) ) {
        $deactivate_wishlist_in_cookie = $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_DEACTIVATE_USER_WISHLIST_COOKIE_PARAM];
    }
    return $deactivate_wishlist_in_cookie;
}

function productive_commerce_unset_wishlist_cookie_if_empty() {
    if( isset( $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_WISHLIST_COOKIE_PARAM] ) && '' == $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_WISHLIST_COOKIE_PARAM] ) {
        unset( $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_WISHLIST_COOKIE_PARAM] );
    }
}

function productive_commerce_get_this_wishlist_page_url( $wishlist_slug = '' ) {
    $wl_url_raw = productive_commerce_wishlist_list_of_wishlists_page_url(); 
    if( empty( $wishlist_slug ) ) {
        $pwl_list = _productive_commerce_get_wishlist_query_param();
    } else {
        $pwl_list = $wishlist_slug;
    }
    
    // Using Endpoint
    if( strpos( get_option('permalink_structure'), 'postname' ) !== false ) {
        $url = $wl_url_raw . '/' . $pwl_list;
    } else {
        $url = add_query_arg( PRODUCTIVE_COMMERCE_PLUGIN_WISHLIST_QUERY_PARAM, $pwl_list, $wl_url_raw );
    }
    return $url; 
}

function productive_commerce_list_of_wishlists_redirect_rule() {
    $wishlists_page_slug = productive_commerce_wishlist_list_of_wishlists_page_slug();
    add_rewrite_tag('%'.PRODUCTIVE_COMMERCE_PLUGIN_WISHLIST_QUERY_PARAM.'%', '([^&]+)');
    add_rewrite_rule( '^' . $wishlists_page_slug . '/([a-z0-9-]+)[/]?$', 'index.php?pagename=' . $wishlists_page_slug . '&' . PRODUCTIVE_COMMERCE_PLUGIN_WISHLIST_QUERY_PARAM . '=$matches[1]', 'top' );
    
    productive_global_flush_rewrite_rule( PRODUCTIVE_COMMERCE_IS_REWRITE_RULE_FLUSHED_KEY );
    
}
add_action( 'init', 'productive_commerce_list_of_wishlists_redirect_rule' );


function productive_commerce_render_part_remove_from_wishlist_button( $product_id, $product_title, $layout_format, $section_style_other_buttons_hover_animation, $productiveminds_icon_remove_icon_add_to_args ) {
?>
    <span title="<?php esc_html_e('Remove', 'productive-commerce'); ?>" aria-label="<?php esc_html_e('Remove from ', 'productive-commerce') . PRODUCTIVE_COMMERCE_WISHLIST_CONCEPT_NAME; ?> <?php echo esc_html( get_the_title() ); ?>" 
       class="other_product_box_button delete_anchor productiveminds_section_container_wishlist_remove <?php echo esc_attr($product_id); ?> <?php echo esc_attr( $section_style_other_buttons_hover_animation ); ?>" 
       data-product_id="<?php echo esc_attr($product_id); ?>" data-product_title="<?php echo esc_attr($product_title); ?>" data-layout_format="<?php echo esc_attr($layout_format); ?>" 
       data-quantity="1">
        <?php 
            echo wp_kses( productiveminds_get_svg_icon( $productiveminds_icon_remove_icon_add_to_args ), 'wp_kses_allowed_html' );
         ?>
    </span>
<?php
}

function is_productive_wishlist_page() {
    $page_id = productive_commerce_wishlist_list_of_wishlists_page();
    if( $page_id && is_page( $page_id ) ) {
        return true;
    }
    return false;
}

function productive_commerce_prep_wishlist_products( $products ) {
    $product_qtys = '';
    if ( !empty( $products ) ) {
        $products_values = explode( '||', $products );
        foreach ( $products_values as $products_value ) {
            $product = explode( '|', $products_value );
            $product_qtys .= $product[0].'|'.$product[1].',';
        }
        $product_qtys = rtrim( $product_qtys, ',' );
    }
    return $product_qtys;
}


// Start:: Compare
function is_productive_compare_page() {
    $page_id = productive_commerce_compare_list_of_compares_page();
    if( $page_id && is_page( $page_id ) ) {
        return true;
    }
    return false;
}

function productive_commerce_get_compare_productive_cpts_and_dates( $is_compare_page = 0, $is_compare_slug = '' ) {
    if( !empty($is_compare_slug) ) {
        $pwl_list = $is_compare_slug;
    } else {
        $pwl_list = _productive_commerce_get_compare_query_param();
    }
    return _productive_commerce_get_compare_productive_cpts_and_dates( $pwl_list, $is_compare_page );
}

function _productive_commerce_get_compare_productive_cpts_and_dates( $pcp_list, $is_compare_page = 0 ) {
    $compare_products = productive_commerce_get_compare_products( $pcp_list );
    $product_db_objects = array();
    if ( 0 < count( $compare_products ) ) {
        foreach ( $compare_products as $compare_product ) {
            $id = $compare_product['product_id'];
            $product_db_objects[$id] = $compare_product;
        }
    }
    $current_user_id = get_current_user_id();
    $compare_obj_array = productive_commerce_get_compare_via_slug( $pcp_list );
    $compare_owner_user_id = 0;
    if( array_key_exists( 'user_id', $compare_obj_array) ) {
        $compare_owner_user_id = $compare_obj_array['user_id'];
    }
    $is_compare_owner = 0;
    if( ( $current_user_id && $current_user_id == $compare_owner_user_id ) || $pcp_list == productive_commerce_get_compare_in_cookie() ) {
        $is_compare_owner = 1;
    }
    if( ( $current_user_id && $current_user_id != $compare_owner_user_id ) && $pcp_list == productive_commerce_get_compare_in_cookie() ) {
        productive_commerce_update_compare_ownership( $pcp_list, $current_user_id );
    }
    
    return array(
        'product_db_objects'        => $product_db_objects,
        'the_compare_object'        => $compare_obj_array,
        'is_compare_owner'          => $is_compare_owner,
    );
}

function _productive_commerce_get_compare_query_param() {
    global $wp_query;
    $pcp_list = '';
    if( isset( $wp_query->query_vars[PRODUCTIVE_COMMERCE_PLUGIN_COMPARE_QUERY_PARAM] ) ) {
        $pcp_list = $wp_query->query_vars[PRODUCTIVE_COMMERCE_PLUGIN_COMPARE_QUERY_PARAM];
    } else {
        // Refresh cookie, if neccessary
        productive_commerce_unset_compare_cookie_if_empty();
        if( isset( $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_COMPARE_COOKIE_PARAM] ) ) {
            $pcp_list = $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_COMPARE_COOKIE_PARAM];
        } else {
            $pcp_list = productive_commerce_set_and_get_compare_cookie_from_ls();
        }
    }
    return $pcp_list;
}

function productive_commerce_set_and_get_compare_cookie_from_ls() {
    $secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );
 ?>
    <script>
        function productive_commerce_js_generate_compare_cookie_from_ls() {
            let compare_slug = '';
            let site = '<?php echo PRODUCTIVE_COMMERCE_LOCALSTORE_SITE_ID; ?>';
            pcpCompares    = localStorage.getItem( 'pcpCompares'+site );
            if( null !== pcpCompares && '' !== pcpCompares ) {
                pcpComparesData = JSON.parse( pcpCompares );
                compare_slug = pcpComparesData[0].slug;
            }            
            let name = '<?php echo PRODUCTIVE_COMMERCE_PLUGIN_COMPARE_COOKIE_PARAM; ?>';
            let expires = parseInt( '<?php echo PRODUCTIVE_COMMERCE_PLUGIN_COOKIE_EXPIRES_IN; ?>' );
            let path = '<?php echo COOKIEPATH; ?>';
            let domain = '<?php echo COOKIE_DOMAIN; ?>';
            let secure = '<?php echo productive_commerce_get_content_to_render($secure); ?>';
            let cookie_param = name + "=" + compare_slug + "; expires=" + expires + "; path=" + path + "; domain=" + domain + "; secure=" + secure ;
            document.cookie = cookie_param;
        }
        productive_commerce_js_generate_compare_cookie_from_ls();
    </script>
<?php
    $pcp_list = '';
    if( isset( $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_COMPARE_COOKIE_PARAM] ) ) {
        $pcp_list = $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_COMPARE_COOKIE_PARAM];
    }
    return $pcp_list;
}

function productive_commerce_refresh_compare_in_cookie( $compare_slug ) {
    if( !isset( $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_COMPARE_COOKIE_PARAM] ) || 
            ( isset( $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_COMPARE_COOKIE_PARAM] ) && $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_COMPARE_COOKIE_PARAM] != $compare_slug ) ) {
        productive_global_setcookie( PRODUCTIVE_COMMERCE_PLUGIN_COMPARE_COOKIE_PARAM, $compare_slug, PRODUCTIVE_COMMERCE_PLUGIN_COOKIE_EXPIRES_IN);
    }
}

function productive_commerce_set_compare_in_cookie( $compare_slug ) {
    productive_global_setcookie( PRODUCTIVE_COMMERCE_PLUGIN_COMPARE_COOKIE_PARAM, $compare_slug, PRODUCTIVE_COMMERCE_PLUGIN_COOKIE_EXPIRES_IN);
}

function productive_commerce_get_compare_in_cookie() {
    $compare_in_cookie = '';
    if( isset( $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_COMPARE_COOKIE_PARAM] ) ) {
        $compare_in_cookie = $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_COMPARE_COOKIE_PARAM];
    }
    return $compare_in_cookie;
}

function productive_commerce_set_init_activate_user_compare_in_cookie() {
    // Trigers logged-in user Comparison aggregation
    productive_global_setcookie( PRODUCTIVE_COMMERCE_PLUGIN_INIT_ACTIVATE_USER_COMPARE_COOKIE_PARAM, 
            PRODUCTIVE_COMMERCE_PLUGIN_INIT_ACTIVATE_USER_COMPARE_COOKIE_PARAM, PRODUCTIVE_COMMERCE_PLUGIN_COOKIE_EXPIRES_IN);
}

function productive_commerce_get_init_activate_user_compare_in_cookie() {
    $deactivate_compare_in_cookie = '';
    if( isset( $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_INIT_ACTIVATE_USER_COMPARE_COOKIE_PARAM] ) ) {
        $deactivate_compare_in_cookie = $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_INIT_ACTIVATE_USER_COMPARE_COOKIE_PARAM];
    }
    return $deactivate_compare_in_cookie;
}

function productive_commerce_set_deactivate_user_compare_in_cookie() {
    // Trigers logged-out user Comparison aggregation
    productive_global_setcookie( PRODUCTIVE_COMMERCE_PLUGIN_DEACTIVATE_USER_COMPARE_COOKIE_PARAM, 
            PRODUCTIVE_COMMERCE_PLUGIN_DEACTIVATE_USER_COMPARE_COOKIE_PARAM, PRODUCTIVE_COMMERCE_PLUGIN_COOKIE_EXPIRES_IN);
}

function productive_commerce_get_deactivate_user_compare_in_cookie() {
    $deactivate_compare_in_cookie = '';
    if( isset( $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_DEACTIVATE_USER_COMPARE_COOKIE_PARAM] ) ) {
        $deactivate_compare_in_cookie = $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_DEACTIVATE_USER_COMPARE_COOKIE_PARAM];
    }
    return $deactivate_compare_in_cookie;
}

function productive_commerce_unset_compare_cookie_if_empty() {
    if( isset( $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_COMPARE_COOKIE_PARAM] ) && '' == $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_COMPARE_COOKIE_PARAM] ) {
        unset( $_COOKIE[PRODUCTIVE_COMMERCE_PLUGIN_COMPARE_COOKIE_PARAM] );
    }
}

function productive_commerce_render_social_share_for_compare( $misc ) {
    $share_url = productive_commerce_get_this_compare_page_url();
    
    $misc['section_content_social_media_share_email_subject']       = esc_html__('My Compare List ', 'productive-commerce') . get_bloginfo( 'name' );
    $misc['section_content_social_media_share_desc_for_pinterest']  = esc_html__('My Compare List ', 'productive-commerce') . get_bloginfo( 'name' );
    $misc['section_content_social_media_share_media']               = '';
    
    productive_global_do_social_shares( $misc, $share_url );
}

function productive_commerce_get_this_compare_page_url() {
    $pcp_url_raw = productive_commerce_compare_list_of_compares_page_url(); 
    $pcp_list = _productive_commerce_get_compare_query_param();
    // Using Endpoint
    if( strpos( get_option('permalink_structure'), 'postname' ) !== false ) {
        $page_path = $pcp_url_raw . '/' . $pcp_list;
        $url = esc_url( $page_path );
    } else {
        $url = add_query_arg( PRODUCTIVE_COMMERCE_PLUGIN_COMPARE_QUERY_PARAM, $pcp_list, $pcp_url_raw );
    }
    return $url; 
}

function productive_commerce_list_of_compares_redirect_rule() {
    $compares_page_slug = productive_commerce_compare_list_of_compares_page_slug();
    add_rewrite_tag('%'.PRODUCTIVE_COMMERCE_PLUGIN_COMPARE_QUERY_PARAM.'%', '([^&]+)');
    add_rewrite_rule( '^' . $compares_page_slug . '/([a-z0-9-]+)[/]?$', 'index.php?pagename=' . $compares_page_slug . '&' . PRODUCTIVE_COMMERCE_PLUGIN_COMPARE_QUERY_PARAM . '=$matches[1]', 'top' );
    
    productive_global_flush_rewrite_rule( PRODUCTIVE_COMMERCE_IS_REWRITE_RULE_FLUSHED_KEY );
    
}
add_action( 'init', 'productive_commerce_list_of_compares_redirect_rule' );

function productive_commerce_render_part_remove_from_compare_button( $product_id, $product_title, $layout_format, $section_style_other_buttons_hover_animation, $productiveminds_icon_remove_icon_add_to_args ) {
?>
    <span title="<?php esc_html_e('Remove', 'productive-commerce'); ?>" aria-label="<?php esc_html_e('Remove from Comparison', 'productive-commerce'); ?> <?php echo esc_html( get_the_title() ); ?>" 
       class="other_product_box_button delete_anchor productiveminds_section_container_compare_remove <?php echo esc_attr($product_id); ?> <?php echo esc_attr( $section_style_other_buttons_hover_animation ); ?>" 
       data-product_id="<?php echo esc_attr($product_id); ?>" data-product_title="<?php echo esc_attr($product_title); ?>" data-layout_format="<?php echo esc_attr($layout_format); ?>" 
       data-quantity="1">
        <?php 
            echo wp_kses( productiveminds_get_svg_icon( $productiveminds_icon_remove_icon_add_to_args ), 'wp_kses_allowed_html' );
         ?>
    </span>
<?php
}

function productive_commerce_prep_compare_products( $products ) {
    $product_qtys = '';
    if ( !empty( $products ) ) {
        $products_values = explode( '||', $products );
        foreach ( $products_values as $products_value ) {
            $product = explode( '|', $products_value );
            $product_qtys .= $product[0].'|'.$product[1].',';
        }
        $product_qtys = rtrim( $product_qtys, ',' );
    }
    return $product_qtys;
}


function productive_commerce_render_part_add_product_to_cart_button( $product_object, $product_id, $product_parent_id, $quantity, $layout_format, $is_customer_buyable, $product_type, $product_sku, $ajax_add_to_cart, $add_to_cart_class, $section_content_show_url_button_icon, $section_style_content_button_hover_animation, $productiveminds_icon_shopping_cart_icon ) {
    $add_to_cart_description = $product_object->add_to_cart_text();
    if( PRODUCTIVE_COMMERCE_PLUGIN_PRODUCT_TYPE_VARIABLE == $product_type ) {
        if( $is_customer_buyable ) {
        ?>
        <a aria-label="<?php echo esc_attr( 'Add to cart', 'productive-commerce' ); ?>"
            class="button add_to_cart_button <?php echo esc_attr($ajax_add_to_cart); ?> <?php echo esc_attr($add_to_cart_class); ?> <?php echo esc_attr( $section_style_content_button_hover_animation ); ?>" 
            data-product_id="<?php echo esc_attr($product_id); ?>" data-quantity="<?php echo esc_attr( $quantity ); ?>"
            data-product_sku="<?php echo esc_attr( $product_sku ); ?>" data-parent_id="<?php echo esc_attr( $product_parent_id ); ?>" data-layout_format="<?php echo esc_attr( $layout_format ); ?>"
            href="<?php echo esc_url( $product_object->add_to_cart_url() ); ?>" rel="nofollow">
            <?php
                if( $section_content_show_url_button_icon ) {
                    echo wp_kses( productiveminds_get_svg_icon( $productiveminds_icon_shopping_cart_icon ), 'wp_kses_allowed_html' );
                }
                echo esc_html__( 'Add to cart', 'productive-commerce' );
             ?>
        </a>
        <?php
        }
    } else {
        ?>
        <a aria-label="<?php echo esc_attr( $add_to_cart_description ); ?>"
            class="button add_to_cart_button <?php echo esc_attr($ajax_add_to_cart); ?> <?php echo esc_attr($add_to_cart_class); ?> <?php echo esc_attr( $section_style_content_button_hover_animation ); ?>" 
            data-product_id="<?php echo esc_attr($product_id); ?>" data-quantity="<?php echo esc_attr( $quantity ); ?>" 
            data-product_sku="<?php echo esc_attr( $product_sku ); ?>" data-parent_id="<?php echo esc_attr( $product_parent_id ); ?>" data-layout_format="<?php echo esc_attr( $layout_format ); ?>"
            href="<?php echo esc_url( $product_object->add_to_cart_url() ); ?>" rel="nofollow">
            <?php
                if( $section_content_show_url_button_icon ) {
                    echo wp_kses( productiveminds_get_svg_icon( $productiveminds_icon_shopping_cart_icon ), 'wp_kses_allowed_html' );
                }
                echo esc_html( $add_to_cart_description ); 
             ?>
        </a>
        <?php
    }
}

function productive_commerce_render_move_wishlist_product_button( $product_id, $product_title, $productiveminds_icon_navicon_icon_add_to_args, $layout_format ) {
?>
    <span class="move_wishlist <?php echo esc_attr($product_id); ?>" data-product_id="<?php echo esc_attr($product_id); ?>" data-product_title="<?php echo esc_attr($product_title); ?>" data-quantity="1" data-layout_format="<?php echo esc_attr($layout_format); ?>">
        <?php echo wp_kses( productiveminds_get_svg_icon( $productiveminds_icon_navicon_icon_add_to_args ), 'wp_kses_allowed_html' ); ?>
    </span>
<?php
}

function productive_commerce_render_move_compare_product_button( $product_id, $product_title, $productiveminds_icon_navicon_icon_add_to_args, $layout_format ) {
?>
    <span class="move_compare <?php echo esc_attr($product_id); ?>" data-product_id="<?php echo esc_attr($product_id); ?>" data-product_title="<?php echo esc_attr($product_title); ?>" data-quantity="1" data-layout_format="<?php echo esc_attr($layout_format); ?>">
        <?php echo wp_kses( productiveminds_get_svg_icon( $productiveminds_icon_navicon_icon_add_to_args ), 'wp_kses_allowed_html' ); ?>
    </span>
<?php
}

function productive_commerce_render_content_not_applicable_v_1() {
?>
    <div><?php esc_html_e('-', 'productive-commerce'); ?></div>
<?php
}

function productive_commerce_render_content_no_review_v_1() {
?>
    <div><?php esc_html_e('No review yet', 'productive-commerce'); ?></div>
<?php
}

function productive_commerce_get_woo_product_price_html( $product ) {
    if( !productive_global_is_woocommerce_active() || !productive_global_get_woo_product_return_wc_get_product_object( $product ) ) {
        return;
    }
    return $product->get_price_html();
}

function productive_commerce_get_content_to_render( $content ) {
    return $content;
}

function productive_commerce_add_items_loop_icons_all( $product, $params = array() ) {
    $args = array(
        'show_wishlist'         => 1,
        'show_compare'          => 1,
        'show_quickview'        => 1,
        'product'               => $product,
    );
    $args_params = array_merge( $args, $params);
    productive_commerce_add_items_loop_icons( $args_params );
}
function productive_commerce_add_items_loop_icons_without_wishlist( $product, $section_content_show_quickview_button = 0, $params = array() ) {
    $args = array(
        'show_wishlist'         => 0,
        'show_compare'          => 1,
        'show_quickview'        => $section_content_show_quickview_button,
        'product'               => $product,
    );
    $args_params = array_merge( $args, $params);
    productive_commerce_add_items_loop_icons( $args_params );
}
function productive_commerce_add_items_loop_icons_without_compare( $product, $section_content_show_quickview_button = 0, $params = array() ) {
    $args = array(
        'show_wishlist'         => 1,
        'show_compare'          => 0,
        'show_quickview'        => $section_content_show_quickview_button,
        'product'               => $product,
    );
    $args_params = array_merge( $args, $params);
    productive_commerce_add_items_loop_icons( $args_params );
}
function productive_commerce_add_items_loop_icons( $args ) {
    if( productive_commerce_is_extra() ) {
        productive_commerce_add_button_loop_extra( $args );
    } else {
        productive_commerce_add_button_loop( $args );
    }
}


function productive_commerce_render_woo_product_add_to_cart( $misc, $hierarchy = 'overlay' ) {
    
    $product             = null;
    if( isset( $misc['product'] )) {
        $product = $misc['product'];
    }
    if( null == $product && ( $product instanceof WC_Product ) ) {
        return;
    }
    
    $button_style             = 'icon_only';
    if( isset( $misc['button_style'] )) {
        $button_style = $misc['button_style'];
    }
    
    $button_hover_animation             = '';
    if( isset( $misc['button_hover_animation'] )) {
        $button_hover_animation = $misc['button_hover_animation'];
    }

    $quantity = 1;
    
    $product_id = $product->get_id();
    $add_to_cart_description = $product->add_to_cart_text();
    $product_type = $product->get_type();
    $is_purchasable = $product->is_purchasable();
    $is_in_stock = $product->is_in_stock();
    $backorders_allowed = $product->backorders_allowed();

    $ajax_add_to_cart = '';
    $is_customer_buyable = $is_purchasable && ( $is_in_stock || $backorders_allowed );
    if ( $product->supports( 'ajax_add_to_cart' ) && $is_customer_buyable ) {
        $ajax_add_to_cart = ' ajax_add_to_cart';
    }

    $add_to_cart_icon_args = array(
        'i'=> 'shopping-cart',
        'w'=>18,
        'h'=>18,
        'css'=> '',
    );

    $details_icon_args = array(
        'i'=> 'external-link',
        'w'=>18,
        'h'=>18,
        'css'=> '',
    );
    
    $add_to_cart_class = '';
    $cart_icon_args = $details_icon_args;
    if ( PRODUCTIVE_COMMERCE_PLUGIN_PRODUCT_TYPE_SIMPLE == $product_type && $is_in_stock ) {
        $cart_icon_args = $add_to_cart_icon_args;
        $add_to_cart_class = 'add_single_to_cart_button ' . $product_id;
    }
    
    ?>
    <span class="product-element-item-add_to_cart <?php echo esc_attr($hierarchy); ?> productiveminds-alignable-container flexed flexed-in-a-flexed align-items-center align-content-center gap-10px">
        <a aria-label="<?php echo esc_attr( $add_to_cart_description ); ?>"
            class="button add_to_cart_button aslink <?php echo esc_attr($ajax_add_to_cart); ?> <?php echo esc_attr($add_to_cart_class); ?> <?php echo esc_attr( $button_hover_animation ); ?> productiveminds-alignable-container flexed flexed-in-a-flexed align-items-center align-content-center gap-5px" 
            data-product_id="<?php echo esc_attr($product_id); ?>" data-quantity="<?php echo esc_attr( $quantity ); ?>" 
            href="<?php echo esc_url( $product->add_to_cart_url() ); ?>" rel="nofollow">
            <?php
                if( 'left_icon' == $button_style || 'icon_only' == $button_style ) {
                    echo wp_kses( productiveminds_get_svg_icon( $cart_icon_args ), 'wp_kses_allowed_html' );
                }
                if( 'icon_only' != $button_style ) {
                    echo '<span>' . esc_html($add_to_cart_description) . '</span>'; 
                }
                if( 'right_icon' == $button_style ) {
                    echo wp_kses( productiveminds_get_svg_icon( $cart_icon_args ), 'wp_kses_allowed_html' );
                }
             ?>
        </a>
    </span>
<?php
}

// Website Header Buttons
 
// Start:: Wishlist and Mini-Wishlist  Header Button
function productive_commerce_render_wishlist_button( $cpt_section_args = array() ) {
    
    if( !productive_global_is_woocommerce_active() ) {
        return;
    }
    
    $section_content_icon = productive_commerce_wishlist_section_header_button_icon();
    $section_content_icon_size = productive_commerce_wishlist_section_header_button_icon_size();
    $section_content_text = productive_commerce_wishlist_section_header_button_text();
    $section_content_show_counter = productive_commerce_wishlist_section_header_button_show_count();
    $section_content_counter_borderred = 'is_borderred';
    $section_content_show_subtotal = 'hide';//productive_commerce_wishlist_section_header_button_show_subtotal();
    $section_content_counter_location = productive_commerce_wishlist_section_header_button_show_count();
    $section_is_page_link = 0;
    
    if ( isset( $cpt_section_args['section_content_icon_size'] ) ) {
        $section_content_icon_size = intval( $cpt_section_args['section_content_icon_size'] );
    }
    if ( isset( $cpt_section_args['section_content_icon'] ) ) {
        $section_content_icon = sanitize_text_field( $cpt_section_args['section_content_icon'] );
    }
    if ( isset( $cpt_section_args['section_content_text'] ) ) {
        $section_content_text = sanitize_text_field( $cpt_section_args['section_content_text'] );
    }
    if ( isset( $cpt_section_args['section_content_show_counter'] ) ) {
        $section_content_show_counter = intval( $cpt_section_args['section_content_show_counter'] );
    }
    if ( isset( $cpt_section_args['section_content_counter_location'] ) ) {
        $section_content_counter_location = sanitize_text_field( $cpt_section_args['section_content_counter_location'] );
    }
    if ( isset( $cpt_section_args['section_content_counter_borderred'] ) ) {
        $section_content_counter_borderred = sanitize_text_field( $cpt_section_args['section_content_counter_borderred'] );
    }
    if ( isset( $cpt_section_args['section_content_show_subtotal'] ) ) {
        $section_content_show_subtotal = sanitize_text_field( $cpt_section_args['section_content_show_subtotal'] );
    }
    if ( isset( $cpt_section_args['section_is_page_link'] ) ) {
        $section_is_page_link = intval( $cpt_section_args['section_is_page_link'] );
    }
    
    $item_action_css = '';
    $item_action_url = productive_commerce_wishlist_list_of_wishlists_page_url();
    $is_miniwishlist_active = 0;
    if( productive_commerce_is_extra() ) {
        $is_miniwishlist_active = is_on_productive_commerce_miniwishlist_enable();
    }
    if( $is_miniwishlist_active && !$section_is_page_link && !is_productive_wishlist_page() ) {
        $item_action_css = 'productive_miniwishlist_button';
    } else if( is_productive_wishlist_page() ) {
        $item_action_url = '#';
    }
    
    $section_header_button_icon_args = array(
        'i'     => $section_content_icon,
        'w'     => $section_content_icon_size,
        'h'     => $section_content_icon_size,
        'css'   => '',
        'svg_css'   => ''
    );
    
?>
    <span class="productiveminds_standard_header_button wishlist">
        <a title="<?php echo PRODUCTIVE_COMMERCE_WISHLIST_CONCEPT_NAME; ?>"
           aria-label="<?php echo PRODUCTIVE_COMMERCE_WISHLIST_CONCEPT_NAME; ?>"
           class="cursored <?php echo esc_attr( $item_action_css ); ?> productiveminds-alignable-container flexed-no-wrap align-items-flex-end align-content-flex-end gap-5px"
           href="<?php echo esc_url( $item_action_url ); ?>">
            <?php if( 1 == 2 && 'position_left' == $section_content_show_subtotal ) {
                productive_commerce_render_wishlist_button_subtotal($section_content_show_subtotal);
            } ?>
            <span class="productiveminds-alignable-container flexed-no-wrap flexed-in-a-flexed align-items-flex-end align-content-flex-end gap-5px">
                <span class="header_button_icon_and_counter productiveminds-alignable-container <?php echo esc_attr( $section_content_counter_location ); ?>">
                    <span class="header_button_icon productiveminds-alignable-container">
                        <?php echo wp_kses( productiveminds_get_svg_icon( $section_header_button_icon_args ), 'wp_kses_allowed_html' ); ?>
                    </span>
                    <?php if( $section_content_show_counter ) { ?>
                        <span class="header_button_counter wishlist productiveminds-alignable-container <?php echo esc_attr( $section_content_counter_borderred ); ?>"><?php echo '0'; ?></span>
                    <?php } ?>
                </span>
                <?php if( !empty( $section_content_text ) ) { ?>
                    <span class="header_button_text">
                        <?php echo esc_html( $section_content_text ); ?>
                    </span>
                <?php } ?>
            </span>
            <?php if( 1 == 2 && 'position_right' == $section_content_show_subtotal ) {
                productive_commerce_render_wishlist_button_subtotal($section_content_show_subtotal);
            } ?>
        </a>
    </span>
<?php
}
add_shortcode('productive_wishlist_button', 'productive_commerce_render_wishlist_button');
add_action('productive_wishlist_button', 'productive_commerce_render_wishlist_button');

function productive_commerce_render_wishlist_button_subtotal( $section_content_show_subtotal ) {
    if( productive_commerce_is_extra() ) {
    ?>
        <span class="header_button_subtotal <?php echo esc_attr( $section_content_show_subtotal ); ?>">
            <span class="header_button_subtotal_amount"><?php echo wc_price( productive_commerce_get_wishlist_subtotal() ); ?></span>
        </span>
    <?php
    }
}


// Start:: Comparison and Mini-Comparison Header Button
function productive_commerce_render_compare_button( $cpt_section_args = array() ) {
    
    if( !productive_global_is_woocommerce_active() ) {
        return;
    }
    
    $section_content_icon = productive_commerce_compare_section_header_button_icon();
    $section_content_icon_size = productive_commerce_compare_section_header_button_icon_size();
    $section_content_text = productive_commerce_compare_section_header_button_text();
    $section_content_show_counter = productive_commerce_compare_section_header_button_show_count();
    $section_content_counter_borderred = 'is_borderred';
    $section_content_show_subtotal = 'hide';//productive_commerce_compare_section_header_button_show_subtotal();
    $section_content_counter_location = productive_commerce_compare_section_header_button_show_count();
    $section_is_page_link = 0;
    
    if ( isset( $cpt_section_args['section_content_icon_size'] ) ) {
        $section_content_icon_size = intval( $cpt_section_args['section_content_icon_size'] );
    }
    if ( isset( $cpt_section_args['section_content_icon'] ) ) {
        $section_content_icon = sanitize_text_field( $cpt_section_args['section_content_icon'] );
    }
    if ( isset( $cpt_section_args['section_content_text'] ) ) {
        $section_content_text = sanitize_text_field( $cpt_section_args['section_content_text'] );
    }
    if ( isset( $cpt_section_args['section_content_show_counter'] ) ) {
        $section_content_show_counter = intval( $cpt_section_args['section_content_show_counter'] );
    }
    if ( isset( $cpt_section_args['section_content_counter_location'] ) ) {
        $section_content_counter_location = sanitize_text_field( $cpt_section_args['section_content_counter_location'] );
    }
    if ( isset( $cpt_section_args['section_content_counter_borderred'] ) ) {
        $section_content_counter_borderred = sanitize_text_field( $cpt_section_args['section_content_counter_borderred'] );
    }
    if ( isset( $cpt_section_args['section_content_show_subtotal'] ) ) {
        $section_content_show_subtotal = sanitize_text_field( $cpt_section_args['section_content_show_subtotal'] );
    }
    if ( isset( $cpt_section_args['section_is_page_link'] ) ) {
        $section_is_page_link = intval( $cpt_section_args['section_is_page_link'] );
    }
    
    $item_action_css = '';
    $item_action_url = productive_commerce_compare_list_of_compares_page_url();
    $is_minicompare_active = 0;
    if( productive_commerce_is_extra() ) {
        $is_minicompare_active = is_on_productive_commerce_minicompare_enable();
    }
    if( $is_minicompare_active && !$section_is_page_link && !is_productive_compare_page() ) {
        $item_action_css = 'productive_minicompare_button';
    } else if( is_productive_compare_page() ) {
        $item_action_url = '#';
    }
    
    $section_header_button_icon_args = array(
        'i'     => $section_content_icon,
        'w'     => $section_content_icon_size,
        'h'     => $section_content_icon_size,
        'css'   => '',
        'svg_css'   => ''
    );
?>
    <span class="productiveminds_standard_header_button compare">
        <a title="<?php echo esc_attr( 'Comparison', 'productive-commerce'); ?>"
           aria-label="<?php echo esc_attr('Comparison', 'productive-commerce'); ?>"
           class="cursored <?php echo esc_attr( $item_action_css ); ?> productiveminds-alignable-container flexed-no-wrap align-items-flex-end align-content-flex-end gap-5px"
           href="<?php echo esc_url( $item_action_url ); ?>">
            <?php if( 'position_left' == $section_content_show_subtotal ) {
                productive_commerce_render_compare_button_subtotal($section_content_show_subtotal);
            } ?>
            <span class="productiveminds-alignable-container flexed-no-wrap flexed-in-a-flexed align-items-flex-end align-content-flex-end gap-5px">
                <span class="header_button_icon_and_counter productiveminds-alignable-container <?php echo esc_attr( $section_content_counter_location ); ?>">
                    <span class="header_button_icon productiveminds-alignable-container">
                        <?php echo wp_kses( productiveminds_get_svg_icon( $section_header_button_icon_args ), 'wp_kses_allowed_html' ); ?>
                    </span>
                    <?php if( $section_content_show_counter ) { ?>
                        <span class="header_button_counter compare productiveminds-alignable-container <?php echo esc_attr( $section_content_counter_borderred ); ?>"><?php echo '0'; ?></span>
                    <?php } ?>
                </span>
                <?php if( !empty( $section_content_text ) ) { ?>
                    <span class="header_button_text">
                        <?php echo esc_html( $section_content_text ); ?>
                    </span>
                <?php } ?>
            </span>
            <?php if( 'position_right' == $section_content_show_subtotal ) {
                productive_commerce_render_compare_button_subtotal($section_content_show_subtotal);
            } ?>
        </a>
    </span>
<?php
}
add_shortcode('productive_compare_button', 'productive_commerce_render_compare_button');
add_action('productive_compare_button', 'productive_commerce_render_compare_button');
function productive_commerce_render_compare_button_subtotal( $section_content_show_subtotal ) {
    ?>
    <span class="header_button_subtotal <?php echo esc_attr( $section_content_show_subtotal ); ?>">
        <span class="header_button_subtotal_amount"><?php //echo 'subtotal'; ?></span>
    </span>
    <?php
}


// Start:: Cart and MiniCart Header Button
function productive_commerce_render_minicart_button( $cpt_section_args = array() ) {
    
    if( !productive_global_is_woocommerce_active() ) {
        return;
    }
    
    $section_content_icon = productive_commerce_minicart_section_header_button_icon();
    $section_content_icon_size = productive_commerce_minicart_section_header_button_icon_size();
    $section_content_text = productive_commerce_minicart_section_header_button_text();
    $section_content_show_counter = productive_commerce_minicart_section_header_button_show_count();
    $section_content_counter_borderred = 'is_borderred';
    $section_content_show_subtotal = productive_commerce_minicart_section_header_button_show_subtotal();
    $section_content_counter_location = productive_commerce_minicart_section_header_button_show_count();
    $section_is_page_link = 0;
    
    if ( isset( $cpt_section_args['section_content_icon_size'] ) ) {
        $section_content_icon_size = intval( $cpt_section_args['section_content_icon_size'] );
    }
    if ( isset( $cpt_section_args['section_content_icon'] ) ) {
        $section_content_icon = sanitize_text_field( $cpt_section_args['section_content_icon'] );
    }
    if ( isset( $cpt_section_args['section_content_text'] ) ) {
        $section_content_text = sanitize_text_field( $cpt_section_args['section_content_text'] );
    }
    if ( isset( $cpt_section_args['section_content_show_counter'] ) ) {
        $section_content_show_counter = intval( $cpt_section_args['section_content_show_counter'] );
    }
    if ( isset( $cpt_section_args['section_content_counter_location'] ) ) {
        $section_content_counter_location = sanitize_text_field( $cpt_section_args['section_content_counter_location'] );
    }
    if ( isset( $cpt_section_args['section_content_counter_borderred'] ) ) {
        $section_content_counter_borderred = sanitize_text_field( $cpt_section_args['section_content_counter_borderred'] );
    }
    if ( isset( $cpt_section_args['section_content_show_subtotal'] ) ) {
        $section_content_show_subtotal = sanitize_text_field( $cpt_section_args['section_content_show_subtotal'] );
    }
    if ( isset( $cpt_section_args['section_is_page_link'] ) ) {
        $section_is_page_link = intval( $cpt_section_args['section_is_page_link'] );
    }
    
    $item_action_css = '';
    $item_action_url = get_permalink( wc_get_page_id( 'cart' ) );
    $is_minicart_active = 0;
    if(function_exists( 'productive_commerce_is_active' ) ) {
        $is_minicart_active = is_on_productive_commerce_minicart_enable();
    }
    if( $is_minicart_active && !$section_is_page_link && !is_cart() ) {
        $item_action_css = 'productive_minicart_button';
    } else if( is_cart() ) {
        $item_action_url = '#';
    }
    
    $section_header_button_icon_args = array(
        'i'     => $section_content_icon,
        'w'     => $section_content_icon_size,
        'h'     => $section_content_icon_size,
        'css'   => '',
        'svg_css'   => ''
    );
    $subtotal = 0;
    $content_count = 0;
    if( null != WC()->cart ) {
        $subtotal = WC()->cart->get_subtotal();
        $content_count = WC()->cart->get_cart_contents_count();
    }
?>
    <span class="productiveminds_standard_header_button cart">
        <a title="<?php echo esc_attr( 'Cart', 'productive-commerce'); ?>"
           aria-label="<?php echo esc_attr('Cart', 'productive-commerce'); ?>"
           class="cursored <?php echo esc_attr( $item_action_css ); ?> productiveminds-alignable-container flexed-no-wrap align-items-flex-end align-content-flex-end gap-5px"
           href="<?php echo esc_url( $item_action_url ); ?>">
            <?php if( 'position_left' == $section_content_show_subtotal ) {
                productive_commerce_render_minicart_button_subtotal( $section_content_show_subtotal, $subtotal );
            } ?>
            <span class="productiveminds-alignable-container flexed-no-wrap flexed-in-a-flexed align-items-flex-end align-content-flex-end gap-5px">
                <span class="header_button_icon_and_counter productiveminds-alignable-container <?php echo esc_attr( $section_content_counter_location ); ?>">
                    <span class="header_button_icon productiveminds-alignable-container">
                        <?php echo wp_kses( productiveminds_get_svg_icon( $section_header_button_icon_args ), 'wp_kses_allowed_html' ); ?>
                    </span>
                    <?php if( $section_content_show_counter ) { ?>
                    <span class="header_button_counter cart productiveminds-alignable-container <?php echo esc_attr( $section_content_counter_borderred ); ?>"><?php echo esc_html( $content_count ); ?></span>
                    <?php } ?>
                </span>
                <?php if( !empty( $section_content_text ) ) { ?>
                    <span class="header_button_text">
                        <?php echo esc_html( $section_content_text ); ?>
                    </span>
                <?php } ?>
            </span>
            <?php if( 'position_right' == $section_content_show_subtotal ) {
                productive_commerce_render_minicart_button_subtotal( $section_content_show_subtotal, $subtotal);
            } ?>
        </a>
    </span>
<?php
}
add_shortcode('productive_minicart_button', 'productive_commerce_render_minicart_button');
add_action('productive_minicart_button', 'productive_commerce_render_minicart_button');
function productive_commerce_render_minicart_button_subtotal( $section_content_show_subtotal, $subtotal ) {
    ?>
    <span class="header_button_subtotal <?php echo esc_attr( $section_content_show_subtotal ); ?>">
        <span class="header_button_subtotal_amount"><?php echo wc_price( $subtotal ); ?></span>
    </span>
    <?php
}


// Start:: Woo My Account Button
function productive_commerce_render_woo_account_button( $cpt_section_args = array() ) {
    
    if( !productive_global_is_woocommerce_active() ) {
        return;
    }
    
    $section_content_icon = 'user-o';
    $section_content_icon_size = 25;
    $section_content_text = '';
    $section_content_counter_location = '';
    $section_content_login_popup = 0;
    
    if ( isset( $cpt_section_args['section_content_icon_size'] ) ) {
        $section_content_icon_size = intval( $cpt_section_args['section_content_icon_size'] );
    }
    if ( isset( $cpt_section_args['section_content_icon'] ) ) {
        $section_content_icon = sanitize_text_field( $cpt_section_args['section_content_icon'] );
    }
    if ( isset( $cpt_section_args['section_content_text'] ) ) {
        $section_content_text = sanitize_text_field( $cpt_section_args['section_content_text'] );
    }
    if ( isset( $cpt_section_args['section_content_counter_location'] ) ) {
        $section_content_counter_location = sanitize_text_field( $cpt_section_args['section_content_counter_location'] );
    }
    if ( isset( $cpt_section_args['section_content_login_popup'] ) ) {
        $section_content_login_popup = intval( sanitize_text_field( $cpt_section_args['section_content_login_popup'] ) );
    }
    
    $item_action_css = '';
    $item_action_url = get_permalink( wc_get_page_id( 'myaccount' ) );
    $item_action_popup_open = '';
    if( $section_content_login_popup ) {
        $item_action_css = 'productive_account_login_popup_el';
        $item_action_url = '#';
        $item_action_popup_open = 'productive_account_login_popup_id';
    }
    
    $section_header_button_icon_args = array(
        'i'     => $section_content_icon,
        'w'     => $section_content_icon_size,
        'h'     => $section_content_icon_size,
        'css'   => '',
        'svg_css'   => ''
    );
?>
    <span class="productiveminds_standard_header_button woo-my-account">
        <a title="<?php echo esc_attr( 'My Account', 'productive-commerce'); ?>"
           data-open-popup="<?php echo esc_attr($item_action_popup_open); ?>"
           aria-label="<?php echo esc_attr('My Account', 'productive-commerce'); ?>"
           class="cursored <?php echo esc_attr( $item_action_css ); ?> productiveminds-alignable-container flexed-no-wrap align-items-flex-end align-content-flex-end gap-5px"
           href="<?php echo esc_url( $item_action_url ); ?>">
            <span class="productiveminds-alignable-container flexed-no-wrap flexed-in-a-flexed align-items-flex-end align-content-flex-end gap-5px">
                <span class="header_button_icon_and_counter productiveminds-alignable-container <?php echo esc_attr( $section_content_counter_location ); ?>">
                    <span class="header_button_icon productiveminds-alignable-container">
                        <?php echo wp_kses( productiveminds_get_svg_icon( $section_header_button_icon_args ), 'wp_kses_allowed_html' ); ?>
                    </span>
                </span>
                <?php if( !empty( $section_content_text ) ) { ?>
                    <span class="header_button_text">
                        <?php echo esc_html( $section_content_text ); ?>
                    </span>
                <?php } ?>
            </span>
        </a>
    </span>
<?php
}
add_shortcode('productive_woo_my_account_button', 'productive_commerce_render_woo_account_button');
add_action('productive_woo_my_account_button', 'productive_commerce_render_woo_account_button');


// Start:: Search Button
function productive_commerce_render_the_search_button( $cpt_section_args = array() ) {
    
    if( !productive_global_is_woocommerce_active() ) {
        return;
    }
    
    $section_content_icon = 'user-o';
    $section_content_icon_size = 25;
    $section_content_text = '';
    $section_content_counter_location = '';
    
    if ( isset( $cpt_section_args['section_content_icon_size'] ) ) {
        $section_content_icon_size = intval( $cpt_section_args['section_content_icon_size'] );
    }
    if ( isset( $cpt_section_args['section_content_icon'] ) ) {
        $section_content_icon = sanitize_text_field( $cpt_section_args['section_content_icon'] );
    }
    if ( isset( $cpt_section_args['section_content_text'] ) ) {
        $section_content_text = sanitize_text_field( $cpt_section_args['section_content_text'] );
    }
    if ( isset( $cpt_section_args['section_content_counter_location'] ) ) {
        $section_content_counter_location = sanitize_text_field( $cpt_section_args['section_content_counter_location'] );
    }
    
    $item_action_css = 'productive_search_icon_button';
    $item_action_url = '#';
    
    $section_header_button_icon_args = array(
        'i'     => $section_content_icon,
        'w'     => $section_content_icon_size,
        'h'     => $section_content_icon_size,
        'css'   => '',
        'svg_css'   => ''
    );
?>
    <span class="productiveminds_standard_header_button search">
        <a data-open-popup="productive_global_search_popup_container"
            title="<?php echo esc_attr( 'Search', 'productive-commerce'); ?>"
           aria-label="<?php echo esc_attr('Search', 'productive-commerce'); ?>"
           class="header_button_icon_container_anchor cursored <?php echo esc_attr( $item_action_css ); ?> productiveminds-alignable-container flexed-no-wrap align-items-flex-end align-content-flex-end gap-5px"
           href="<?php echo esc_url( $item_action_url ); ?>">
            <span class="productiveminds-alignable-container flexed-no-wrap flexed-in-a-flexed align-items-flex-end align-content-flex-end gap-5px">
                <span class="header_button_icon_and_counter productiveminds-alignable-container <?php echo esc_attr( $section_content_counter_location ); ?>">
                    <span class="header_button_icon productiveminds-alignable-container">
                        <?php echo wp_kses( productiveminds_get_svg_icon( $section_header_button_icon_args ), 'wp_kses_allowed_html' ); ?>
                    </span>
                </span>
                <?php if( !empty( $section_content_text ) ) { ?>
                    <span class="header_button_text">
                        <?php echo esc_html( $section_content_text ); ?>
                    </span>
                <?php } ?>
            </span>
        </a>
    </span>
<?php
}
add_shortcode('productive_search_button', 'productive_commerce_render_the_search_button');
add_action('productive_search_button', 'productive_commerce_render_the_search_button');


function productive_commerce_woocommerce_before_shop_loop() {
    remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
    remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
    do_action( 'woocommerce_before_shop_loop' );
}

function productive_commerce_remove_review_tab( $template ) {
    $template = PRODUCTIVE_COMMERCE_PLUGIN_PATH . 'includes/common/comments-none.php';
    return $template;
}
