Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function my_theme_enqueue_styles() {
- wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
- }
- add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
- add_action( 'woocommerce_single_product_summary', 'baba_spec', 35 );
- /* Gets Dimensions, Outputs Dimensions in "inches x inches" */
- function baba_spec() {
- global $product;
- $dimensions = wc_format_dimensions($product->get_dimensions(false));
- // So $dimensions will result something like : 71 × 31 in
- // Here's how we fix that in the same function ;)
- $temp = explode(" ", $dimensions);
- // another check we can put in place is this
- // this will make sure they are actually numbers, and if so they will then build out the dimension
- if(is_numeric($temp[0]) && is_numeric($temp[2])){
- // so that gives us the following
- // $temp[0] = 71
- // temp[1] = x
- // temp[2] = 31
- // temp[3] = in
- // we basically removed all the spaces from teh string
- // Now we use those temp variables to calculate the real dimensions
- $feet1 = floor(($temp[0]/12));
- $feet2 = floor(($temp[2]/12));
- $first = $feet1."' ".($temp[0]%12).'"';
- $second = $feet2."' ".($temp[2]%12).'"';
- // finally we pass the variables in a format we want it to display
- $dimension_new = $second . ' x ' .$first;
- }
- if ( $product->has_dimensions() ) {
- $label = __( /*'Dimensions: ', 'babasouktextdomain'*/ );
- print '<span class="dim_label" style="font-size: 14px;">' . $label . '</span>';
- echo '<span style="dim_style" style="font-size: 14px;">' . $dimension_new . ' </span>';
- }
- }
- add_shortcode('showdimensions', 'baba_spec');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement