Advertisement
danrancan

wp-content/themes/h-code/lib/hcode-woocommerce-functions.php

Jul 6th, 2023
814
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 41.30 KB | Source Code | 0 0
  1. //  /var/www/mcmo.is/wp-content/themes/h-code/lib/hcode-woocommerce-functions.php //
  2. <?php
  3. /**
  4.  * WooCommerce Extra Function.
  5.  *
  6.  * @package H-Code
  7.  */
  8. ?>
  9. <?php
  10. if ( class_exists( 'WooCommerce' ) ){
  11.  
  12.     /* For Woocommerce Color Attributele */
  13.     $hcode_options           = get_option( 'hcode_theme_setting' );
  14.     $hcode_color_attributele = ( isset( $hcode_options['hcode_color_attributele'] ) ) ? $hcode_options['hcode_color_attributele'] : '';
  15.  
  16.     if( $hcode_color_attributele && ( $hcode_options['hcode_enable_color_attribute'] == 1) ):
  17.         add_action( 'pa_'.$hcode_color_attributele.'_add_form_fields', 'hcode_add_color_field', 10, 2 );
  18.         add_action( 'pa_'.$hcode_color_attributele.'_edit_form_fields', 'hcode_edit_color_field', 10, 2 );
  19.         add_action( 'edited_pa_'.$hcode_color_attributele, 'hcode_save_taxonomy_custom_field_color', 10, 2 );
  20.         add_action( 'create_pa_'.$hcode_color_attributele, 'hcode_save_taxonomy_custom_field_color', 10, 2 );
  21.     endif;
  22.  
  23.     // Add H-Code Custom Product Tabs
  24.     if ( ! function_exists( 'hcode_custom_tab_options_tab' ) ) {
  25.         function hcode_custom_tab_options_tab() {
  26.  
  27.             echo '<li class="custom_tab wc-special-product"><a href="#custom_tab_data">'.esc_html( 'Special Product', 'H-Code' ).'</a></li>';
  28.             echo '<li class="custom_tab wc-washing-instruction"><a href="#washing_instruction">'.esc_html( 'Washing Instructions', 'H-Code' ).'</a></li>';
  29.             echo '<li class="custom_tab wc-sizes"><a href="#sizes_tab">'.esc_html( 'Sizes', 'H-Code' ).'</a></li>';
  30.         }
  31.     }
  32.     add_action( 'woocommerce_product_write_panel_tabs', 'hcode_custom_tab_options_tab' );
  33.  
  34.     if ( ! function_exists( 'hcode_custom_tab_options' ) ) {
  35.         function hcode_custom_tab_options() {
  36.             global $post;
  37.             $hcode_feature_product_order = array(
  38.                 'hcode_feature_product_order' => get_post_meta( $post->ID, 'hcode_feature_product_order', true ),
  39.             );
  40.             $hcode_feature_product_shop = array(
  41.                 'hcode_feature_product_shop' => get_post_meta( $post->ID, 'hcode_feature_product_shop', true ),
  42.             );
  43.             $hcode_new_product_shop = array(
  44.                 'hcode_new_product_shop' => get_post_meta( $post->ID, 'hcode_new_product_shop', true ),
  45.             );
  46.  
  47.             echo '<div id="custom_tab_data" class="panel woocommerce_options_panel">';
  48.                 echo '<div class="options_group custom_tab_options">';
  49.                     echo '<p class="form-field">';
  50.                         echo '<label>'.esc_html( 'Order:', 'H-Code' ).'</label>';
  51.                         echo '<input type="text" name="hcode_feature_product_order" placeholder="'.esc_html( 'Enter your Order', 'H-Code' ).'" value="'.esc_html( $hcode_feature_product_order['hcode_feature_product_order'] ).'">';
  52.                     echo '</p>';
  53.                     echo '<p class="form-field">';
  54.                         echo '<label>'.esc_html( 'Feature:', 'H-Code' ).'</label>';
  55.                             $features_prod=$hcode_feature_product_shop['hcode_feature_product_shop'];
  56.                         ?>
  57.                         <select name="hcode_feature_product_shop" class="hcode_feature_product" id="feature_product">
  58.                             <option value=""><?php echo esc_html( 'Select One', 'H-Code' ); ?></option>
  59.                             <option value="yes"<?php selected( $features_prod, 'yes' ); ?>><?php echo esc_html( 'Yes', 'H-Code' ); ?></option>
  60.                             <option value="no"<?php selected( $features_prod, 'no' ); ?>><?php echo esc_html( 'No', 'H-Code' ); ?></option>
  61.                         </select>
  62.                         <?php
  63.                     echo '</p>';
  64.                     echo '<p class="form-field">';
  65.                         echo '<label>'.esc_html( 'New Product:', 'H-Code' ).'</label>';
  66.                             $new_prod=$hcode_new_product_shop['hcode_new_product_shop'];
  67.                         ?>
  68.                         <select name="hcode_new_product_shop" class="hcode_feature_product" id="new_product">
  69.                             <option value=""><?php echo esc_html( 'Select One', 'H-Code' ); ?></option>
  70.                             <option value="yes"<?php selected( $new_prod, 'yes' ); ?>><?php echo esc_html( 'Yes', 'H-Code' ); ?></option>
  71.                             <option value="no"<?php selected( $new_prod, 'no' ); ?>><?php echo esc_html( 'No', 'H-Code' ); ?></option>
  72.                         </select>
  73.                         <?php
  74.                     echo '</p>';
  75.                 echo '</div>';
  76.             echo '</div>';
  77.         }
  78.     }
  79.     add_action( 'woocommerce_product_data_panels', 'hcode_custom_tab_options' );
  80.  
  81.     if ( ! function_exists( 'hcode_sizes_tab' ) ) {
  82.         function hcode_sizes_tab() {
  83.             global $post;
  84.             $hcode_size_tab = '';
  85.             $meta_size_tab = get_post_meta( $post->ID, 'hcode_product_tabs_options', true );
  86.             if( isset( $meta_size_tab[0]['hcode_size_tab'] ) ) {
  87.                 $breaks = array( "<br />", "<br>", "<br/>" );
  88.                 $hcode_size_tab = ( $meta_size_tab[0]['hcode_size_tab'] ) ? str_ireplace( $breaks, " ", $meta_size_tab[0]['hcode_size_tab'] ) : '';
  89.             }
  90.  
  91.             echo '<div id="sizes_tab" class="panel woocommerce_options_panel">';
  92.                 echo '<div class="options_group custom_tab_options">';
  93.                     echo '<p class="form-field">';
  94.                         echo '<label>'.esc_html( 'Sizes Description:', 'H-Code' ).'</label>';
  95.                         echo '<textarea class="theEditor" rows="10" cols="40" name="hcode_size_tab" placeholder="'.esc_html( 'Enter your sizes content', 'H-Code' ).'" style="height:250px">'.$hcode_size_tab.'</textarea>';
  96.                     echo '</p>';
  97.                 echo '</div>';
  98.             echo '</div>';
  99.         }
  100.     }
  101.     add_action( 'woocommerce_product_data_panels', 'hcode_sizes_tab' );
  102.  
  103.     if ( ! function_exists( 'hcode_washing_instruction' ) ) {
  104.         function hcode_washing_instruction() {
  105.             global $post;
  106.             $hcode_washing_instruction = '';
  107.             $metabox_washing_instruction = get_post_meta( $post->ID, 'hcode_product_tabs_options', true );
  108.             if( isset( $metabox_washing_instruction[0]['hcode_washing_instruction'] ) ) {
  109.                 $breaks = array( "<br />", "<br>", "<br/>" );
  110.                 $hcode_washing_instruction = ( $metabox_washing_instruction[0]['hcode_washing_instruction'] ) ? str_ireplace( $breaks, " ", $metabox_washing_instruction[0]['hcode_washing_instruction'] ) : '';
  111.             }
  112.  
  113.             echo '<div id="washing_instruction" class="panel woocommerce_options_panel">';
  114.                 echo '<div class="options_group custom_tab_options">';
  115.                     echo '<p class="form-field">';
  116.                         echo '<label>'.esc_html( 'Washing Instruction:', 'H-Code' ).'</label>';
  117.                         echo '<textarea class="theEditor" rows="10" cols="40" name="hcode_washing_instruction" placeholder="'.esc_html( 'Enter your washing instruction', 'H-Code' ).'" style="height:250px">'.$hcode_washing_instruction.'</textarea>';
  118.                     echo '</p>';
  119.                 echo '</div>';
  120.             echo '</div>';
  121.         }
  122.     }
  123.     add_action( 'woocommerce_product_data_panels', 'hcode_washing_instruction' );
  124.  
  125.     if ( ! function_exists( 'hcode_process_product_meta_custom_tab' ) ) {
  126.         function hcode_process_product_meta_custom_tab( $post_id ) {
  127.  
  128.             update_post_meta( $post_id, 'hcode_feature_product_order', $_POST['hcode_feature_product_order'] );
  129.             update_post_meta( $post_id, 'hcode_feature_product_shop', $_POST['hcode_feature_product_shop'] );
  130.  
  131.             /* field array */
  132.             $data_args = $options_value = array();
  133.  
  134.             /* sizes */
  135.             if( $_POST['hcode_size_tab'] ) {
  136.                 $data_args['hcode_size_tab'] = stripslashes( nl2br( $_POST['hcode_size_tab'] ) );
  137.                 update_post_meta( $post_id, 'hcode_size_tab',  $_POST['hcode_size_tab'] );
  138.             }
  139.  
  140.             /* washing instruction */
  141.             if( $_POST['hcode_washing_instruction'] ) {
  142.                 update_post_meta( $post_id, 'hcode_washing_instruction', serialize( $_POST['hcode_washing_instruction'] ) );
  143.                 $data_args['hcode_washing_instruction'] = stripslashes( nl2br( $_POST['hcode_washing_instruction'] ) );
  144.             }
  145.  
  146.             $options_value[] = $data_args;
  147.             update_post_meta( $post_id, 'hcode_product_tabs_options', $options_value );
  148.         }
  149.     }
  150.     add_action( 'woocommerce_process_product_meta', 'hcode_process_product_meta_custom_tab' );
  151.  
  152.     // Remove Woocommerce setup screen.
  153.     remove_action( 'admin_init', 'setup_wizard' );
  154.  
  155.     if ( ! function_exists( 'hcode_remove_woocommerce_admin_notice' ) ) {
  156.         function hcode_remove_woocommerce_admin_notice() {
  157.             if ( class_exists( 'WC_Admin_Notices' ) ) {
  158.                 // Remove the "you have outdated template files" nag
  159.                 WC_Admin_Notices::remove_notice( 'template_files' );
  160.  
  161.                 // Remove the "install pages" nag
  162.                 WC_Admin_Notices::remove_notice( 'install' );
  163.             }
  164.         }
  165.     }
  166.     add_action( 'wp_loaded', 'hcode_remove_woocommerce_admin_notice', 99 );
  167.  
  168.     // Hide the "install the WooThemes Updater"
  169.     remove_action( 'admin_notices', 'woothemes_updater_notice' );
  170.  
  171.     // To Remove woocommerce_breadcrumb Action And Add New Action For Breadcrumb
  172.     remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );
  173.     add_action( 'hcode_woocommerce_breadcrumb', 'hcode_woocommerce_breadcrumb', 20, 0 );
  174.     /* Woocommerce Breadcrumb*/
  175.     if ( ! function_exists( 'hcode_woocommerce_breadcrumb' ) ) {
  176.         function hcode_woocommerce_breadcrumb( $args = array() ) {
  177.             $args = wp_parse_args( $args, apply_filters( 'woocommerce_breadcrumb_defaults', array(
  178.                 'delimiter'   => '',
  179.                 'wrap_before' => '',
  180.                 'wrap_after'  => '',
  181.                 'before'      => '',
  182.                 'after'       => '',
  183.                 'home'        => esc_html__( 'Home', 'H-Code' )
  184.             ) ) );
  185.  
  186.             $breadcrumbs = new WC_Breadcrumb();
  187.  
  188.             if ( $args['home'] ) {
  189.                 $breadcrumbs->add_crumb( $args['home'], apply_filters( 'woocommerce_breadcrumb_home_url', home_url( '/' ) ) );
  190.             }
  191.  
  192.             $args['breadcrumb'] = $breadcrumbs->generate();
  193.  
  194.             wc_get_template( 'global/breadcrumb.php', $args );
  195.         }
  196.     }
  197.  
  198.     /* Naxt and Prev button on product pages */
  199.     if ( ! function_exists( 'hcode_woocommerce_next_prev' ) ) {
  200.         function hcode_woocommerce_next_prev( $args = array() ) {
  201.  
  202.             global $post;
  203.  
  204.             if( is_shop() ) return;
  205.             $current_url = get_permalink( $post->ID );
  206.  
  207.             // Get the previous and next product links
  208.             $previous_link = get_permalink(get_adjacent_post(false,'',false));
  209.             $next_link = get_permalink(get_adjacent_post(false,'',true));
  210.  
  211.             // Create the two links provided the product exists
  212.             if ( $previous_link != $current_url ) {
  213.                 echo '<a rel="previous" class="black-text-link" href="' . $previous_link . '"><i class="fa-solid fa-angle-left"></i> '.esc_html__("Previous",'H-Code').'</a>';
  214.             }
  215.             if ( $next_link != $current_url ) {
  216.                 echo '<a rel="next" class="black-text-link" href="' . $next_link . '">'.esc_html__('Next','H-Code').'<i class="fa-solid fa-angle-right"></i></a>';
  217.             }
  218.  
  219.         }
  220.     }
  221.  
  222.     remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
  223.  
  224.     remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_meta',40);
  225.     /* H-Code V1.8 add category and tags */
  226.     add_action('woocommerce_single_product_summary', 'woocommerce_template_single_meta',60);
  227.  
  228.     remove_action('woocommerce_single_product_summary','woocommerce_template_single_rating',10);
  229.     // H-Code 2.0
  230.     $hcode_options = get_option( 'hcode_theme_setting' );
  231.     $enable_product_rating = ( isset( $hcode_options['enable_product_rating'] ) && !empty( $hcode_options['enable_product_rating'] ) ) ? $hcode_options['enable_product_rating'] : '';
  232.     if( $enable_product_rating == 1 ) {
  233.         add_action('hcode_woocommerce_product_single_rating_sku','woocommerce_template_single_rating',10);
  234.     }
  235.     // Show price after woocommerce_template_single_excerpt
  236.     remove_action('woocommerce_single_product_summary','woocommerce_template_single_price',10);
  237.     add_action('woocommerce_single_product_summary','woocommerce_template_single_price',20);
  238.     // TO remove rating in related product
  239.     remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
  240.  
  241.     // To remove Sale! from product
  242.     remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );
  243.     remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash', 10 );
  244.     add_action( 'hcode_sale_flash', 'woocommerce_show_product_loop_sale_flash', 10 );
  245.  
  246.     // related product config
  247.     remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
  248.     add_action( 'woocommerce_after_single_product_summary', 'hcode_related_products', 20 );
  249.     if ( ! function_exists( 'hcode_related_products' ) ) {
  250.  
  251.         function hcode_related_products() {
  252.             $args = array(
  253.                 'posts_per_page' => ( hcode_option('related_product_show_no') ) ? hcode_option('related_product_show_no') : 7,
  254.                 'orderby' => 'rand'
  255.             );
  256.             woocommerce_related_products( apply_filters( 'woocommerce_output_related_products_args', $args ) );
  257.         }
  258.     }
  259.  
  260.     add_action('hcode_woocommerce_product_single_rating_sku', 'hcode_woocommerce_product_single_sku',40);
  261.     if ( ! function_exists( 'hcode_woocommerce_product_single_sku' ) ) {
  262.         function hcode_woocommerce_product_single_sku(){
  263.             global $post, $product;
  264.             $enable_product_sku = hcode_option( 'enable_product_sku' );
  265.             if ( $enable_product_sku == 1 && wc_product_sku_enabled() && ( $product->get_sku() || $product->is_type( 'variable' ) ) ) : ?>
  266.                     <div class="product_meta">
  267.                         <span class="rating-text text-uppercase">
  268.                             <?php echo __( 'SKU:', 'H-Code' ); ?>
  269.                             <span class="sku black-text" itemprop="sku">
  270.                                 <?php echo ( $sku = $product->get_sku() ) ? $sku : ''; ?>
  271.                             </span>
  272.                         </span>
  273.                     </div>
  274.             <?php endif;
  275.         }
  276.     }
  277.  
  278.     /* Product Title And Stock Action For Responsive Version Start */
  279.     add_action ('woocommerce_product_title_responsive', 'woocommerce_template_single_title',5);
  280.     add_action ('woocommerce_product_title_responsive', 'hcode_woocommerce_template_single_stock_and_shipping_available',5);
  281.     /* Product Title And Stock Action For Responsive Version End */
  282.  
  283.  
  284.     remove_action ('woocommerce_single_product_summary', 'woocommerce_template_single_title',5);
  285.  
  286.     add_action( 'hcode_woocommerce_product_list_excerpt', 'woocommerce_template_single_excerpt', 20 );
  287.  
  288.     add_action ( 'hcode_woocommerce_product_title_stock_and_shipping_available', 'hcode_woocommerce_template_single_stock_and_shipping_available', 5 );
  289.     if ( ! function_exists( 'hcode_woocommerce_template_single_stock_and_shipping_available' ) ) {
  290.         function hcode_woocommerce_template_single_stock_and_shipping_available(){
  291.             global $post, $product;
  292.             $stock = $shipping_available = $separatorline = '';
  293.             $enable_product_stock_status = hcode_option( 'enable_product_stock_status' );
  294.             $enable_product_shipping = hcode_option( 'enable_product_shipping' );
  295.             $hcode_shipping_available_text = hcode_option( 'hcode_shipping_available_text' );
  296.             $availability = $product->get_availability();
  297.  
  298.             if ( $product->is_type( 'simple' ) && $availability['availability'] && $enable_product_stock_status ) :
  299.                 $stock = apply_filters( 'woocommerce_stock_html', esc_html( $availability['availability'] ), $availability['availability'] );
  300.             endif;
  301.             if( $product->is_type( 'simple' ) && $enable_product_stock_status ) :
  302.                 $stock = ( $stock ) ? $stock : __( 'In stock', 'H-Code' );
  303.             endif;
  304.             if( get_option('woocommerce_calc_shipping') == 'yes' && $enable_product_shipping && !$product->is_virtual() && ( $product->get_stock_status() !== 'outofstock' ) ) :
  305.                 $shipping_available = $hcode_shipping_available_text;
  306.             endif;
  307.             if( $stock && $shipping_available ):
  308.                 $separatorline = ' / ';
  309.             endif;
  310.             echo '<p class="text-uppercase letter-spacing-2 margin-two product-available">'.$stock.$separatorline.$shipping_available.'</p>';
  311.             echo '<div class="separator-line bg-black no-margin-lr margin-five"></div>';
  312.         }
  313.     }
  314.  
  315.     // check for empty-cart get param to clear the cart
  316.     add_action( 'init', 'hcode_woocommerce_clear_cart_url' );
  317.     if ( ! function_exists( 'hcode_woocommerce_clear_cart_url' ) ) {
  318.         function hcode_woocommerce_clear_cart_url() {
  319.           global $woocommerce;
  320.  
  321.             if ( isset( $_GET['empty-cart'] ) ) {
  322.                 $woocommerce->cart->empty_cart();
  323.             }
  324.         }
  325.     }
  326.  
  327.     /* Remove Woocommerce Default style */
  328.     add_filter( 'woocommerce_enqueue_styles', 'hcode_dequeue_woocommerce_styles' );
  329.     if ( ! function_exists( 'hcode_dequeue_woocommerce_styles' ) ) {
  330.         function hcode_dequeue_woocommerce_styles( $enqueue_styles ) {
  331.  
  332.             unset( $enqueue_styles['woocommerce-general'] );
  333.             unset( $enqueue_styles['woocommerce-layout'] );
  334.             unset( $enqueue_styles['woocommerce-smallscreen'] );
  335.             unset( $enqueue_styles['select2'] );
  336.             return $enqueue_styles;
  337.         }
  338.     }
  339.  
  340.     // To add custom color field in taxonomy "pa_color"
  341.     if ( ! function_exists( 'hcode_edit_color_field' ) ) {
  342.         function hcode_edit_color_field($term) {
  343.             // put the term ID into a variable
  344.  
  345.                 $t_id = $term->term_id;
  346.  
  347.             // retrieve the existing value(s) for this meta field. This returns an array
  348.             $term_meta = get_option( "taxonomy_$t_id" ); ?>
  349.             <tr class="form-field">
  350.             <th scope="row" valign="top"><label for="term_meta[custom_color]"><?php esc_html_e( 'Add color code with #', 'H-Code' ); ?></label></th>
  351.                 <td>
  352.                     <input type="text" name="term_meta[custom_color]" id="term_meta[custom_color]" value="<?php echo esc_attr( $term_meta['custom_color'] ) ? esc_attr( $term_meta['custom_color'] ) : ''; ?>">
  353.                     <p class="description"><?php esc_html_e( 'Enter a color code. ex. for white = #FFFFFF','H-Code' ); ?></p>
  354.                 </td>
  355.             </tr>
  356.         <?php
  357.         }
  358.     }
  359.  
  360.     if ( ! function_exists( 'hcode_add_color_field' ) ) {
  361.         function hcode_add_color_field( $term ){ ?>
  362.             <tr class="form-field">
  363.             <th scope="row" valign="top"><label for="term_meta[custom_color]"><?php esc_html_e( 'Add color code with #', 'H-Code' ); ?></label></th>
  364.                 <td>
  365.                     <input type="text" name="term_meta[custom_color]" id="term_meta[custom_color]" value="">
  366.                     <p class="description"><?php esc_html_e( 'Enter a color code. ex. for white = #FFFFFF','H-Code' ); ?></p>
  367.                 </td>
  368.             </tr>
  369.         <?php
  370.         }
  371.     }
  372.  
  373.     // Save extra taxonomy fields callback function.
  374.     if ( ! function_exists( 'hcode_save_taxonomy_custom_field_color' ) ) {
  375.         function hcode_save_taxonomy_custom_field_color( $term_id ) {
  376.             if ( isset( $_POST['term_meta'] ) ) {
  377.                 $t_id = $term_id;
  378.                 $term_meta = get_option( "taxonomy_$t_id" );
  379.                 $cat_keys = array_keys( $_POST['term_meta'] );
  380.                 foreach ( $cat_keys as $key ) {
  381.                     if ( isset ( $_POST['term_meta'][$key] ) ) {
  382.                         $term_meta[$key] = $_POST['term_meta'][$key];
  383.                     }
  384.                 }
  385.                 // Save the option array.
  386.                 update_option( "taxonomy_$t_id", $term_meta );
  387.             }
  388.         }
  389.     }
  390.  
  391.     add_filter('woocommerce_add_to_cart_fragments', 'hcode_add_to_cart_fragments');
  392.     if ( ! function_exists( 'hcode_add_to_cart_fragments' ) ) {
  393.         function hcode_add_to_cart_fragments( $fragments ) {
  394.             global $woocommerce;
  395.             ob_start();
  396.             ?>
  397.             <div class="hcode_shopping_cart_content">
  398.                 <?php wc_get_template( 'cart/mini-cart.php');?>
  399.             </div>
  400.             <?php
  401.             $fragments['.hcode_shopping_cart_content'] = ob_get_clean();
  402.             return $fragments;
  403.         }
  404.     }
  405.  
  406.     /* For Grid and List view in Woocommerce */
  407.  
  408.     if ( ! function_exists( 'hcode_woocommerce_category_view' ) ) :
  409.  
  410.         function hcode_woocommerce_category_view() {
  411.             $product_view_type = '';
  412.             $hcode_woocommerce_category_view_type = hcode_option( 'hcode_woocommerce_category_view_type' );
  413.             if( $hcode_woocommerce_category_view_type == 1 ):
  414.                 $product_view_type = ' product-grid-view';
  415.             elseif( $hcode_woocommerce_category_view_type == 2 ):
  416.                 $product_view_type = ' product-list-view';
  417.             else:
  418.             endif;
  419.             echo esc_attr( $product_view_type );
  420.         }
  421.     endif;
  422.  
  423.     /* For Woocommerce product Tabs */
  424.     add_filter( 'woocommerce_product_tabs', 'hcode_woo_rename_tabs', 10 );
  425.     if ( ! function_exists( 'hcode_woo_rename_tabs' ) ) {
  426.         function hcode_woo_rename_tabs( $tabs ) {
  427.             global $product, $post;
  428.  
  429.             // Description Additional Information First Tab
  430.             if ( $post->post_content ) :
  431.                 $tabs['description'] = array(
  432.                 'title'     => esc_html__( 'Details', 'H-Code' ),
  433.                 'priority'  => 10,
  434.                 'callback'  => 'woocommerce_product_description_tab'
  435.                );
  436.             endif;
  437.  
  438.             // Adds Washing Instructions Second Tab
  439.             $hcode_washing_instruction = get_post_meta( $post->ID, 'hcode_washing_instruction', true );
  440.             if( $hcode_washing_instruction ):
  441.                 $tabs['washing_instructions'] = array(
  442.                 'title'     => esc_html__( 'Washing Instructions', 'H-Code' ),
  443.                 'priority'  => 30,
  444.                 'callback'  => 'hcode_woocommerce_product_tab_instructions'
  445.                 );
  446.             endif;
  447.  
  448.             // Adds Sizing Third Tab
  449.             $hcode_size_tab = get_post_meta($post->ID, 'hcode_size_tab', true);
  450.             if ($hcode_size_tab):
  451.                 $tabs['sizing'] = array(
  452.                 'title'     => esc_html__( 'Sizing', 'H-Code' ),
  453.                 'priority'  => 35,
  454.                 'callback'  => 'hcode_woocommerce_product_tab_sizing'
  455.                 );
  456.             endif;
  457.  
  458.             // Reviews Last Tab
  459.             if ( comments_open() ) {
  460.                 $tabs['reviews']['priority'] = 40;
  461.             }
  462.  
  463.             return $tabs;
  464.         }
  465.     }
  466.  
  467.     if ( ! function_exists( 'hcode_woocommerce_product_tab_instructions' ) ) {
  468.         function hcode_woocommerce_product_tab_instructions() {
  469.             global $post;
  470.  
  471.             $meta_value = get_post_meta( $post->ID, 'hcode_product_tabs_options', true );
  472.  
  473.             if( !empty($meta_value) && isset( $meta_value[0]['hcode_washing_instruction'] )) {
  474.  
  475.                 $hcode_washing_instruction = ( $meta_value[0]['hcode_washing_instruction'] ) ? $meta_value[0]['hcode_washing_instruction'] : '';
  476.                 // Washing Instructions Content
  477.                 echo '<div class="col-md-12 col-sm-12 col-xs-12">'.$hcode_washing_instruction.'</div>';
  478.             }
  479.         }
  480.     }
  481.  
  482.     if ( ! function_exists( 'hcode_woocommerce_product_tab_sizing' ) ) {
  483.         function hcode_woocommerce_product_tab_sizing() {
  484.             global $post;
  485.  
  486.             $meta_value = get_post_meta($post->ID, 'hcode_product_tabs_options', true);
  487.             if( !empty($meta_value) && isset( $meta_value[0]['hcode_size_tab'] )) {
  488.  
  489.                 $hcode_size_tab = ( $meta_value[0]['hcode_size_tab'] ) ? $meta_value[0]['hcode_size_tab'] : '';
  490.                 // Sizing Content
  491.                 echo '<div class="col-md-12 col-sm-12 col-xs-12">'.$hcode_size_tab.'</div>';
  492.             }
  493.         }
  494.     }
  495.  
  496.     /* Product single Title setup */
  497.     if ( ! function_exists( 'hcode_woocommerce_product_single_title' ) ) {
  498.         function hcode_woocommerce_product_single_title(){
  499.             global $post;
  500.             $output = '';
  501.  
  502.             ob_start();
  503.             do_action('woocommerce_product_title_responsive');
  504.             $output = ob_get_contents();
  505.             ob_end_clean();
  506.             return $output;
  507.  
  508.         }
  509.     }
  510.  
  511.     /* To Remove Placehoder From Checkout Form */
  512.     add_filter( 'woocommerce_default_address_fields', 'hcode_override_address_fields' );
  513.     if ( ! function_exists( 'hcode_override_address_fields' ) ) {
  514.         function hcode_override_address_fields( $address_fields ) {
  515.             if( is_checkout() ) {
  516.                 $address_fields['address_1']['placeholder'] = '';
  517.                 $address_fields['address_2']['placeholder'] = '';
  518.                 $address_fields['city']['placeholder'] = '';
  519.                 $address_fields['state']['placeholder'] = '';
  520.                 $address_fields['postcode']['placeholder'] = '';
  521.             }
  522.             return $address_fields;
  523.         }
  524.     }
  525.  
  526.     /* Remove Mini cart buttons */
  527.     remove_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_button_view_cart', 10 );
  528.     remove_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_proceed_to_checkout', 20 );
  529.  
  530.     /* Removed cart totals from cart page */
  531.     remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cart_totals', 10 );
  532.  
  533.     if ( ! function_exists( 'hcode_woocommerce_archive_column_class' ) ) :
  534.         function hcode_woocommerce_archive_column_class( $classes ) {
  535.  
  536.             if( is_shop() || is_product_category() || is_product_tag() || is_tax( 'product_brand' ) || is_product_taxonomy() ) {
  537.  
  538.                 $hcode_category_product_row = hcode_option( 'hcode_category_product_row_column' );
  539.  
  540.                 switch ( $hcode_category_product_row ) {
  541.                     case '6':
  542.                         $classes[] = 'col-md-2 col-sm-6 col-xs-12';
  543.                     break;
  544.                     case '4':
  545.                         $classes[] = 'col-md-3 col-sm-6 col-xs-12';
  546.                     break;
  547.                     case '3':
  548.                         $classes[] = 'col-md-4 col-sm-6 col-xs-12';
  549.                     break;
  550.                     case '2':
  551.                         $classes[] = 'col-md-6 col-sm-6 col-xs-12';
  552.                     break;
  553.                     case '1':
  554.                         $classes[] = 'col-md-12 col-sm-12 col-xs-12';
  555.                     break;
  556.                     default:
  557.                         $classes[] = 'col-md-4 col-sm-6 col-xs-12';
  558.                     break;
  559.                 }
  560.             }
  561.             return $classes;
  562.         }
  563.     endif;
  564.     add_filter( 'post_class', 'hcode_woocommerce_archive_column_class' );
  565.  
  566.     if ( ! function_exists( 'hcode_woocommerce_archive_loop_columns' ) ) :
  567.         function hcode_woocommerce_archive_loop_columns() {
  568.             $hcode_category_product_row = hcode_option( 'hcode_category_product_row_column' );
  569.             $column = '';
  570.             switch ( $hcode_category_product_row ) {
  571.                 case '6':
  572.                     $column = 6;
  573.                 break;
  574.                 case '4':
  575.                     $column = 4;
  576.                 break;
  577.                 case '3':
  578.                     $column = 3;
  579.                 break;
  580.                 case '2':
  581.                     $column = 2;
  582.                 break;
  583.                 case '1':
  584.                     $column = 1;
  585.                 break;
  586.                 default:
  587.                     $column = 3;
  588.                 break;
  589.             }
  590.             return $column;
  591.         }
  592.     endif;
  593.     add_filter( 'loop_shop_columns', 'hcode_woocommerce_archive_loop_columns', 999 );
  594.  
  595.     /* Add Thumbnail on Product Tag page */
  596.     add_action( 'product_tag_add_form_fields', 'hcode_add_thumbnail_option_in_product_tag_page' );
  597.  
  598.     if ( ! function_exists( 'hcode_add_thumbnail_option_in_product_tag_page' ) ) :
  599.         function hcode_add_thumbnail_option_in_product_tag_page() { ?>
  600.             <div class="form-field product_tag_thumbnail_main">
  601.                 <label><?php echo esc_html__( 'Thumbnail', 'H-Code' ); ?></label>
  602.                 <div id="product_tag_thumbnail" class="thumb_img_preview" style="float: left; margin-right: 10px;">
  603.                     <img src="<?php echo esc_url( wc_placeholder_img_src() ); ?>" width="60px" height="60px" alt=""/>
  604.                 </div>
  605.                 <div style="line-height: 60px;">
  606.                     <input type="hidden" id="product_tag_thumbnail_id" class="product_tag_thumb_id" name="product_tag_thumbnail_id" />
  607.                     <button type="button" class="upload_image_button button"><?php echo esc_html__( 'Upload/Add image', 'H-Code' ); ?></button>
  608.                     <button type="button" class="remove_image_button button"><?php echo esc_html__( 'Remove image', 'H-Code' ); ?></button>
  609.                 </div>
  610.                 <div class="clear"></div>
  611.             </div>
  612.             <script type="text/javascript">
  613.                 (function( $ ) {
  614.                     // Only show the "remove image" button when needed
  615.                     if ( !$( '.product_tag_thumbnail_main #product_tag_thumbnail_id' ).val() ) {
  616.                         $( '.product_tag_thumbnail_main .remove_image_button' ).hide();
  617.                     }
  618.                     $( document ).on( 'click', '.upload_image_button', function( event ) {
  619.                         // Uploading files
  620.                         var file_frame;
  621.                         event.preventDefault();
  622.                         var currentdiv = $(this).parent().parent();
  623.  
  624.                         // If the media frame already exists, reopen it.
  625.                         if ( file_frame ) {
  626.                             file_frame.open();
  627.                             return;
  628.                         }
  629.  
  630.                         // Create the media frame.
  631.                         file_frame = wp.media.frames.downloadable_file = wp.media({
  632.                             title: '<?php echo esc_html__( "Choose an image", "H-Code" ); ?>',
  633.                             button: {
  634.                                 text: '<?php echo esc_html__( "Use image", "H-Code" ); ?>'
  635.                             },
  636.                             multiple: false
  637.                         });
  638.  
  639.                         // When an image is selected, run a callback.
  640.                         file_frame.on( 'select', function() {
  641.                             var attachment = file_frame.state().get( 'selection' ).first().toJSON();
  642.                             currentdiv.find( '.product_tag_thumb_id' ).val( attachment.id );
  643.                             currentdiv.find( '.thumb_img_preview img' ).attr( 'src', attachment.url );
  644.                             currentdiv.find( '.remove_image_button' ).show();
  645.                         });
  646.  
  647.                         // Finally, open the modal.
  648.                         file_frame.open();
  649.                     });
  650.  
  651.                     $( document ).on( 'click', '.remove_image_button', function() {
  652.                         var currentdiv = $(this).parent().parent();
  653.                         currentdiv.find( '.thumb_img_preview img' ).attr( 'src', '<?php echo esc_js( wc_placeholder_img_src() ); ?>' );
  654.                         currentdiv.find( '.product_tag_thumb_id   ' ).val( '' );
  655.                         currentdiv.find( '.remove_image_button' ).hide();
  656.                         return false;
  657.                     });
  658.                     $( document ).ajaxComplete( function( event, request, options ) {
  659.                         if ( request && 4 === request.readyState && 200 === request.status && options.data && 0 <= options.data.indexOf( 'action=add-tag' ) ) {
  660.  
  661.                             var res = wpAjax.parseAjaxResponse( request.responseXML, 'ajax-response' );
  662.                             if ( ! res || res.errors ) {
  663.                                 return;
  664.                             }
  665.                             // Clear Thumbnail fields on submit
  666.                             $( '#product_tag_thumbnail' ).find( 'img' ).attr( 'src', '<?php echo esc_js( wc_placeholder_img_src() ); ?>' );
  667.                             $( '#product_tag_thumbnail_id' ).val( '' );
  668.                             $( '.remove_image_button' ).hide();
  669.                             return;
  670.                         }
  671.                     });
  672.                 })( jQuery );
  673.             </script>
  674.         <?php
  675.         }
  676.     endif;
  677.  
  678.     /* Add Thumbnail on Edit Product Tag page */
  679.     add_action( 'product_tag_edit_form_fields', 'hcode_edit_thumbnail_option_in_product_tag_page', 10, 2 );
  680.  
  681.     if ( ! function_exists( 'hcode_edit_thumbnail_option_in_product_tag_page' ) ) :
  682.         function hcode_edit_thumbnail_option_in_product_tag_page( $term, $taxonomy ) {
  683.             $image = '';
  684.             $thumbnail_id   = absint( get_term_meta( $term->term_id, 'thumbnail_id', true ) );
  685.             if ( $thumbnail_id ){
  686.                 $image = wp_get_attachment_thumb_url( $thumbnail_id );
  687.             } else {
  688.                 $image = wc_placeholder_img_src();
  689.             }
  690.  
  691.             ?>
  692.             <tr class="form-field">
  693.                 <th scope="row" valign="top"><label><?php echo esc_html__( 'Thumbnail', 'H-Code' ); ?></label></th>
  694.                 <td>
  695.                     <div class="product_tag_thumbnail_main">
  696.                         <div id="product_brand_thumbnail" class="thumb_img_preview" style="float: left; margin-right: 10px;">
  697.                             <img src="<?php echo esc_url( $image ); ?>" width="60px" height="60px" alt="" />
  698.                         </div>
  699.                         <div style="line-height: 60px;">
  700.                             <input type="hidden" id="product_tag_thumbnail_id" name="product_tag_thumbnail_id" class="product_tag_thumb_id" value="<?php echo $thumbnail_id; ?>" />
  701.                             <button type="button" class="upload_image_button button"><?php echo esc_html__( 'Upload/Add image', 'H-Code' ); ?></button>
  702.                             <button type="button" class="remove_image_button button"><?php echo esc_html__( 'Remove image', 'H-Code' ); ?></button>
  703.                         </div>
  704.                         <div class="clear"></div>
  705.                     </div>
  706.                 </td>
  707.  
  708.                 <script type="text/javascript">
  709.                     (function( $ ) {
  710.                         // Only show the "remove image" button when needed
  711.                         if ( '0' === $( '.product_tag_thumbnail_main #product_tag_thumbnail_id' ).val() ) {
  712.                             $( '.product_tag_thumbnail_main .remove_image_button' ).hide();
  713.                         }
  714.  
  715.                         $( document ).on( 'click', '.upload_image_button', function( event ) {
  716.                             // Uploading files
  717.                             var file_frame;
  718.                             event.preventDefault();
  719.                             var currentdiv = $(this).parent().parent();
  720.  
  721.                             // If the media frame already exists, reopen it.
  722.                             if ( file_frame ) {
  723.                                 file_frame.open();
  724.                                 return;
  725.                             }
  726.  
  727.                             // Create the media frame.
  728.                             file_frame = wp.media.frames.downloadable_file = wp.media({
  729.                                 title: '<?php echo esc_html__( "Choose an image", "H-Code" ); ?>',
  730.                                 button: {
  731.                                         text: '<?php echo esc_html__( "Use image", "H-Code" ); ?>'
  732.                                 },
  733.                                 multiple: false
  734.                             });
  735.  
  736.                             // When an image is selected, run a callback.
  737.                             file_frame.on( 'select', function() {
  738.                                 var attachment = file_frame.state().get( 'selection' ).first().toJSON();
  739.                                 currentdiv.find( '.product_tag_thumb_id' ).val( attachment.id );
  740.                                 currentdiv.find( '.thumb_img_preview img' ).attr( 'src', attachment.url );
  741.                                 currentdiv.find( '.remove_image_button' ).show();
  742.                             });
  743.  
  744.                             // Finally, open the modal.
  745.                             file_frame.open();
  746.                         });
  747.  
  748.                         $( document ).on( 'click', '.remove_image_button', function() {
  749.                             var currentdiv = $(this).parent().parent();
  750.                             currentdiv.find( '.thumb_img_preview img' ).attr( 'src', '<?php echo esc_js( wc_placeholder_img_src() ); ?>' );
  751.                             currentdiv.find( '.product_tag_thumb_id' ).val( '' );
  752.                             currentdiv.find( '.remove_image_button' ).hide();
  753.                             return false;
  754.                         });
  755.                     })( jQuery );
  756.                 </script>
  757.             </tr>
  758.         <?php
  759.         }
  760.     endif;
  761.  
  762.     /* Save Thumbnail */
  763.     add_action( 'created_term', 'hcode_save_product_tag_field', 10, 3 );
  764.     add_action( 'edit_term', 'hcode_save_product_tag_field', 10, 3 );
  765.  
  766.     if ( ! function_exists( 'hcode_save_product_tag_field' ) ) :
  767.         function hcode_save_product_tag_field( $term_id, $tt_id, $taxonomy ) {
  768.             if ( isset( $_POST['product_tag_thumbnail_id'] ) && 'product_tag' === $taxonomy ) {
  769.                 update_term_meta( $term_id, 'thumbnail_id', absint( $_POST['product_tag_thumbnail_id'] ) );
  770.             }
  771.         }
  772.     endif;
  773.  
  774.     /* Add Thumbnail on Tags listing */
  775.     add_filter( 'manage_edit-product_tag_columns', 'hcode_product_tag_columns' );
  776.     if ( ! function_exists( 'hcode_product_tag_columns' ) ) :
  777.         function hcode_product_tag_columns( $columns ) {
  778.  
  779.             $new_columns          = array();
  780.             $new_columns['cb']    = $columns['cb'];
  781.             $new_columns['banner_thumb'] = esc_html__( 'Banner', 'H-Code' );
  782.             unset( $columns['cb'] );
  783.  
  784.             return array_merge( $new_columns, $columns );
  785.         }
  786.     endif;
  787.  
  788.     add_filter( 'manage_product_tag_custom_column', 'hcode_product_tag_column', 10, 3 );
  789.  
  790.     if ( ! function_exists( 'hcode_product_tag_column' ) ) :
  791.         function hcode_product_tag_column( $columns, $column, $id ) {
  792.             if ( 'banner_thumb' == $column ) {
  793.                 $thumbnail_id = get_term_meta( $id, 'thumbnail_id', true );
  794.                 if ( $thumbnail_id ) {
  795.                     $image = wp_get_attachment_thumb_url( $thumbnail_id );
  796.                 } else {
  797.                     $image = wc_placeholder_img_src();
  798.                 }
  799.  
  800.                 // Prevent esc_url from breaking spaces in urls for image embeds
  801.                 // Ref: http://core.trac.wordpress.org/ticket/23605
  802.                 $image = str_replace( ' ', '%20', $image );
  803.                 $columns .= '<img src="' . esc_url( $image ) . '" alt="' . esc_attr__( 'Thumbnail', 'H-Code' ) . '" class="wp-post-image" height="48" width="48" />';
  804.             }
  805.             return $columns;
  806.         }
  807.     endif;
  808.  
  809.     /* H-Code Version 1.9.9 Continue shopping Link */
  810.     add_action( 'hcode_woocommerce_continue_shopping_link', 'hcode_woocommerce_continue_shopping_link_callback' );
  811.     if ( ! function_exists( 'hcode_woocommerce_continue_shopping_link_callback' ) ) :
  812.         function hcode_woocommerce_continue_shopping_link_callback() {
  813.             $hcode_options = get_option( 'hcode_theme_setting' );
  814.             $continue_shopping_page_link = ( isset( $hcode_options['continue_shopping_page_link'] ) && !empty( $hcode_options['continue_shopping_page_link'] ) ) ? $hcode_options['continue_shopping_page_link'] : '';
  815.             if( $continue_shopping_page_link ) {
  816.                 $continue_shopping_page_link_url = get_page_by_path( $continue_shopping_page_link );
  817.                 if( is_cart() ) {
  818.                     echo '<a href="'.get_permalink( $continue_shopping_page_link_url ).'" class="highlight-button btn btn-very-small no-margin pull-right continue-shopping">'.esc_html__( 'Continue shopping', 'H-Code' ).'</a>';
  819.                 } else {
  820.                     echo '<a href="'.get_permalink( $continue_shopping_page_link_url ).'" class="highlight-button btn btn-small no-margin-bottom clear-both pull-left"><i class="fa-solid fa-long-arrow-alt-left extra-small-icon"></i>'.esc_html__( 'Continue shopping', 'H-Code' ).'</a>';
  821.                 }
  822.             } else {
  823.                 if( is_cart() ) {
  824.                     echo '<a href="'.get_permalink( wc_get_page_id( 'shop' ) ).'" class="highlight-button btn btn-very-small no-margin pull-right continue-shopping">'.esc_html__( 'Continue shopping', 'H-Code' ).'</a>';
  825.                 } else {
  826.                     echo '<a href="'.get_permalink( wc_get_page_id( 'shop' ) ).'" class="highlight-button btn btn-small no-margin-bottom clear-both pull-left"><i class="fa-solid fa-long-arrow-alt-left extra-small-icon"></i>'.esc_html__( 'Continue shopping', 'H-Code' ).'</a>';
  827.                 }
  828.             }
  829.         }
  830.     endif;
  831. }
Tags: wordpress
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement