BaapJaan

My Customized Function

Apr 14th, 2022 (edited)
660
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.79 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Theme functions and definitions.
  4.  */
  5.  
  6. add_action('elementor/widgets/widgets_registered', 'bookory_customs_widgets');
  7. function bookory_customs_widgets($widgets_manager){
  8.     require_once (get_stylesheet_directory().'/all_publisher.php');
  9.     require_once (get_stylesheet_directory().'/all_editors.php');
  10.     require_once (get_stylesheet_directory().'/all_translaters.php');
  11.     require_once (get_stylesheet_directory().'/all_categories.php');
  12. }
  13.  
  14. function bookory_get_book_publisher_taxonomy() {
  15.     return apply_filters( 'bookory_book_publisher_taxonomy', 'pa_publisher' );
  16. }
  17.  
  18. function bookory_get_book_editors_taxonomy() {
  19.     return apply_filters( 'bookory_book_editors_taxonomy', 'pa_editor' );
  20. }
  21.  
  22. function bookory_get_book_translator_taxonomy() {
  23.     return apply_filters( 'bookory_book_translator_taxonomy', 'pa_translator' );
  24. }
  25.  
  26. function bookory_wc_get_product_attributes($pa_taxonomy) {
  27.     global $product;
  28.     $terms       = get_the_terms( $product->get_id(), $pa_taxonomy );
  29.     $author_name = '';
  30.  
  31.     if ( $terms && ! is_wp_error( $terms ) ) {
  32.         foreach ( $terms as $term ) {
  33.             $author_name .= '<a href="'. esc_url( get_term_link( $term ) ) . '">' . $term->name . '</a>';
  34.         }
  35.     }
  36.  
  37.     return $author_name;
  38. }
  39.  
  40. if (!function_exists('bookory_woocommerce_single_author')) {
  41.     function bookory_woocommerce_single_author() {
  42.         $author_name = bookory_wc_get_product_author();
  43.         if ( ! empty ( $author_name ) ) : ?>
  44.             <div class="product-brand">
  45.                 <?php echo esc_html__('লেখক: ', 'bookory') . wp_kses_post( str_replace( '</a><a ', '</a>, <a ', $author_name ) ); ?>
  46.             </div>
  47.         <?php endif;
  48.     }
  49. }
  50.  
  51.  
  52. function bookory_woocommerce_single_publisher() {
  53.     $pa_publisher = bookory_get_book_publisher_taxonomy();
  54.     $publisher = bookory_wc_get_product_attributes($pa_publisher);
  55.     if ( ! empty ( $publisher ) ) : ?>
  56.     <div class="product-brand">
  57.         <?php echo esc_html__('প্রকাশক: ', 'bookory') . wp_kses_post( str_replace( '</a><a ', '</a>, <a ', $publisher ) ); ?>
  58.     </div>
  59. <?php endif;
  60. }
  61.  
  62. function bookory_woocommerce_single_editor() {
  63.     $pa_editor = bookory_get_book_editors_taxonomy();
  64.     $editors = bookory_wc_get_product_attributes($pa_editor);
  65.     if ( ! empty ( $editors ) ) : ?>
  66.     <div class="product-brand">
  67.         <?php echo esc_html__('সম্পাদক: ', 'bookory') . wp_kses_post( str_replace( '</a><a ', '</a>, <a ', $editors ) ); ?>
  68.     </div>
  69. <?php endif;
  70. }
  71.  
  72. function bookory_woocommerce_single_translator() {
  73.     $pa_translator = bookory_get_book_translator_taxonomy();
  74.     $translator = bookory_wc_get_product_attributes($pa_translator);
  75.     if ( ! empty ( $translator ) ) : ?>
  76.     <div class="product-brand">
  77.         <?php echo esc_html__('অনুবাদক: ', 'bookory') . wp_kses_post( str_replace( '</a><a ', '</a>, <a ', $translator ) ); ?>
  78.     </div>
  79. <?php endif;
  80. }
  81.  
  82. function bookory_single_product_after_title() {
  83.     global $product;
  84. ?>
  85. <div class="product_after_title">
  86.     <?php
  87.         bookory_woocommerce_single_author();
  88.         bookory_woocommerce_single_translator();
  89.         bookory_woocommerce_single_editor();
  90.         bookory_woocommerce_single_publisher();
  91.         echo wc_get_product_category_list( $product->get_id(), ', ', '<span class="posted_in">' . _n( 'বিষয়:', 'বিষয়সমূহ:', count( $product->get_category_ids() ), 'woocommerce' ) . ' ', '</span>' ); ?>
  92. </div>
  93. <?php
  94. }
  95.  
  96. function bookory_mas_product_authors_list_terms_clauses($clauses, $taxonomies, $args) {
  97.     global $wpdb;
  98.  
  99.     if (!isset($args['first_letter'])) {
  100.         return $clauses;
  101.     }
  102.     $clauses['where'] .= ' AND ' . $wpdb->prepare("t.name LIKE %s", $wpdb->esc_like($args['first_letter']) . '%');
  103.  
  104.     return $clauses;
  105. }
  106.  
  107. add_action('init', 'bookory_setup_woocommerce_set_sidebar', 999);
  108. function bookory_setup_woocommerce_set_sidebar(){
  109.     add_filter('bookory_theme_sidebar', 'bookory_woocommerce_set_sidebar', 20);
  110.     add_filter('body_class', 'bookory_woocommerce_body_class');
  111. }
  112.  
  113. function bookory_woocommerce_set_sidebar($name) {
  114.     if (is_product_taxonomy() || is_product_category()) {
  115.         $name = '';
  116.     }
  117.     return $name;
  118. }
  119.  
  120. function bookory_woocommerce_body_class($classes){
  121.     if (is_product_taxonomy() || is_product_category()) {
  122.         $classes   = array_diff($classes, array(
  123.                     'bookory-sidebar-left',
  124.                     'bookory-sidebar-right',
  125.                     'shop_filter_canvas',
  126.                     'shop_filter_dropdown'
  127.                 ));
  128.         $classes[] = 'bookory-full-width-content';
  129.     }
  130.     return $classes;
  131. }
  132.  
  133.  
  134. function bookory_woocommerce_deal_progress() {
  135.         global $product;
  136.  
  137.         $limit = get_post_meta($product->get_id(), '_deal_quantity', true);
  138.         $sold  = intval(get_post_meta($product->get_id(), '_deal_sales_counts', true));
  139.         if (empty($limit)) {
  140.             return;
  141.         }
  142.  
  143.         ?>
  144.  
  145.         <div class="deal-sold">
  146.             <div class="deal-sold-text">
  147.                 <span><?php echo esc_html__('Already sold: ', 'bookory'); ?></span><span class="value"><?php echo esc_html($sold); ?>/<?php echo esc_html($limit); ?></span>
  148.             </div>
  149.             <div class="deal-progress">
  150.                 <div class="progress-bar">
  151.                     <div class="progress-value" style="width: <?php echo trim($sold / $limit * 100) ?>%"></div>
  152.                 </div>
  153.             </div>
  154.         </div>
  155.  
  156.         <?php
  157.     }
  158.  
  159.  
  160. add_action( 'woosq_product_summary', 'bookory_single_product_after_title', 5 );
  161.  
  162. add_action( 'init', 'my_remove_lightbox' );      
  163. function my_remove_lightbox() {      
  164.    remove_theme_support( 'wc-product-gallery-lightbox' );        
  165. }
  166. add_filter( 'woocommerce_single_product_zoom_enabled', '__return_false' );
  167. add_filter( 'woocommerce_single_product_image_thumbnail_html', 'custom_remove_product_link' );
  168. function custom_remove_product_link( $html ) {
  169.   return strip_tags( $html, '<div><img>' );
  170. }
  171.  
  172.  
  173.  
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment