Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.18 KB | None | 0 0
  1. <?php
  2.  
  3. function theme_enqueue_styles() {
  4.     wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'avada-stylesheet' ) );
  5. }
  6. add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
  7.  
  8. function avada_lang_setup() {
  9.     $lang = get_stylesheet_directory() . '/languages';
  10.     load_child_theme_textdomain( 'Avada', $lang );
  11. }
  12. add_action( 'after_setup_theme', 'avada_lang_setup' );
  13. register_sidebar( array(
  14.         'name'          => 'After Single Post',
  15.         'id'            => 'after-single',
  16.         'before_widget' => '<div>',
  17.         'after_widget'  => '</div>',
  18.         'before_title'  => '<h2 class="related-post-title">',
  19.         'after_title'   => '</h2>',
  20.     ) );
  21.  
  22. /** Customized **/
  23.  
  24. //remove excerpt from Product
  25. remove_action('woocommerce_single_product_summary','woocommerce_template_single_excerpt', 20);
  26.  
  27. // move SKU below the price
  28. remove_action('woocommerce_single_product_summary','woocommerce_template_single_meta', 40);
  29. add_action('woocommerce_single_product_summary','woocommerce_template_single_meta', 20);
  30.  
  31. add_filter( 'avada_blog_read_more_excerpt', 'my_read_more_symbol' );
  32. function my_read_more_symbol( $read_more ) {
  33.  $read_more = "Read more";
  34.  
  35.  return $read_more;
  36. }
  37. //removing reviews tab from products page
  38. add_filter( 'woocommerce_product_tabs', 'wcs_woo_remove_reviews_tab', 98 );
  39.     function wcs_woo_remove_reviews_tab($tabs) {
  40.     unset($tabs['reviews']);
  41.     return $tabs;
  42. }
  43.  
  44. // Add Variation Settings
  45. add_action( 'woocommerce_product_after_variable_attributes', 'variation_settings_fields', 10, 3 );
  46. // Save Variation Settings
  47. add_action( 'woocommerce_save_product_variation', 'save_variation_settings_fields', 10, 2 );
  48. /**
  49.  * Create new fields for variations
  50.  *
  51.  */
  52. function variation_settings_fields( $loop, $variation_data, $variation ) {
  53.     // Text Field
  54.     woocommerce_wp_text_input(
  55.         array(
  56.             'id'          => '_text_field[' . $variation->ID . ']',
  57.             'name'        => 'Text Field 1',
  58.             'label'       => __( 'My Text Field', 'woocommerce' ),
  59.             'placeholder' => 'http://',
  60.             'desc_tip'    => 'true',
  61.             'description' => __( 'Enter the custom value here.', 'woocommerce' ),
  62.             'value'       => get_post_meta( $variation->ID, '_text_field', true )
  63.         )
  64.     );
  65.     // Number Field
  66.     woocommerce_wp_text_input(
  67.         array(
  68.             'id'          => '_number_field[' . $variation->ID . ']',
  69.             'label'       => __( 'My Number Field', 'woocommerce' ),
  70.             'desc_tip'    => 'true',
  71.             'description' => __( 'Enter the custom number here.', 'woocommerce' ),
  72.             'value'       => get_post_meta( $variation->ID, '_number_field', true ),
  73.             'custom_attributes' => array(
  74.                 'step'  => 'any',
  75.                 'min'   => '0'
  76.             )
  77.         )
  78.     );
  79.     // Textarea
  80.     woocommerce_wp_textarea_input(
  81.         array(
  82.             'id'          => '_textarea[' . $variation->ID . ']',
  83.             'label'       => __( 'My Textarea', 'woocommerce' ),
  84.             'placeholder' => '',
  85.             'description' => __( 'Enter the custom value here.', 'woocommerce' ),
  86.             'value'       => get_post_meta( $variation->ID, '_textarea', true ),
  87.         )
  88.     );
  89.     // Select
  90.     woocommerce_wp_select(
  91.         array(
  92.             'id'          => '_select[' . $variation->ID . ']',
  93.             'label'       => __( 'My Select Field', 'woocommerce' ),
  94.             'description' => __( 'Choose a value.', 'woocommerce' ),
  95.             'value'       => get_post_meta( $variation->ID, '_select', true ),
  96.             'options' => array(
  97.                 'one'   => __( 'Option 1', 'woocommerce' ),
  98.                 'two'   => __( 'Option 2', 'woocommerce' ),
  99.                 'three' => __( 'Option 3', 'woocommerce' )
  100.             )
  101.         )
  102.     );
  103.     // Checkbox
  104.     woocommerce_wp_checkbox(
  105.         array(
  106.             'id'            => '_checkbox[' . $variation->ID . ']',
  107.             'label'         => __('My Checkbox Field', 'woocommerce' ),
  108.             'description'   => __( 'Check me!', 'woocommerce' ),
  109.             'value'         => get_post_meta( $variation->ID, '_checkbox', true ),
  110.         )
  111.     );
  112.     // Hidden field
  113.     woocommerce_wp_hidden_input(
  114.         array(
  115.             'id'    => '_hidden_field[' . $variation->ID . ']',
  116.             'value' => 'hidden_value'
  117.         )
  118.     );
  119. }
  120. /**
  121.  * Save new fields for variations
  122.  *
  123.  */
  124. function save_variation_settings_fields( $post_id ) {
  125.     // Text Field
  126.     $text_field = $_POST['_text_field'][ $post_id ];
  127.     if( ! empty( $text_field ) ) {
  128.         update_post_meta( $post_id, '_text_field', esc_attr( $text_field ) );
  129.     }
  130.  
  131.     // Number Field
  132.     $number_field = $_POST['_number_field'][ $post_id ];
  133.     if( ! empty( $number_field ) ) {
  134.         update_post_meta( $post_id, '_number_field', esc_attr( $number_field ) );
  135.     }
  136.     // Textarea
  137.     $textarea = $_POST['_textarea'][ $post_id ];
  138.     if( ! empty( $textarea ) ) {
  139.         update_post_meta( $post_id, '_textarea', esc_attr( $textarea ) );
  140.     }
  141.  
  142.     // Select
  143.     $select = $_POST['_select'][ $post_id ];
  144.     if( ! empty( $select ) ) {
  145.         update_post_meta( $post_id, '_select', esc_attr( $select ) );
  146.     }
  147.  
  148.     // Checkbox
  149.     $checkbox = isset( $_POST['_checkbox'][ $post_id ] ) ? 'yes' : 'no';
  150.     update_post_meta( $post_id, '_checkbox', $checkbox );
  151.  
  152.     // Hidden field
  153.     $hidden = $_POST['_hidden_field'][ $post_id ];
  154.     if( ! empty( $hidden ) ) {
  155.         update_post_meta( $post_id, '_hidden_field', esc_attr( $hidden ) );
  156.     }
  157. }
  158.  
  159. // Add New Variation Settings
  160. add_filter( 'woocommerce_available_variation', 'load_variation_settings_fields' );
  161. /**
  162.  * Add custom fields for variations
  163.  *
  164.  */
  165. function load_variation_settings_fields( $variations ) {
  166.  
  167.     // duplicate the line for each field
  168.     $variations['text_field'] = get_post_meta( $variations[ 'variation_id' ], '_text_field', true );
  169.  
  170.     return $variations;
  171. }
  172. //remove the tabs
  173. //remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
  174.  
  175.  
  176. /**      * Hook in each tabs callback function after single content.         */
  177. //add_action( 'woocommerce_after_single_product_summary', 'woocommerce_product_description_tab' );
  178. //add_action( 'woocommerce_after_single_product_summary', 'woocommerce_product_additional_information_tab' );
  179. //add_action( 'woocommerce_after_single_product_summary', 'comments_template' );
  180.  
  181. function woocommerce_template_single_product_summary() {
  182.     return '<div class="test-class">This is a test to relocate some text into the product summary area</div>';
  183. }
  184.  
  185. add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_single_product_summary', 10 );
  186.  
  187. add_action( 'woocommerce_single_product_summary', '_woocommerce_single_product_summary_', 20 );
  188. //
  189. //remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
  190. //
  191. //// add them under short description
  192. //// note: this will need a bit of CSS customization!
  193. //
  194. //add_action( 'woocommerce_after_single_product_summary', 'woocommerce_show_product_thumbnails', 50 );
  195.  
  196. function list_hooked_functions($tag='woocommerce_single_product_summary'){
  197.     global $wp_filter;
  198.  
  199.     if ($tag) {
  200.         $hook[$tag]=$wp_filter[$tag];
  201.         if (!is_array($hook[$tag])) {
  202.             trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
  203.             return;
  204.         }
  205.     }
  206.     else {
  207.         $hook=$wp_filter;
  208.         ksort($hook);
  209.     }
  210.     echo "<!--\n\n";
  211.     foreach($hook as $tag => $priority){
  212.         echo ">>>>>>>>>>  $tag\n\n";
  213.         ksort($priority);
  214.         foreach($priority as $priority => $function){
  215.             echo $priority;
  216.             foreach($function as $name => $properties) echo "\t$name\n\n";
  217.         }
  218.     }
  219.     echo "\n\n-->";
  220.     return;
  221. }
  222.  
  223. add_action('wp_head', 'list_hooked_functions');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement