0 ) { add_meta_box( 'al_product_attributes', $labels[ 'attributes' ], 'al_product_attributes', 'al_product', apply_filters( 'product_attributes_box_column', 'normal' ), apply_filters( 'product_attributes_box_priority', 'default' ) ); } } /** * Shows attributes metabox * * @global type $post */ function al_product_attributes( $post, $args = null ) { echo ''; //echo '
' . __( 'Only attributes with values set will be shown on product page.', 'ecommerce-product-catalog' ) . ' ' . sprintf( __( 'See docs.', 'ecommerce-product-catalog' ), 'https://implecode.com/docs/ecommerce-product-catalog/product-attributes/?cam=catalog-add-page-box&key=product-attributes' ) . '
'; implecode_info( __( 'Only attributes with values set will be shown on product page.', 'ecommerce-product-catalog' ) . ' ' . sprintf( __( 'See docs.', 'ecommerce-product-catalog' ), 'https://implecode.com/docs/ecommerce-product-catalog/product-attributes/?cam=catalog-add-page-box&key=product-attributes' ) ); do_action( 'before_product_attributes_edit_single', $args ); echo ''; do_action( 'inside_attributes_edit_table' ); $attributes_option = isset( $args[ 'args' ][ 'attribute_values' ] ) ? $args[ 'args' ][ 'attribute_values' ] : get_option( 'product_attribute' ); $attributes_label_option = isset( $args[ 'args' ][ 'attribute_labels' ] ) ? $args[ 'args' ][ 'attribute_labels' ] : get_option( 'product_attribute_label' ); $attributes_unit_option = isset( $args[ 'args' ][ 'attribute_units' ] ) ? $args[ 'args' ][ 'attribute_units' ] : get_option( 'product_attribute_unit' ); $attributes_number = product_attributes_number(); $available_labels = get_all_attribute_labels(); $label_autocomplete = ''; if ( !empty( $available_labels ) ) { $label_autocomplete = 'data-ic-autocomplete="' . esc_attr( json_encode( $available_labels ) ) . '"'; } $names = isset( $args[ 'args' ][ 'field_names' ] ) ? $args[ 'args' ][ 'field_names' ] : array( 'value' => '_attribute', 'label' => '_attribute-label', 'unit' => '_attribute-unit' ); for ( $i = 1; $i <= $attributes_number; $i++ ) { $attributes_option_field = get_attribute_value( $i, $post->ID ); //get_post_meta( $post->ID, '_attribute' . $i, true ); $attributes_label_option_field = get_attribute_label( $i, $post->ID ); //get_post_meta( $post->ID, '_attribute-label' . $i, true ); $attributes_unit_option_field = get_attribute_unit( $i, $post->ID ); //get_post_meta( $post->ID, '_attribute-unit' . $i, true ); $attributes_option[ $i ] = isset( $attributes_option[ $i ] ) ? $attributes_option[ $i ] : ''; $attributes_label_option[ $i ] = isset( $attributes_label_option[ $i ] ) ? $attributes_label_option[ $i ] : ''; $attributes_unit_option[ $i ] = isset( $attributes_unit_option[ $i ] ) ? $attributes_unit_option[ $i ] : ''; if ( is_ic_new_product_screen() ) { $attributes_option_field = !empty( $attributes_option_field ) ? $attributes_option_field : $attributes_option[ $i ]; } $attributes_label_option_field = !empty( $attributes_label_option_field ) ? $attributes_label_option_field : $attributes_label_option[ $i ]; $attributes_unit_option_field = !empty( $attributes_unit_option_field ) ? $attributes_unit_option_field : $attributes_unit_option[ $i ]; $attribute_value_field = ''; /* if ( is_array( $attributes_option_field ) ) { $attributes_option_field = ''; } * */ $autocomplete = ''; if ( !empty( $attributes_label_option_field ) ) { $available_attribute_values = ic_get_attribute_values( $attributes_label_option_field ); if ( $available_attribute_values ) { $autocomplete = 'data-ic-autocomplete="' . esc_attr( json_encode( $available_attribute_values ) ) . '"'; } } $field_value = is_array( $attributes_option_field ) ? reset( $attributes_option_field ) : $attributes_option_field; $attribute_value_field = ''; ?>
Name Value Unit
class="ic_autocomplete attribute-label" type="text" name="" value=""/> :
ID ) : ''; $product_meta[ '_attribute' . $i ] = !empty( $_POST[ '_attribute' . $i ] ) ? apply_filters( 'save_product_attribute_value', $_POST[ '_attribute' . $i ], $i, $post->ID, $product_meta[ '_attribute-label' . $i ] ) : ''; $product_meta[ '_attribute-unit' . $i ] = !empty( $_POST[ '_attribute-unit' . $i ] ) ? apply_filters( 'save_product_attribute_unit', $_POST[ '_attribute-unit' . $i ], $i, $post->ID, $product_meta[ '_attribute-label' . $i ] ) : ''; } if ( !empty( $_POST[ '_size_length' ] ) ) { $product_meta[ '_size_length' ] = sanitize_text_field( $_POST[ '_size_length' ] ); } if ( !empty( $_POST[ '_size_width' ] ) ) { $product_meta[ '_size_width' ] = sanitize_text_field( $_POST[ '_size_width' ] ); } if ( !empty( $_POST[ '_size_height' ] ) ) { $product_meta[ '_size_height' ] = sanitize_text_field( $_POST[ '_size_height' ] ); } if ( !empty( $_POST[ '_weight' ] ) ) { $product_meta[ '_weight' ] = floatval( $_POST[ '_weight' ] ); } return $product_meta; } function ic_size_field_names() { $field_names = array( '_size_length' => _x( 'L', 'Length', 'ecommerce-product-catalog' ), '_size_width' => _x( 'W', 'Width', 'ecommerce-product-catalog' ), '_size_height' => _x( 'H', 'Height', 'ecommerce-product-catalog' ) ); return apply_filters( 'ic_catalog_size_names', $field_names ); } add_filter( 'active_product_filters', 'ic_activate_size_filter' ); function ic_activate_size_filter( $filters ) { $fields = ic_size_field_names(); if ( !empty( $fields ) ) { $filters = array_merge( $filters, array_keys( $fields ) ); } return $filters; } add_filter( 'product_details_box_visible', 'ic_manage_size_weight_box_visibility' ); function ic_manage_size_weight_box_visibility( $visible ) { if ( $visible ) { return $visible; } if ( is_ic_attributes_size_enabled() || is_ic_attributes_weight_enabled() ) { return true; } return false; } function ic_get_product_size( $product_id, $force_value = false, $size = null, $enable_desc = true ) { if ( empty( $size ) ) { $length = apply_filters( 'ic_front_size_value', get_post_meta( $product_id, '_size_length', true ) ); $width = apply_filters( 'ic_front_size_value', get_post_meta( $product_id, '_size_width', true ) ); $height = apply_filters( 'ic_front_size_value', get_post_meta( $product_id, '_size_height', true ) ); $size[ 'length' ] = !empty( $length ) ? $length : ''; $size[ 'width' ] = !empty( $width ) ? $width : ''; $size[ 'height' ] = !empty( $height ) ? $height : ''; } if ( !is_ic_admin() && !$force_value ) { $unit = ic_attributes_get_size_unit(); $desc = ''; $text_size = ''; $field_names = ic_size_field_names(); foreach ( $field_names as $name => $label ) { $this_desc = ''; $this_text_size = ''; if ( $name === '_size_length' && !empty( $size[ 'length' ] ) ) { $this_desc = $label; $this_text_size = $size[ 'length' ] . ' ' . $unit; } else if ( $name === '_size_width' && !empty( $size[ 'width' ] ) ) { $this_desc .= _x( 'W', 'Width', 'ecommerce-product-catalog' ); $this_text_size .= $size[ 'width' ] . ' ' . $unit; } else if ( $name === '_size_height' && !empty( $size[ 'height' ] ) ) { $this_desc .= _x( 'H', 'Height', 'ecommerce-product-catalog' ); $this_text_size .= $size[ 'height' ] . ' ' . $unit; } if ( !empty( $this_desc ) ) { if ( !empty( $desc ) ) { $desc .= ' x '; } $desc .= $this_desc; if ( !empty( $text_size ) ) { $text_size .= ' x '; } $text_size .= $this_text_size; } } if ( !empty( $desc ) ) { $desc = '(' . $desc . ')'; } if ( !empty( $text_size ) && $enable_desc ) { $text_size .= ' ' . $desc; } return $text_size; } else { return $size; } } function ic_get_product_weight( $product_id, $force_value = false, $weight = null ) { if ( empty( $weight ) ) { $weight = apply_filters( 'ic_front_weight_value', get_post_meta( $product_id, '_weight', true ), $product_id ); } if ( !is_ic_admin() && !$force_value && !empty( $weight ) ) { $unit = ic_attributes_get_weight_unit(); $weight = $weight . ' ' . $unit; } return $weight; } add_action( 'admin_product_details', 'ic_size_metabox', 10, 2 ); /** * Adds attributes meatbox * * @param array $names */ function ic_size_metabox( $product_details, $product_id, $field_name = null, $size = null ) { if ( is_ic_attributes_size_enabled() ) { if ( $field_name === null || empty( $field_name[ 0 ] ) || empty( $field_name[ 1 ] ) || empty( $field_name[ 2 ] ) ) { //$field_name = array( '_size_length', '_size_width', '_size_height' ); $field_names = ic_size_field_names(); } if ( $size === null || !isset( $size[ 'length' ] ) || !isset( $size[ 'width' ] ) || !isset( $size[ 'height' ] ) ) { $size = ic_get_product_size( $product_id ); } if ( !empty( $field_names ) ) { $fields = ''; foreach ( $field_names as $field_name => $field_label ) { if ( $field_name === '_size_length' ) { $val_name = 'length'; } else if ( $field_name === '_size_width' ) { $val_name = 'width'; } else if ( $field_name === '_size_height' ) { $val_name = 'height'; } if ( !empty( $fields ) ) { $fields .= 'x '; } $fields .= ''; } } else { $fields = ''; $fields .= 'x '; $fields .= 'x '; } $label = __( 'Size', 'ecommerce-product-catalog' ); $unit = ic_attributes_get_size_unit(); if ( !empty( $unit ) ) { $label .= ' (' . $unit . ')'; } $product_details .= apply_filters( 'admin_size_table', '
' . $label . ':' . $fields . '
', $product_id ); } return $product_details; } add_action( 'admin_product_details', 'ic_weight_metabox', 10, 2 ); /** * Adds attributes meatbox * * @param array $names */ function ic_weight_metabox( $product_details, $product_id, $field_name = '_weight', $weight = null ) { if ( is_ic_attributes_weight_enabled() ) { if ( $weight === null ) { $weight = get_post_meta( $product_id, '_weight', true ); } $label = __( 'Weight', 'ecommerce-product-catalog' ); $unit = ic_attributes_get_weight_unit(); if ( !empty( $unit ) ) { $label .= ' (' . $unit . ')'; } $product_details .= apply_filters( 'admin_weight_table', '
' . $label . ':
', $product_id ); } return $product_details; }