/** * Checks if product has any attributes selected * * @param type $product_id * @return boolean */ function has_product_any_attributes($product_id) { $attributes_number = product_attributes_number(); for ($i = 1; $i <= $attributes_number; $i++) { $at_val = get_post_meta($product_id, "_attribute" . $i, true); if (!empty($at_val)) { return true; } } return false; }
if (!defined('ABSPATH')) { exit; // Exit if accessed directly } /** * The template to display product attributes on product page or with a shortcode * * Copy it to your theme implecode folder to edit the output: your-theme-folder-name/implecode/product-attributes.php * * @version 1.1.2 * @package ecommerce-product-catalog/templates/template-parts/product-page * @author Norbert Dreszer */ $single_names = get_single_names(); $product_id = ic_get_product_id(); $attributes_number = product_attributes_number(); $table = ''; if ($attributes_number > 0 && has_product_any_attributes($product_id)) { ?> <div id="product_features" class="product-features"> <h3><?php echo $single_names['product_features']; ?> </h3> <table class="features-table"><?php for ($i = 1; $i <= $attributes_number; $i++) { $attribute_value = get_attribute_value($i, $product_id); if (!empty($attribute_value)) { ?> <tr> <td class="attribute-label-single"><?php
/** * Returns product attributes table * * @param int $product_id * @param array $v_single_names * @return string */ function get_product_attributes($product_id, $v_single_names = null) { $single_names = isset($v_single_names) ? $v_single_names : get_single_names(); $attributes_number = product_attributes_number(); $at_val = ''; $any_attribute_value = ''; for ($i = 1; $i <= $attributes_number; $i++) { $at_val = get_post_meta($product_id, "_attribute" . $i, true); if (!empty($at_val)) { $any_attribute_value = $at_val; } } $table = ''; if ($attributes_number > 0 && !empty($any_attribute_value)) { $table .= '<div id="product_features" class="product-features">'; $table .= '<h3>' . $single_names['product_features'] . '</h3>'; $table .= '<table class="features-table">'; for ($i = 1; $i <= $attributes_number; $i++) { $attribute_value = get_post_meta($product_id, "_attribute" . $i, true); if (!empty($attribute_value)) { $table .= '<tr><td class="attribute-label-single">' . get_post_meta($product_id, "_attribute-label" . $i, true) . '</td><td>' . get_post_meta($product_id, "_attribute" . $i, true) . ' ' . get_post_meta($product_id, "_attribute-unit" . $i, true) . '</td></tr>'; } } $table .= '</table>'; $table .= '</div>'; } return $table; }
function implecode_save_products_meta($post_id, $post) { $post_type_now = substr($post->post_type, 0, 10); if ($post_type_now == 'al_product') { $pricemeta_noncename = isset($_POST['pricemeta_noncename']) ? $_POST['pricemeta_noncename'] : ''; if (!empty($pricemeta_noncename) && !wp_verify_nonce($pricemeta_noncename, plugin_basename(__FILE__))) { return $post->ID; } if (!isset($_POST['action'])) { return $post->ID; } else { if (isset($_POST['action']) && $_POST['action'] != 'editpost') { return $post->ID; } } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post->ID; } if (defined('DOING_AJAX') && DOING_AJAX) { return $post->ID; } if (!current_user_can('edit_post', $post->ID)) { return $post->ID; } $product_meta['_price'] = $_POST['_price'] != null ? $_POST['_price'] : ''; $product_meta['_sku'] = !empty($_POST['_sku']) ? $_POST['_sku'] : ''; $product_meta['excerpt'] = !empty($_POST['excerpt']) ? $_POST['excerpt'] : ''; $product_meta['content'] = !empty($_POST['content']) ? $_POST['content'] : ''; for ($i = 1; $i <= get_shipping_options_number(); $i++) { $product_meta['_shipping' . $i] = isset($_POST['_shipping' . $i]) ? $_POST['_shipping' . $i] : ''; $product_meta['_shipping-label' . $i] = !empty($_POST['_shipping-label' . $i]) ? $_POST['_shipping-label' . $i] : ''; } for ($i = 1; $i <= product_attributes_number(); $i++) { $product_meta['_attribute' . $i] = !empty($_POST['_attribute' . $i]) ? $_POST['_attribute' . $i] : ''; $product_meta['_attribute-label' . $i] = !empty($_POST['_attribute-label' . $i]) ? $_POST['_attribute-label' . $i] : ''; $product_meta['_attribute-unit' . $i] = !empty($_POST['_attribute-unit' . $i]) ? $_POST['_attribute-unit' . $i] : ''; } $product_meta = apply_filters('product_meta_save', $product_meta); foreach ($product_meta as $key => $value) { $current_value = get_post_meta($post->ID, $key, true); if (isset($value) && !isset($current_value)) { add_post_meta($post->ID, $key, $value, true); } else { if (isset($value) && $value != $current_value) { update_post_meta($post->ID, $key, $value); } else { if (!isset($value) && $current_value) { delete_post_meta($post->ID, $key); } } } } do_action('product_edit_save', $post); } }
/** * Returns modern grid element for a given product * * @param object $post Product post object * @param string $archive_template * @return string */ function get_default_archive_theme($post, $archive_template = null) { $archive_template = isset($archive_template) ? $archive_template : get_product_listing_template(); $return = ''; if ($archive_template == 'default') { $archive_price = apply_filters('archive_price_filter', '', $post); $modern_grid_settings = get_modern_grid_settings(); $thumbnail_product = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'modern-grid-listing'); $img_class = ''; if ($thumbnail_product) { $url = $thumbnail_product[0]; if (!empty($thumbnail_product[2])) { $ratio = $thumbnail_product[1] / $thumbnail_product[2]; if ($ratio <= 1.35 && $ratio > 1.2) { $img_class = ' class="higher"'; } else { if ($ratio <= 1.15) { $img_class = ' class="higher rect"'; } else { if ($ratio > 2) { $img_class = ' class="wider rect"'; } } } } } else { $url = default_product_thumbnail_url(); } $product_name = get_the_title(); $return = '<div class="al_archive product-' . $post->ID . ' modern-grid-element ' . design_schemes('box', 0) . ' ' . product_listing_size_class($thumbnail_product) . ' ' . product_class($post->ID) . '">'; $return .= '<div class="pseudo"></div>'; $return .= '<a href="' . get_permalink() . '"><img' . $img_class . ' src="' . $url . '" alt="' . $product_name . '">'; $return .= '<h3 class="product-name ' . design_schemes('box', 0) . '">' . $product_name . '</h3>'; if ($modern_grid_settings['attributes'] == 1) { $attributes_number = product_attributes_number(); $at_val = ''; $any_attribute_value = ''; for ($i = 1; $i <= $attributes_number; $i++) { $at_val = get_post_meta($post->ID, "_attribute" . $i, true); if (!empty($at_val)) { $any_attribute_value = $at_val . $i; } } if ($attributes_number > 0 && !empty($any_attribute_value)) { $return .= '<div class="product-attributes"><table class="attributes-table">'; for ($i = 1; $i <= $attributes_number; $i++) { $attribute_value = get_post_meta($post->ID, "_attribute" . $i, true); if (!empty($attribute_value)) { $return .= '<tr><td>' . get_post_meta($post->ID, "_attribute-label" . $i, true) . '</td><td>' . get_post_meta($post->ID, "_attribute" . $i, true) . ' ' . get_post_meta($post->ID, "_attribute-unit" . $i, true) . '</td></tr>'; } } $return .= '</table></div>'; } } $return .= $archive_price . '</a></div>'; } return $return; }
/** * Checks if product attributes are enabled * * @return boolean */ function is_ic_attributes_enabled() { $attributes_count = product_attributes_number(); if ($attributes_count > 0) { return true; } return false; }
function attributes_settings_content() { $submenu = $_GET['submenu']; ?> <div class="attributes-product-settings settings-wrapper" style="clear:both;"> <div class="settings-submenu"> <h3> <a id="attributes-settings" class="element current" href="<?php echo admin_url('edit.php?post_type=al_product&page=product-settings.php&tab=attributes-settings&submenu=attributes'); ?> "><?php _e('Attributes Settings', 'ecommerce-product-catalog'); ?> </a> <?php do_action('attributes_submenu'); ?> </h3> </div> <?php if ($submenu == 'attributes') { ?> <div class="setting-content submenu"> <script> jQuery( '.settings-submenu a' ).removeClass( 'current' ); jQuery( '.settings-submenu a#attributes-settings' ).addClass( 'current' ); </script> <h2><?php _e('Attributes Settings', 'ecommerce-product-catalog'); ?> </h2> <form method="post" action="options.php"> <?php settings_fields('product_attributes'); $attributes_count = product_attributes_number(); ?> <h3><?php _e('Product attributes options', 'ecommerce-product-catalog'); ?> </h3> <table> <tr> <td colspan="2"><?php _e('Number of product attributes', 'ecommerce-product-catalog'); ?> <input size="30" type="number" step="1" min="0" name="product_attributes_number" id="admin-number-field" value="<?php echo $attributes_count; ?> " /><input type="submit" class="button" value="<?php _e('Update', 'ecommerce-product-catalog'); ?> " /> </td> </tr> </table> <?php if ($attributes_count > 0) { ?> <div class="al-box info"> <p><?php _e("If you fill out the fields below, system will automatically pre-fill the fields on product pages so you doesn't have to fill them every time you add product.</p><p>When every product in your catalogue is different you can leave all or a part of these field empty.", 'ecommerce-product-catalog'); ?> </p><p><?php _e('You can change these default values on every product page.', 'ecommerce-product-catalog'); ?> </p> </div> <table class="wp-list-table widefat product-settings-table dragable"> <thead> <tr> <th class="title"></th><th class="title"><b><?php _e('Attribute default name', 'ecommerce-product-catalog'); ?> </b></th> <th></th> <th class="title"><b><?php _e('Attribute default value', 'ecommerce-product-catalog'); ?> </b></th> <th class="title"><b><?php _e('Attribute default unit', 'ecommerce-product-catalog'); ?> </b></th> <?php do_action('product_attributes_settings_table_th'); ?> <th class="dragger"></th> </tr> </thead> <tbody><?php $attribute = get_option('product_attribute'); $attribute_label = get_option('product_attribute_label'); $attribute_unit = get_option('product_attribute_unit'); for ($i = 1; $i <= product_attributes_number(); $i++) { $attribute_label[$i] = isset($attribute_label[$i]) ? $attribute_label[$i] : ''; $attribute[$i] = isset($attribute[$i]) ? $attribute[$i] : ''; $attribute_unit[$i] = isset($attribute_unit[$i]) ? $attribute_unit[$i] : ''; ?> <tr> <td class="lp-column lp'.$i.'"><?php echo $i; ?> .</td> <td class="product-attribute-label-column"><input class="product-attribute-label" type="text" name="product_attribute_label[<?php echo $i; ?> ]" value="<?php echo esc_html($attribute_label[$i]); ?> " /></td><td class="lp-column">:</td> <td><input class="product-attribute" type="text" name="product_attribute[<?php echo $i; ?> ]" value="<?php echo esc_html($attribute[$i]); ?> " /></td> <td><input id="admin-number-field" class="product-attribute-unit" type="text" name="product_attribute_unit[<?php echo $i; ?> ]" value="<?php echo esc_html($attribute_unit[$i]); ?> " /></td> <?php do_action('product_attributes_settings_table_td', $i); ?> <td class="dragger"></td> </tr> <?php } ?> </tbody> </table> <?php do_action('attributes-settings'); ?> <p class="submit"> <input type="submit" class="button-primary" value="<?php _e('Save changes', 'ecommerce-product-catalog'); ?> " /> </p><?php } else { ?> <table> <tr> <td colspan="2"> <div class="al-box warning"><?php _e('Attributes disabled. To enable set minimum 1 attribute.', 'ecommerce-product-catalog'); ?> </div> </td> </tr> </table><?php } ?> </form> </div> <div class="helpers"><div class="wrapper"><?php main_helper(); doc_helper(__('attributes', 'ecommerce-product-catalog'), 'product-attributes'); ?> </div></div> <?php } do_action('product-attributes'); ?> </div><?php }
/** * Returns modern grid element for a given product * * @param object $post Product post object * @param string $archive_template * @return string */ function get_default_archive_theme($post, $archive_template = null) { $archive_template = isset($archive_template) ? $archive_template : get_product_listing_template(); $return = ''; if ($archive_template == 'default') { $product_id = $post->ID; $archive_price = apply_filters('archive_price_filter', '', $post); $modern_grid_settings = get_modern_grid_settings(); $image_id = get_post_thumbnail_id($product_id); $thumbnail_product = wp_get_attachment_image_src($image_id, 'modern-grid-listing'); $product_name = get_the_title(); if ($thumbnail_product) { $url = $thumbnail_product[0]; $img_class['alt'] = $product_name; $img_class['class'] = "modern-grid-image"; if (!empty($thumbnail_product[2])) { $ratio = $thumbnail_product[1] / $thumbnail_product[2]; if ($ratio <= 1.35 && $ratio > 1.2) { $img_class['class'] .= " higher"; } else { if ($ratio <= 1.15) { $img_class['class'] .= " higher rect"; } else { if ($ratio > 2) { $img_class['class'] .= " wider rect"; } } } } $image = wp_get_attachment_image($image_id, 'modern-grid-listing', false, $img_class); } else { $url = default_product_thumbnail_url(); $image = '<img class="modern-grid-image" src="' . $url . '" alt="' . $product_name . '">'; } $return = '<div class="al_archive product-' . $product_id . ' modern-grid-element ' . design_schemes('box', 0) . ' ' . product_listing_size_class($thumbnail_product) . ' ' . product_class($product_id) . '">'; $return .= '<div class="pseudo"></div>'; $return .= '<a href="' . get_permalink($product_id) . '">' . $image; $return .= '<h3 class="product-name ' . design_schemes('box', 0) . '">' . $product_name . '</h3>'; if ($modern_grid_settings['attributes'] == 1) { $attributes_number = product_attributes_number(); if ($attributes_number > 0 && has_product_any_attributes($product_id)) { $return .= '<div class="product-attributes"><table class="attributes-table">'; for ($i = 1; $i <= $attributes_number; $i++) { $attribute_value = get_attribute_value($i, $product_id); if (!empty($attribute_value)) { $return .= '<tr><td class="attribute-label-listing">' . get_attribute_label($i, $product_id) . '</td><td><span class="attribute-value-listing">' . get_attribute_value($i, $product_id) . '</span> <span class="attribute-unit-listing">' . get_attribute_unit($i, $product_id) . '</span></td></tr>'; } } $return .= '</table></div>'; } } $return .= $archive_price . '</a></div>'; } return $return; }