Tagged: child theme, woocommerce
-
AuthorPosts
-
June 1, 2015 at 8:12 am #452363
I am trying to add custom code to enfold / config-woocommerce / config.php
function avia_shop_overview_extra_header_div(){ echo "<div class='inner_product_header'><div class='avia-arrow'></div>"; global $product; $product_name = $product->post->post_title; $product_o_price = $product->regular_price; $product_s_price = $product->sale_price; echo '<span class="product_name">'.$product_name.'</span>'; if ($product_s_price == ''){ // No Discount if ($product_o_price != ''){ echo '<span class="product_price">'.get_woocommerce_currency_symbol().$product_o_price.'</span>'; } } else { echo '<span class="product_price">'.get_woocommerce_currency_symbol().$product_s_price.'</span>'; echo '<span class="product_o_price"><del>'.get_woocommerce_currency_symbol().$product_o_price.'</del></span>'; echo '<span class="product_percent">'.(($product_o_price - $product_s_price) / $product_o_price) * 100 .'% off</span>'; } }
I want to put this script into child theme. I tried to create the same folder in my child theme and copy the config.php into it. But It doesn’t working. I am new to child theme. Am I doing something wrong?
- This topic was modified 9 years, 5 months ago by boscotwcheung.
June 2, 2015 at 9:40 am #453015I read this post:
https://kriesi.at/support/topic/does-child-theme-read-woocommerce-configconfig-php/But I still don’t know what to do. Any help?
- This reply was modified 9 years, 5 months ago by boscotwcheung.
June 4, 2015 at 4:54 am #454226I had the same problem when I updated the product_snippet_info.php for adding some extra content into the product info element shortcode. it only works when I put the code in the parent theme but it doesn’t when the code is in the child theme.
June 4, 2015 at 4:58 am #454229Hey!
Try this in your child theme functions.php:
add_action('init', function() { remove_action( 'woocommerce_before_shop_loop_item_title', 'avia_shop_overview_extra_header_div', 1000); }); add_action( 'woocommerce_before_shop_loop_item_title', 'child_avia_shop_overview_extra_header_div', 20); function child_avia_shop_overview_extra_header_div() { echo "<div class='inner_product_header'><div class='avia-arrow'></div>"; }
Regards,
JosueJune 4, 2015 at 5:49 am #454250Thanks. It works for the product list now in the child theme. But the product info is not working yet. I updated the following function in the enfold/config-templatebuilder/avia-shortcodes/product_snippet_info.php. I tried to put the whole script into the function.php of the child theme but it will become error 500 on the frontend. I tried to comment out extended class “extends aviaShortcodeTemplate” and it fixed the error 500 problem but it shows nothing in the product info area.
function shortcode_handler($atts, $content = "", $shortcodename = "", $meta = "") { $output = ""; $meta['el_class']; global $woocommerce, $product; if(!is_object($woocommerce) || !is_object($woocommerce->query) || empty($product)) return; // $product = wc_get_product(); $output .= "<div class='av-woo-product-info ".$meta['el_class']."'>"; ob_start(); // Disabled by Alex // $product->list_attributes(); // Custom Code by Alex to add more product info data $string_item_code = 'Item-code'; if (ICL_LANGUAGE_CODE != 'en'){ $string_item_code = '產品編號'; } if ($product->sku != ''){ echo '<div class="product_sku">'.$string_item_code.': '.$product->sku.'</div>'; } if ($product->post->post_title != ''){ echo '<div class="product_title">'.$product->post->post_title.'</div>'; } if ($product->regular_price != ''){ echo '<div class="product_price_row">'; $product_o_price = $product->regular_price; $product_s_price = $product->sale_price; $product_symbol = get_woocommerce_currency_symbol(); if ($product_symbol == '$'){ $product_symbol = 'HKD$'; } $product_symbol = 'HKD'; if ($product_s_price == ''){ // No Discount if ($product_o_price != ''){ echo '<span class="product_price">'.$product_symbol.wc_price($product_o_price).'</span>'; } } else { echo '<span class="product_price">'.$product_symbol.wc_price($product_s_price).'</span>'; echo '<span class="product_o_price"><del>'.$product_symbol.wc_price($product_o_price).'</del></span>'; echo '<span class="product_percent">'.(($product_o_price - $product_s_price) / $product_o_price) * 100 .'% off</span>'; } echo '</div>'; } // end of custom code by Alex $output .= ob_get_clean(); $output .= "</div>"; return $output; }
June 5, 2015 at 4:40 am #454903any help? how I can override a class with extended in child theme?
June 5, 2015 at 11:30 am #455047I opened another question for the product info problem. So it can be easier for others with the same problem. Please refer to https://kriesi.at/support/topic/how-to-add-custom-product-info-element-to-child-theme
For the custom info in the product list, it has been solved. Thanks.
-
AuthorPosts
- The topic ‘Woocommerce custom code in child theme for the product list’ is closed to new replies.