Tagged: 

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #455045

    I updated the following function to add more product data to the product info element 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. I also tried to create the same file in the child theme but it doesn’t loaded. How can I move this to the child theme??

    
    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;
    }
    
    • This topic was modified 8 years, 12 months ago by boscotwcheung.
    #455386

    Hi boscotwcheung!

    Thank you for using Enfold.

    Add this in the functions.php file:

    add_filter('avia_load_shortcodes', 'avia_include_shortcode_template', 15, 1);
    function avia_include_shortcode_template($paths)
    {
    	$template_url = get_stylesheet_directory();
        	array_unshift($paths, $template_url.'/shortcodes/');
    
    	return $paths;
    }
    

    Create a folder, name it “shortcodes”. Inside the folder create another php file called “product_snippet_custom”. Add this:

    <?php
    /**
     * Custom product shortcode
     */
    
    if ( !class_exists( 'avia_sc_produc_custom' ) )
    {
    	class avia_sc_produc_custom extends aviaShortcodeTemplate
    	{
    			/**
    			 * Create the config array for the shortcode custom
    			 */
    			function shortcode_insert_button()
    			{
    				$this->config['name']		= __('Product Custom', 'avia_framework' );
    				$this->config['tab']		= __('Plugin Additions', 'avia_framework' );
    				$this->config['icon']		= AviaBuilder::$path['imagesURL']."sc-button.png";
    				$this->config['order']		= 10;
    				$this->config['target']		= 'avia-target-insert';
    				$this->config['shortcode'] 	= 'av_product_custom';
            $this->config['tooltip'] 	= __('Display a custom info', 'avia_framework' );
            $this->config['drag-level'] = 3;
            $this->config['tinyMCE'] 	= array('disable' => "true");
    			}
    
          /**
      		 * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
      		 * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
      		 * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
      		 *
      		 *
      		 * @param array $params this array holds the default values for $content and $args.
      		 * @return $params the return array usually holds an innerHtml key that holds item specific markup.
      		 */
      		function editor_element($params)
      		{
      			$params['innerHtml'] = "<img src='".$this->config['icon']."' title='".$this->config['name']."' />";
      			$params['innerHtml'].= "<div class='avia-element-label'>".$this->config['name']."</div>";
      			$params['content'] 	 = NULL; //remove to allow content elements
      			return $params;
      		}
    
          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;
          }
    	}
    }
    

    You will find another element named “Product Custom” in the Plugin Additions panel.

    Best regards,
    Ismael

    #455524

    Thanks. It works!

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘How to add custom product info element to child theme?’ is closed to new replies.