Created
November 13, 2017 05:51
-
-
Save anonymous/9d62720a5dfc909b01612d04c5d92c95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function yummy_pro_get_item_menu_section_details( $input ) { | |
$options = yummy_pro_get_theme_options(); | |
// Item menu type | |
$item_menu_content_type = $options['item_menu_type']; | |
$content = array(); | |
switch ( $item_menu_content_type ) { | |
case 'demo': | |
$title_1 = array( 1 => esc_html__( 'Texas Caviar', 'yummy-pro' ), 2 => esc_html__( 'Spicey Onion Rings', 'yummy-pro' ), 3 => esc_html__( 'Fish & Chips', 'yummy-pro' ), 4 => esc_html__( 'Chicken Wings', 'yummy-pro' ), 5 => esc_html__( 'Shrimp Scampi', 'yummy-pro' ), 6 => esc_html__( 'Double Cheese Burger', 'yummy-pro' ) ); | |
$title_2 = array( 1 => esc_html__( 'Banana Ice Cream', 'yummy-pro' ), 2 => esc_html__( 'Chocolate dipped peanut butter', 'yummy-pro' ), 3 => esc_html__( 'Chocolate brownie cookies', 'yummy-pro' ), 4 => esc_html__( 'galaxy fruit pops', 'yummy-pro' ), 5 => esc_html__( 'Salted chocolate milk', 'yummy-pro' ), 6 => esc_html__( 'Black Forest Cake', 'yummy-pro' ) ); | |
$price = sprintf( esc_html__( '%1$s$%2$s19 %3$s', 'yummy-pro' ), '<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">', '</span> ', '</span>' ); | |
$content[0]['cat_title'] = esc_html__( 'Food & aperitives', 'yummy-pro' ); | |
$content[1]['cat_title'] = esc_html__( 'Deserts', 'yummy-pro' ); | |
for ( $i = 1; $i <= 6; $i++ ) { | |
$content[0]['val'][$i]['title'] = $title_1[$i]; | |
$content[0]['val'][$i]['url'] = '#'; | |
$content[0]['val'][$i]['excerpt'] = esc_html__( 'Suspendisse tempor sapien ut lacus pharetra, rhon cus bibendum dolor maximus. Namde ...', 'yummy-pro' ); | |
$content[0]['val'][$i]['price'] = $price; | |
$content[1]['val'][$i]['title'] = $title_2[$i]; | |
$content[1]['val'][$i]['url'] = '#'; | |
$content[1]['val'][$i]['excerpt'] = esc_html__( 'Suspendisse tempor sapien ut lacus pharetra, rhon cus bibendum dolor maximus. Namde ...', 'yummy-pro' ); | |
$content[1]['val'][$i]['price'] = $price; | |
} | |
break; | |
case 'category': | |
$cat_id = array(); | |
for ( $i = 1; $i <= 2; $i++ ) { | |
if ( ! empty( $options['item_menu_category_' . $i ] ) ) | |
$cat_id[$i] = $options['item_menu_category_' . $i ]; | |
} | |
// Bail if no valid pages are selected. | |
if ( empty( $cat_id ) ) { | |
return $input; | |
} | |
$args = array(); | |
foreach ( $cat_id as $id ) { | |
if ( ! empty( $id ) ) : | |
$args[] = array( | |
'no_found_rows' => true, | |
'cat' => $id, | |
'post_type' => 'post', | |
'posts_per_page' => 8, | |
); | |
$term = get_the_category_by_ID( $id ); | |
$content[]['cat_title'] = ! empty( $term ) ? $term : ''; | |
endif; | |
} | |
break; | |
case 'woo-category': | |
$cat_id = array(); | |
for ( $i = 1; $i <= 2; $i++ ) { | |
if ( ! empty( $options['item_menu_woo_category_' . $i ] ) ) | |
$cat_id[$i] = $options['item_menu_woo_category_' . $i ]; | |
} | |
// Bail if no valid pages are selected. | |
if ( empty( $cat_id ) ) { | |
return $input; | |
} | |
$args = array(); | |
foreach ( $cat_id as $id ) { | |
if ( ! empty( $id ) ) : | |
$args[] = array( | |
'post_type' => 'product', | |
'posts_per_page' => 8, | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'product_cat', | |
'field' => 'id', | |
'terms' => $id, | |
) ) ); | |
$term = get_term( $id, $taxonomy = 'product_cat' ); | |
$content[]['cat_title'] = ! empty( $term ) ? $term->name : ''; | |
endif; | |
} | |
break; | |
} | |
if ( 'demo' != $item_menu_content_type ) { | |
// Fetch posts. | |
if ( ! empty( $args ) ) { | |
$count = 0; | |
foreach ( $args as $query_args ) { | |
$posts = get_posts( $query_args ); | |
$i = 1; | |
foreach ( $posts as $post ) : | |
$page_id = $post->ID; | |
if ( 'woo-category' == $item_menu_content_type ) { | |
$product = new WC_Product( $page_id ); | |
$content[$count]['val'][$i]['price'] = $product->get_price_html(); | |
} else { | |
$content[$count]['val'][$i]['price'] = ''; | |
} | |
$content[$count]['val'][$i]['title'] = get_the_title( $page_id ); | |
$content[$count]['val'][$i]['url'] = get_the_permalink( $page_id ); | |
$content[$count]['val'][$i]['excerpt'] = yummy_pro_trim_content( 11, $post ); | |
$i++; | |
endforeach; | |
$count++; | |
} | |
} | |
} | |
if ( ! empty( $content ) ) { | |
$input = $content; | |
} | |
return $input; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment