products(); $shortcode = ''; if ( !empty( $products ) && is_array( $products ) ) { $rows = $this->rows(); $shortcode .= '
'; $shortcode .= '
'; foreach ( $rows as $row ) { $shortcode .= '
'; foreach ( $products as $i => $product_id ) { switch ( $row ) { case 'name': $shortcode .= '
'; if ( !empty( $product_id ) ) { $shortcode .= get_product_name( $product_id ); } $shortcode .= '
'; break; case 'choose_compare': $shortcode .= '
'; $shortcode .= $this->choose( $i, $products ); $shortcode .= '
'; break; case 'image': $shortcode .= '
'; if ( !empty( $product_id ) ) { $shortcode .= get_product_image( $product_id ); } $shortcode .= '
'; break; case 'short_desc': $shortcode .= '
'; if ( !empty( $product_id ) ) { $shortcode .= get_product_short_description( $product_id ); } $shortcode .= '
'; break; case 'attributes': $shortcode .= '
'; if ( !empty( $product_id ) ) { $shortcode .= get_product_attributes( $product_id ); } $shortcode .= '
'; break; default: $shortcode .= apply_filters( 'ic_comparison_table_row', '', $row, $product_id ); } } $shortcode .= '
'; } $shortcode .= '
'; $shortcode .= '
'; } else { $shortcode .= $this->choose(); } return $shortcode; } function rows() { $rows = array( 'name', 'choose_compare', 'image', 'short_desc', 'attributes' ); return apply_filters( 'ic_comparison_table_rows', $rows ); } function products( $i = null ) { $max = 2; $session = get_product_catalog_session(); if ( !isset( $session[ 'comparison' ] ) || !is_array( $session[ 'comparison' ] ) ) { $session[ 'comparison' ] = array(); } if ( !empty( $_GET[ 'compare' ] ) ) { if ( !is_array( $_GET[ 'compare' ] ) ) { $new_compare = intval( $_GET[ 'compare' ] ); if ( !empty( $new_compare ) && !in_array( $new_compare, $session[ 'comparison' ] ) ) { $session[ 'comparison' ][] = $new_compare; } } else { $session[ 'comparison' ] = array_map( 'intval', array_filter( $_GET[ 'compare' ] ) ); } set_product_catalog_session( $session ); } ksort( $session[ 'comparison' ] ); if ( count( $session[ 'comparison' ] ) < $max ) { $session[ 'comparison' ][] = ''; } if ( $i !== null && isset( $session[ 'comparison' ][ $i ] ) ) { return intval( $session[ 'comparison' ][ $i ] ); } return $session[ 'comparison' ]; } function choose( $i = 0, $exclude = null ) { $names = get_catalog_names( 'singular' ); $label = sprintf( __( 'Select %s to compare', 'ecommerce-product-catalog' ), $names ); $selected_product_id = $this->products( $i ); if ( !empty( $selected_product_id ) && ($key = array_search( $selected_product_id, $exclude )) !== false ) { unset( $exclude[ $key ] ); } $select = '
'; foreach ( $exclude as $key => $product_id ) { if ( !empty( $product_id ) && $product_id !== $selected_product_id ) { $select .= ''; } } $select .= ic_select_product( $label, $selected_product_id, 'compare[' . $i . ']', 'ic_self_submit', 0, $exclude ); $select .= '
'; return $select; } function add_shortcode( $content ) { if ( $this->is_comparison() && !has_shortcode( $content, 'catalog_comparison' ) ) { $content .= '[catalog_comparison]'; } return $content; } function is_comparison() { $page_id = $this->page_id(); if ( !empty( $page_id ) && is_page( $page_id ) ) { return true; } return false; } /** * Registers advanced attributes settings * */ function register_setting() { register_setting( 'product_attributes', 'ic_attributes_compare' ); } function button() { $product_id = ic_get_product_id(); $url = $this->url( $product_id ); if ( empty( $url ) ) { return; } ?> label() ?> page_id(); if ( empty( $page_id ) ) { return ''; } $url = get_permalink( $page_id ); if ( !empty( $url ) && !empty( $product_id ) ) { $url = add_query_arg( 'compare', $product_id, $url ); } if ( !empty( $url ) ) { return $url; } return ''; } function settings_page() { $settings = $this->settings(); ?>

:
settings(); if ( !empty( $settings[ 'url' ] ) ) { $page_id = intval( $settings[ 'url' ] ); if ( !empty( $page_id ) ) { return $page_id; } } return ''; } } global $ic_attribute_comparison; $ic_attribute_comparison = new ic_attribute_comparison;