Advertisement
crowley_offcl

TMRC_functions.php

Mar 26th, 2020
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.77 KB | None | 0 0
  1. <?php
  2. function my_theme_enqueue_styles() {
  3.     wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
  4. }
  5. add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
  6.  
  7.  
  8.  
  9.  
  10. add_action( 'woocommerce_single_product_summary', 'baba_spec', 35 );
  11.  
  12. /* Gets Dimensions, Outputs Dimensions in "inches x inches" */
  13. function baba_spec() {
  14.     global $product;
  15.     $dimensions = wc_format_dimensions($product->get_dimensions(false));
  16.  
  17.  
  18.         // So $dimensions will result something like : 71 × 31 in
  19.        
  20.         // Here's how we fix that in the same function ;)
  21.        
  22.         $temp = explode(" ", $dimensions);
  23.        
  24.         // another check we can put in place is this
  25.         // this will make sure they are actually numbers, and if so they will then build out the dimension
  26.         if(is_numeric($temp[0]) && is_numeric($temp[2])){
  27.            
  28.        
  29.             // so that gives us the following
  30.            
  31.             // $temp[0] = 71
  32.             // temp[1] = x
  33.             // temp[2] = 31
  34.             // temp[3] = in
  35.             // we basically removed all the spaces from teh string
  36.            
  37.             // Now we use those temp variables to calculate the real dimensions
  38.            
  39.                $feet1 = floor(($temp[0]/12));
  40.                $feet2 = floor(($temp[2]/12));      
  41.                $first = $feet1."' ".($temp[0]%12).'"';
  42.                $second = $feet2."' ".($temp[2]%12).'"';
  43.                
  44.                // finally we pass the variables in a format we want it to display
  45.                $dimension_new = $second . ' x ' .$first;           
  46.            
  47.            
  48.         }
  49.  
  50.        
  51.  
  52.  
  53.  
  54.             if ( $product->has_dimensions() ) {
  55.                 $label = __( /*'Dimensions: ', 'babasouktextdomain'*/ );
  56.                 print '<span class="dim_label" style="font-size: 14px;">' . $label . '</span>';
  57.                
  58.                 echo '<span style="dim_style" style="font-size: 14px;">' . $dimension_new . ' </span>';
  59.                
  60.             }
  61.            
  62. }
  63.  
  64. add_shortcode('showdimensions', 'baba_spec');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement