'loop-container',
'footer' => 'overflow-container',
'render' => 'ct_modern_store_infinite_scroll_render'
) );
add_theme_support( 'custom-logo', array(
'height' => 60,
'width' => 200,
'flex-height' => true,
'flex-width' => true
) );
// Add WooCommerce support
add_theme_support( 'woocommerce' );
// Add support for WooCommerce image gallery features
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
add_image_size( 'homepage-thumb', 600, 600, true ); // (cropped)
// Gutenberg - add support for editor styles
add_theme_support('editor-styles');
// Gutenberg - wide images
add_theme_support( 'align-wide' );
// Gutenberg - modify the font sizes
add_theme_support( 'editor-font-sizes', array(
array(
'name' => __( 'small', 'modern-store' ),
'shortName' => __( 'S', 'modern-store' ),
'size' => 12,
'slug' => 'small'
),
array(
'name' => __( 'regular', 'modern-store' ),
'shortName' => __( 'M', 'modern-store' ),
'size' => 16,
'slug' => 'regular'
),
array(
'name' => __( 'large', 'modern-store' ),
'shortName' => __( 'L', 'modern-store' ),
'size' => 21,
'slug' => 'large'
),
array(
'name' => __( 'larger', 'modern-store' ),
'shortName' => __( 'XL', 'modern-store' ),
'size' => 28,
'slug' => 'larger'
)
) );
register_nav_menus( array(
'primary' => esc_html__( 'Primary', 'modern-store' ),
'secondary' => esc_html__( 'Secondary', 'modern-store' )
) );
load_theme_textdomain( 'modern-store', get_template_directory() . '/languages' );
}
}
add_action( 'after_setup_theme', 'ct_modern_store_theme_setup' );
//----------------------------------------------------------------------------------
// Register widget areas
//----------------------------------------------------------------------------------
if ( ! function_exists( ( 'ct_modern_store_register_widget_areas' ) ) ) {
function ct_modern_store_register_widget_areas() {
register_sidebar( array(
'name' => esc_html__( 'Store Sidebar', 'modern-store' ),
'id' => 'store',
'description' => esc_html__( 'These widgets display in the sidebar of the store page', 'modern-store' ),
'before_widget' => '',
'before_title' => '
'
) );
}
}
add_action( 'widgets_init', 'ct_modern_store_register_widget_areas' );
//----------------------------------------------------------------------------------
// Customize comment markup
//----------------------------------------------------------------------------------
if ( ! function_exists( ( 'ct_modern_store_customize_comments' ) ) ) {
function ct_modern_store_customize_comments( $comment, $args, $depth ) { ?>
id="li-comment-">
post_content, '' );
$read_more_text = get_theme_mod( 'read_more_text' );
$new_excerpt_length = get_theme_mod( 'excerpt_length' );
$excerpt_more = ( $new_excerpt_length === 0 ) ? '' : '…';
$output = '';
// add ellipsis for automatic excerpts
if ( empty( $ismore ) && $custom !== true ) {
$output .= $excerpt_more;
}
// Because i18n text cannot be stored in a variable
if ( empty( $read_more_text ) ) {
$output .= '';
} else {
$output .= '';
}
return $output;
}
}
add_filter( 'the_content_more_link', 'ct_modern_store_filter_read_more_link' ); // more tags
add_filter( 'excerpt_more', 'ct_modern_store_filter_read_more_link', 10 ); // automatic excerpts
//----------------------------------------------------------------------------------
// Add more link to excerpts
//----------------------------------------------------------------------------------
if ( ! function_exists( 'ct_modern_store_filter_manual_excerpts' ) ) {
function ct_modern_store_filter_manual_excerpts( $excerpt ) {
$excerpt_more = '';
if ( has_excerpt() ) {
$excerpt_more = ct_modern_store_filter_read_more_link( true );
}
return $excerpt . $excerpt_more;
}
}
add_filter( 'get_the_excerpt', 'ct_modern_store_filter_manual_excerpts' );
//----------------------------------------------------------------------------------
// Output content VS excerpt based on user settings
//----------------------------------------------------------------------------------
if ( ! function_exists( 'ct_modern_store_excerpt' ) ) {
function ct_modern_store_excerpt() {
global $post;
$show_full_post = get_theme_mod( 'full_post' );
$ismore = strpos( $post->post_content, '' );
if ( $show_full_post === 'yes' || $ismore ) {
the_content();
} else {
the_excerpt();
}
}
}
//----------------------------------------------------------------------------------
// Update automatic excerpt word count based on user settings
//----------------------------------------------------------------------------------
if ( ! function_exists( 'ct_modern_store_custom_excerpt_length' ) ) {
function ct_modern_store_custom_excerpt_length( $length ) {
$new_excerpt_length = get_theme_mod( 'excerpt_length' );
if ( ! empty( $new_excerpt_length ) && $new_excerpt_length != 25 ) {
return $new_excerpt_length;
} elseif ( $new_excerpt_length === 0 ) {
return 0;
} else {
return 25;
}
}
}
add_filter( 'excerpt_length', 'ct_modern_store_custom_excerpt_length', 99 );
//----------------------------------------------------------------------------------
// Turn off scrolling to after excerpt after clicking 'read more' link
//----------------------------------------------------------------------------------
if ( ! function_exists( 'ct_modern_store_remove_more_link_scroll' ) ) {
function ct_modern_store_remove_more_link_scroll( $link ) {
$link = preg_replace( '|#more-[0-9]+|', '', $link );
return $link;
}
}
add_filter( 'the_content_more_link', 'ct_modern_store_remove_more_link_scroll' );
//----------------------------------------------------------------------------------
// Output Featured Image
//----------------------------------------------------------------------------------
if ( ! function_exists( 'ct_modern_store_featured_image' ) ) {
function ct_modern_store_featured_image() {
global $post;
$featured_image = '';
if ( has_post_thumbnail( $post->ID ) ) {
$featured_image = '';
if ( is_singular() ) {
$featured_image .= '
' . get_the_post_thumbnail( $post->ID, 'full' ) . '
';
} else {
$featured_image .= '
';
}
$featured_image .= '
';
}
$featured_image = apply_filters( 'ct_modern_store_featured_image', $featured_image );
if ( $featured_image ) {
echo $featured_image;
}
}
}
//----------------------------------------------------------------------------------
// Return array of all social sites and IDs
//----------------------------------------------------------------------------------
if ( ! function_exists( 'ct_modern_store_social_array' ) ) {
function ct_modern_store_social_array() {
$social_sites = array(
'twitter' => 'ct_modern_store_twitter_profile',
'facebook' => 'ct_modern_store_facebook_profile',
'instagram' => 'ct_modern_store_instagram_profile',
'linkedin' => 'ct_modern_store_linkedin_profile',
'pinterest' => 'ct_modern_store_pinterest_profile',
'google-plus' => 'ct_modern_store_googleplus_profile',
'youtube' => 'ct_modern_store_youtube_profile',
'email' => 'ct_modern_store_email_profile',
'phone' => 'ct_modern_store_phone_profile',
'email-form' => 'ct_modern_store_email_form_profile',
'amazon' => 'ct_modern_store_amazon_profile',
'artstation' => 'ct_modern_store_artstation_profile',
'bandcamp' => 'ct_modern_store_bandcamp_profile',
'behance' => 'ct_modern_store_behance_profile',
'bitbucket' => 'ct_modern_store_bitbucket_profile',
'codepen' => 'ct_modern_store_codepen_profile',
'delicious' => 'ct_modern_store_delicious_profile',
'deviantart' => 'ct_modern_store_deviantart_profile',
'digg' => 'ct_modern_store_digg_profile',
'discord' => 'ct_modern_store_discord_profile',
'dribbble' => 'ct_modern_store_dribbble_profile',
'etsy' => 'ct_modern_store_etsy_profile',
'flickr' => 'ct_modern_store_flickr_profile',
'foursquare' => 'ct_modern_store_foursquare_profile',
'github' => 'ct_modern_store_github_profile',
'goodreads' => 'ct_modern_store_goodreads_profile',
'google-wallet' => 'ct_modern_store_google_wallet_profile',
'hacker-news' => 'ct_modern_store_hacker-news_profile',
'medium' => 'ct_modern_store_medium_profile',
'meetup' => 'ct_modern_store_meetup_profile',
'mixcloud' => 'ct_modern_store_mixcloud_profile',
'ok-ru' => 'ct_modern_store_ok_ru_profile',
'patreon' => 'ct_modern_store_patreon_profile',
'paypal' => 'ct_modern_store_paypal_profile',
'podcast' => 'ct_modern_store_podcast_profile',
'quora' => 'ct_modern_store_quora_profile',
'qq' => 'ct_modern_store_qq_profile',
'ravelry' => 'ct_modern_store_ravelry_profile',
'reddit' => 'ct_modern_store_reddit_profile',
'rss' => 'ct_modern_store_rss_profile',
'skype' => 'ct_modern_store_skype_profile',
'slack' => 'ct_modern_store_slack_profile',
'slideshare' => 'ct_modern_store_slideshare_profile',
'snapchat' => 'ct_modern_store_snapchat_profile',
'soundcloud' => 'ct_modern_store_soundcloud_profile',
'spotify' => 'ct_modern_store_spotify_profile',
'stack-overflow' => 'ct_modern_store_stack_overflow_profile',
'steam' => 'ct_modern_store_steam_profile',
'stumbleupon' => 'ct_modern_store_stumbleupon_profile',
'telegram' => 'ct_modern_store_telegram_profile',
'tencent-weibo' => 'ct_modern_store_tencent_weibo_profile',
'tumblr' => 'ct_modern_store_tumblr_profile',
'twitch' => 'ct_modern_store_twitch_profile',
'vimeo' => 'ct_modern_store_vimeo_profile',
'vine' => 'ct_modern_store_vine_profile',
'vk' => 'ct_modern_store_vk_profile',
'wechat' => 'ct_modern_store_wechat_profile',
'weibo' => 'ct_modern_store_weibo_profile',
'whatsapp' => 'ct_modern_store_whatsapp_profile',
'xing' => 'ct_modern_store_xing_profile',
'yahoo' => 'ct_modern_store_yahoo_profile',
'yelp' => 'ct_modern_store_yelp_profile',
'500px' => 'ct_modern_store_500px_profile'
);
return apply_filters( 'ct_modern_store_social_array_filter', $social_sites );
}
}
//----------------------------------------------------------------------------------
// Output social iconss
//----------------------------------------------------------------------------------
if ( ! function_exists( 'ct_modern_store_social_icons_output' ) ) {
function ct_modern_store_social_icons_output() {
$social_sites = ct_modern_store_social_array();
// store the site name and url
foreach ( $social_sites as $social_site => $profile ) {
if ( strlen( get_theme_mod( $social_site ) ) > 0 ) {
$active_sites[ $social_site ] = $social_site;
}
}
if ( ! empty( $active_sites ) ) {
echo "";
}
}
}
/*
* WP will apply the ".menu-primary-items" class & id to the containing instead of
* making styling difficult and confusing. Using this wrapper to add a unique class to make styling easier.
*/
if ( ! function_exists( ( 'ct_modern_store_wp_page_menu' ) ) ) {
function ct_modern_store_wp_page_menu() {
wp_page_menu( array(
"menu_class" => "menu-unset",
"depth" => - 1
)
);
}
}
//----------------------------------------------------------------------------------
// Output dropdown buttons for mobile menu
//----------------------------------------------------------------------------------
if ( ! function_exists( ( 'ct_modern_store_nav_dropdown_buttons' ) ) ) {
function ct_modern_store_nav_dropdown_buttons( $item_output, $item, $depth, $args ) {
if ( $args->theme_location == 'primary' || $args->theme_location == 'secondary' ) {
if ( in_array( 'menu-item-has-children', $item->classes ) || in_array( 'page_item_has_children', $item->classes ) ) {
$item_output = str_replace( $args->link_after . '', $args->link_after . '', $item_output );
}
}
return $item_output;
}
}
add_filter( 'walker_nav_menu_start_el', 'ct_modern_store_nav_dropdown_buttons', 10, 4 );
//----------------------------------------------------------------------------------
// Add featured status marker to sticky posts
//----------------------------------------------------------------------------------
if ( ! function_exists( ( 'ct_modern_store_sticky_post_marker' ) ) ) {
function ct_modern_store_sticky_post_marker() {
if ( is_sticky() && ! is_archive() ) {
echo '' . esc_html__( "Featured", "modern-store" ) . '
';
}
}
}
add_action( 'sticky_post_status', 'ct_modern_store_sticky_post_marker' );
//----------------------------------------------------------------------------------
// Reset the Customizer options after user clicks reset button in theme options page
//----------------------------------------------------------------------------------
if ( ! function_exists( ( 'ct_modern_store_reset_customizer_options' ) ) ) {
function ct_modern_store_reset_customizer_options() {
if ( empty( $_POST['modern_store_reset_customizer'] ) || 'modern_store_reset_customizer_settings' !== $_POST['modern_store_reset_customizer'] ) {
return;
}
if ( ! wp_verify_nonce( wp_unslash( $_POST['modern_store_reset_customizer_nonce'] ), 'modern_store_reset_customizer_nonce' ) ) {
return;
}
if ( ! current_user_can( 'edit_theme_options' ) ) {
return;
}
$mods_array = array(
'homepage_on_sale_products',
'homepage_on_sale_products_title',
'homepage_on_sale_products_count',
'homepage_on_sale_products_order',
'homepage_latest_products',
'homepage_latest_products_title',
'homepage_latest_products_count',
'homepage_latest_products_category',
'homepage_top_rated_products',
'homepage_top_rated_products_title',
'homepage_top_rated_products_count',
'homepage_featured_products',
'homepage_featured_products_title',
'homepage_featured_products_count',
'homepage_featured_products_order',
'homepage_categories',
'homepage_categories_title',
'homepage_categories_count',
'homepage_categories_subcategory_display',
'homepage_categories_thumbnail',
'homepage_categories_product_count',
'homepage_categories_order',
'header_promo_display',
'header_promo_title_text',
'header_promo_subtitle_text',
'header_promo_button_text',
'header_promo_button_url',
'header_promo_text_alignment',
'header_promo_text_width',
'header_promo_image',
'header_promo_height',
'header_promo_overlay_color',
'header_promo_overlay_opacity',
'color_primary',
'store_search_bar_display',
'store_search_bar_category_select',
'store_search_bar_submit_button',
'store_search_bar_category_select_label',
'user_icon_display',
'user_icon_mobile_display',
'shopping_cart_display',
'shopping_cart_display_count',
'shopping_cart_mobile_display',
'fi_size_type',
'fi_size',
'full_post',
'excerpt_length',
'read_more_text',
'last_updated',
'scroll_to_top'
);
$social_sites = ct_modern_store_social_array();
// add social site settings to mods array
foreach ( $social_sites as $social_site => $value ) {
$mods_array[] = $social_site;
}
$mods_array = apply_filters( 'ct_modern_store_mods_to_remove', $mods_array );
foreach ( $mods_array as $theme_mod ) {
remove_theme_mod( $theme_mod );
}
$redirect = admin_url( 'themes.php?page=modern-store-options' );
$redirect = add_query_arg( 'modern_store_status', 'deleted', $redirect );
// safely redirect
wp_safe_redirect( $redirect );
exit;
}
}
add_action( 'admin_init', 'ct_modern_store_reset_customizer_options' );
//----------------------------------------------------------------------------------
// Admin notice that Customizer settings were deleted
//----------------------------------------------------------------------------------
if ( ! function_exists( ( 'ct_modern_store_delete_settings_notice' ) ) ) {
function ct_modern_store_delete_settings_notice() {
if ( isset( $_GET['modern_store_status'] ) ) {
?>
';
} elseif ( $type == 'close-menu' ) {
$svg = '';
}
return $svg;
}
}
//----------------------------------------------------------------------------------
// Output meta elements in the
//----------------------------------------------------------------------------------
if ( ! function_exists( ( 'ct_modern_store_add_meta_elements' ) ) ) {
function ct_modern_store_add_meta_elements() {
$meta_elements = '';
$meta_elements .= sprintf( '' . "\n", esc_attr( get_bloginfo( 'charset' ) ) );
$meta_elements .= '' . "\n";
$theme = wp_get_theme( get_template() );
$template = sprintf( '' . "\n", esc_attr( $theme->get( 'Name' ) ), esc_attr( $theme->get( 'Version' ) ) );
$meta_elements .= $template;
echo $meta_elements;
}
}
add_action( 'wp_head', 'ct_modern_store_add_meta_elements', 1 );
//----------------------------------------------------------------------------------
// Select proper template part for Jetpack infinite scroll compatibility
//----------------------------------------------------------------------------------
if ( ! function_exists( ( 'ct_modern_store_infinite_scroll_render' ) ) ) {
function ct_modern_store_infinite_scroll_render() {
while ( have_posts() ) {
the_post();
get_template_part( 'content', 'archive' );
}
}
}
//----------------------------------------------------------------------------------
// Get correct template part from main loop
// Routing templates this way to follow DRY coding patterns
// (Loop is only present in index.php)
//----------------------------------------------------------------------------------
if ( ! function_exists( 'ct_modern_store_get_content_template' ) ) {
function ct_modern_store_get_content_template() {
if ( is_home() || is_archive() || is_search() ) {
get_template_part( 'content-archive', get_post_type() );
} else {
get_template_part( 'content', get_post_type() );
}
}
}
//----------------------------------------------------------------------------------
// Allow Skype URIs to be used
//----------------------------------------------------------------------------------
if ( ! function_exists( 'ct_modern_store_allow_skype_protocol' ) ) {
function ct_modern_store_allow_skype_protocol( $protocols ) {
$protocols[] = 'skype';
return $protocols;
}
}
add_filter( 'kses_allowed_protocols' , 'ct_modern_store_allow_skype_protocol' );
//----------------------------------------------------------------------------------
// Remove label that can't be edited with the_archive_title() e.g. "Category: Business" => "Business"
//----------------------------------------------------------------------------------
if ( ! function_exists( 'ct_modern_store_modify_archive_titles' ) ) {
function ct_modern_store_modify_archive_titles( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false );
} elseif ( is_tag() ) {
$title = single_tag_title( '', false );
} elseif ( is_author() ) {
$title = get_the_author();
} elseif ( is_month() ) {
$title = single_month_title( ' ' );
}
// is_year() and is_day() neglected b/c there is no analogous function for retrieving the page title
return $title;
}
}
add_filter( 'get_the_archive_title', 'ct_modern_store_modify_archive_titles' );
//--------------------------------------------------------------------------------------------------
// Sanitize CSS then convert ">" back into ">" character so direct descendant CSS selectors work
//--------------------------------------------------------------------------------------------------
if ( ! function_exists( 'ct_modern_store_sanitize_css' ) ) {
function ct_modern_store_sanitize_css( $css ) {
$css = wp_kses( $css, '' );
$css = str_replace( '>', '>', $css );
return $css;
}
}
//----------------------------------------------------------------------------------
// Return CSS based on the user's Customizer selected colors.
//----------------------------------------------------------------------------------
if ( ! function_exists( 'ct_modern_store_override_colors' ) ) {
function ct_modern_store_override_colors() {
$color_css = '';
$primary_color = get_theme_mod( 'color_primary' );
if ( $primary_color != '' && $primary_color != '#ffc270' ) {
$color_css = "a:hover,a:active,a:focus,.design-credit a:hover,.design-credit a:active,.design-credit a:focus,.menu-primary ul li.current-menu-item > a:link,.menu-primary ul li.current-menu-item > a:visited,
.menu-primary ul li.current_page_item > a:link,.menu-primary ul li.current_page_item > a:visited,
.widget_rating_filter .star-rating,.woocommerce.single-product .star-rating,.woocommerce.single-product #reviews #comments .review .star-rating,.woocommerce.single-product .comment-form .stars a,
.woocommerce ul.products li.product .star-rating,.woocommerce-message:before,.woocommerce-info:before,.user-icon a:hover, .user-icon a:active, .user-icon a:focus, .cart-icon a:hover, .cart-icon a:active, .cart-icon a:focus,
.woocommerce-cart .shopping-cart-container a,.woocommerce-account .user-account-icon-container a,#cancel-comment-reply-link:link, .comment-reply-link:link, .comment-edit-link:link, #cancel-comment-reply-link:visited,
.comment-reply-link:visited, .comment-edit-link:visited,.widget_products .star-rating {
color: $primary_color;
}";
$color_css .= "input[type='submit']:hover,input[type='submit']:active,input[type='submit']:focus,.comment-form .form-submit input:hover,.post-tags a:hover,
.post-tags a:active,.post-tags a:focus,.site-header .search-form-container .submit-button,.woocommerce .widget_price_filter .ui-slider-horizontal .ui-slider-range,.woocommerce .widget_price_filter .ui-slider .ui-slider-handle,
.woocommerce .widget_price_filter .button:hover,.woocommerce .widget_price_filter .button:active,.woocommerce .widget_price_filter .button:focus,.woocommerce-cart .woocommerce-cart-form__contents .actions > .button:hover,
.woocommerce-cart .woocommerce-cart-form__contents .actions > .button:active,.woocommerce-cart .woocommerce-cart-form__contents .actions > .button:focus,.woocommerce-cart .cart-collaterals .cart_totals .checkout-button:hover,
.woocommerce-cart .cart-collaterals .cart_totals .checkout-button:active,.woocommerce-cart .cart-collaterals .cart_totals .checkout-button:focus,.woocommerce-checkout .checkout #place_order:hover,.woocommerce-checkout .checkout #place_order:active,
.woocommerce-checkout .checkout #place_order:focus,.woocommerce.single-product .entry .onsale,.woocommerce.single-product form .single_add_to_cart_button:hover,.woocommerce.single-product form .single_add_to_cart_button:active,
.woocommerce.single-product form .single_add_to_cart_button:focus,.woocommerce.single-product #review_form #respond .form-submit input:hover,.woocommerce ul.products li.product .button:hover,.woocommerce ul.products li.product .button:active,
.woocommerce ul.products li.product .button:focus,.woocommerce ul.products li.product .onsale,.woocommerce nav.woocommerce-pagination ul li a:hover,.woocommerce nav.woocommerce-pagination ul li a:active,.woocommerce nav.woocommerce-pagination ul li a:focus,
.woocommerce a.button:hover,.woocommerce a.button:active,.woocommerce a.button:focus,.woocommerce-message a.button:hover,.woocommerce-message a.button:active,.woocommerce-message a.button:focus,.woocommerce button.button:hover,
.woocommerce button.button:active,.woocommerce button.button:focus,.woocommerce-account .woocommerce-MyAccount-content .woocommerce-orders-table .woocommerce-orders-table__cell-order-actions .button:hover,.woocommerce-store-notice,p.demo_store,
.cart-count, .social-media-icons a:hover,.social-media-icons a:active,.social-media-icons a:focus {
background: $primary_color;
}";
$color_css .= "blockquote,.wp-block-quote,.wp-block-quote.is-style-large,input[type='text']:focus,input[type='email']:focus,input[type='password']:focus,input[type='number']:focus,input[type='search']:focus,
input[type='tel']:focus,input[type='url']:focus,textarea:focus,.comment-form input:focus,.comment-form textarea:focus,.pagination a:hover,.pagination a:active,.pagination a:focus,.blog .featured-image-container:hover,.archive .featured-image-container:hover,.search-results .featured-image-container:hover,.toggle-dropdown.open,.more-link:hover,.more-link:active,.more-link:focus,
.post-tags a:hover,.post-tags a:active,.post-tags a:focus,.further-reading div:hover,.site-header .search-form-container .search-field:focus,.search .main-container .search-form .search-field:focus,
.woocommerce-cart .woocommerce-cart-form__contents .product-quantity input:focus,.woocommerce-cart .woocommerce-cart-form__contents .coupon .input-text:focus,.woocommerce.single-product form .quantity input:focus,
.woocommerce ul.products li.product .button,.woocommerce-message,.woocommerce-info, .social-media-icons a:hover,.social-media-icons a:active,.social-media-icons a:focus {
border-color: $primary_color;
}";
}
return $color_css;
}
}
//----------------------------------------------------------------------------------
// Output the user's custom colors
//----------------------------------------------------------------------------------
if ( ! function_exists( 'ct_modern_store_output_color_css' ) ) {
function ct_modern_store_output_color_css() {
if ( !is_rtl() ) {
$color_css = ct_modern_store_override_colors();
if ( !empty( $color_css ) ) {
wp_add_inline_style( 'ct-modern-store-style', ct_modern_store_sanitize_css( $color_css ) );
}
}
}
}
add_action( 'wp_enqueue_scripts', 'ct_modern_store_output_color_css', 20 );
//----------------------------------------------------------------------------------
// Output differently for RTL b/c RTL stylesheets have no handle (not enqueued!!) and the
// element is output so late
//----------------------------------------------------------------------------------
if ( ! function_exists( 'ct_modern_store_output_color_css_rtl' ) ) {
function ct_modern_store_output_color_css_rtl() {
if ( is_rtl() ) {
$color_css = ct_modern_store_override_colors();
if ( !empty($color_css) ) {
echo '';
}
}
}
}
add_action( 'wp_head', 'ct_modern_store_output_color_css_rtl', 99 );
//----------------------------------------------------------------------------------
// Output the "Last Updated" date on posts
//----------------------------------------------------------------------------------
if ( ! function_exists( 'ct_modern_store_output_last_updated_date' ) ) {
function ct_modern_store_output_last_updated_date() {
global $post;
if ( get_the_modified_date() != get_the_date() ) {
$updated_post = get_post_meta( $post->ID, 'ct_modern_store_last_updated', true );
$updated_customizer = get_theme_mod( 'last_updated' );
if (
( $updated_customizer == 'yes' && ($updated_post != 'no') )
|| $updated_post == 'yes'
) {
echo ''. esc_html__("Last updated on", "modern-store") . ' ' . get_the_modified_date() . '
';
}
}
}
}
//----------------------------------------------------------------------------------
// Output the markup for the optional scroll-to-top arrow
//----------------------------------------------------------------------------------
if ( ! function_exists( 'ct_modern_store_scroll_to_top_arrow' ) ) {
function ct_modern_store_scroll_to_top_arrow() {
$setting = get_theme_mod('scroll_to_top');
if ( $setting == 'yes' ) {
echo '';
}
}
}
add_action( 'ct_modern_store_body_bottom', 'ct_modern_store_scroll_to_top_arrow');
//----------------------------------------------------------------------------------
// Output CSS to style height of Featured Images based on Customizer setting
//----------------------------------------------------------------------------------
function ct_modern_store_output_fi_styles() {
$css = '';
$fi_size_type = get_theme_mod( 'fi_size_type' );
if ( $fi_size_type == 'no' ) {
$css .= ".featured-image {
padding-bottom: 0;
height: auto;
}";
$css .= ".featured-image > a, .featured-image > a > img, .featured-image > img {
position: static;
}";
} else {
$fi_size = get_theme_mod( 'fi_size' );
if ( !empty($fi_size) && $fi_size != 50 ) {
$css .= ".featured-image { padding-bottom: $fi_size%; }";
}
}
if ( !empty( $css ) ) {
$css = ct_modern_store_sanitize_css($css);
wp_add_inline_style( 'ct-modern-store-style', $css );
}
}
add_action( 'wp_enqueue_scripts', 'ct_modern_store_output_fi_styles', 99 );
//----------------------------------------------------------------------------------
// Output CSS to update search form styles based on which elements are hidden
//----------------------------------------------------------------------------------
function ct_modern_store_update_search_form_styles() {
$css = '';
$cat_select = get_theme_mod( 'store_search_bar_category_select' );
$submit_button = get_theme_mod( 'store_search_bar_submit_button' );
if ( $cat_select == 'no' ) {
$css .= ".site-header .search-form-container .search-field {
border-radius: 18px 0 0 18px;
}";
}
if ( $submit_button == 'no' ) {
$css .= ".site-header .search-form-container .search-field {
border-radius: 0 18px 18px 0;
}";
}
if ( $cat_select == 'no' && $submit_button == 'no' ) {
$css .= ".site-header .search-form-container .search-field {
border-radius: 18px;
}";
}
if ( !empty( $css ) ) {
$css = ct_modern_store_sanitize_css($css);
wp_add_inline_style( 'ct-modern-store-style', $css );
}
}
add_action( 'wp_enqueue_scripts', 'ct_modern_store_update_search_form_styles', 20 );
//----------------------------------------------------------------------------------
// Update styles for user account icon
//----------------------------------------------------------------------------------
function ct_modern_store_update_user_icon_styles() {
$css = '';
if ( get_theme_mod( 'user_icon_mobile_display' ) == 'no' ) {
$css .= '@media all and (max-width: 799px) {
.user-account-icon-container {
display: none;
}
}';
}
if ( !empty( $css ) ) {
$css = ct_modern_store_sanitize_css($css);
wp_add_inline_style( 'ct-modern-store-style', $css );
}
}
add_action( 'wp_enqueue_scripts', 'ct_modern_store_update_user_icon_styles', 20 );
//----------------------------------------------------------------------------------
// Update styles for shopping cart icon
//----------------------------------------------------------------------------------
function modern_store_update_shopping_cart_styles() {
$css = '';
if ( get_theme_mod( 'shopping_cart_mobile_display' ) == 'no' ) {
$css .= '@media all and (max-width: 799px) {
.shopping-cart-container {
display: none;
}
}';
}
if ( !empty( $css ) ) {
$css = ct_modern_store_sanitize_css($css);
wp_add_inline_style( 'ct-modern-store-style', $css );
}
}
add_filter( 'wp_enqueue_scripts', 'modern_store_update_shopping_cart_styles', 20 );
//----------------------------------------------------------------------------------
// Update cart count in shopping cart live
//----------------------------------------------------------------------------------
function ct_modern_store_update_cart_count( $fragments ) {
global $woocommerce;
ob_start();
?>
cart->get_cart_contents_count(); ?>
'product',
'posts_per_page' => $count,
'meta_query' => WC()->query->get_meta_query(),
'post__in' => array_merge( array( 0 ), wc_get_product_ids_on_sale() ),
);
if ( $order == 'oldest' ) {
$loop_args['order'] = 'ASC';
}
if ( $order == 'cheapest' || $order == 'most-expensive' ) {
$loop_args['orderby'] = 'meta_value_num';
$loop_args['meta_key'] = '_price';
}
if ( $order == 'cheapest' ) {
$loop_args['order'] = 'ASC';
}
} elseif ( $setting == 'modern_store_homepage_latest_products' ) {
if ( get_theme_mod( 'homepage_latest_products' ) == 'no' ) {
return;
}
$class = 'latest-products woocommerce';
$title = get_theme_mod( 'homepage_latest_products_title' ) ? get_theme_mod( 'homepage_latest_products_title' ) : __( 'Latest Products', 'modern-store' );
$count = get_theme_mod( 'homepage_latest_products_count' ) ? get_theme_mod( 'homepage_latest_products_count' ) : 7;
$category = get_theme_mod( 'homepage_latest_products_category' ) ? get_theme_mod( 'homepage_latest_products_category' ) : 'all';
$loop_args = array(
'post_type' => 'product',
'posts_per_page' => $count,
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $category,
'operator' => 'IN'
),
array(
'taxonomy' => 'product_visibility',
'field' => 'slug',
'terms' => 'exclude-from-catalog',
'operator' => 'NOT IN'
)
)
);
} elseif ( $setting == 'modern_store_homepage_top_rated_products' ) {
if ( get_theme_mod( 'homepage_top_rated_products' ) == 'no' ) {
return;
}
$class = 'top-rated-products woocommerce';
$title = get_theme_mod( 'homepage_top_rated_products_title' ) ? get_theme_mod( 'homepage_top_rated_products_title' ) : __( 'Top-rated Products', 'modern-store' );
$count = get_theme_mod( 'homepage_top_rated_products_count' ) ? get_theme_mod( 'homepage_top_rated_products_count' ) : 4;
$loop_args = array(
'post_type' => 'product',
'posts_per_page' => $count,
'meta_key' => '_wc_average_rating',
'orderby' => 'meta_value_num',
'order' => 'DESC',
);
} elseif ( $setting == 'modern_store_homepage_featured_products' ) {
if ( get_theme_mod( 'homepage_featured_products' ) == 'no' ) {
return;
}
$class = 'featured-products woocommerce';
$title = get_theme_mod( 'homepage_featured_products_title' ) ? get_theme_mod( 'homepage_featured_products_title' ) : __( 'Featured Products', 'modern-store' );
$count = get_theme_mod( 'homepage_featured_products_count' ) ? get_theme_mod( 'homepage_featured_products_count' ) : 4;
$order = get_theme_mod( 'homepage_featured_products_order' ) ? get_theme_mod( 'homepage_featured_products_order' ) : 'newest';
$loop_args = array(
'post_type' => 'product',
'posts_per_page' => $count,
'tax_query' => array(
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
)
)
);
if ( $order == 'oldest' ) {
$loop_args['order'] = 'ASC';
}
if ( $order == 'cheapest' || $order == 'most-expensive' ) {
$loop_args['orderby'] = 'meta_value_num';
$loop_args['meta_key'] = '_price';
}
if ( $order == 'cheapest' ) {
$loop_args['order'] = 'ASC';
}
}
// Loop and output products
echo '';
echo '
'. esc_html( $title ) .'
';
echo '
';
$loop = new WP_Query( $loop_args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( 'content', 'product' );
endwhile;
} else {
echo __( 'No products found', 'modern-store' );
}
wp_reset_postdata();
echo '
';
echo '
';
}
//----------------------------------------------------------------------------------
// Output product categories ssection based on user settings (used in templates/homepage.php)
//----------------------------------------------------------------------------------
function ct_modern_store_homepage_categories() {
if ( get_theme_mod( 'homepage_categories' ) == 'no' ) {
return;
}
$title = get_theme_mod( 'homepage_categories_title' ) ? get_theme_mod( 'homepage_categories_title' ) : __( 'Shop by Category', 'modern-store' );
$count = get_theme_mod( 'homepage_categories_count' ) ? get_theme_mod( 'homepage_categories_count' ) : 3;
$subcategories = get_theme_mod( 'homepage_categories_subcategory_display' ) ? get_theme_mod( 'homepage_categories_subcategory_display' ) : 'no';
$product_categories = get_terms('product_cat');
$order = get_theme_mod( 'homepage_categories_order' ) ? get_theme_mod( 'homepage_categories_order' ) : 'alphabetical';
$loop_count = 0;
$category_html = '';
if ( !empty( $product_categories ) ) {
if ( $order == 'reverse-alphabetical' ) {
$product_categories = array_reverse( $product_categories );
}
if ( $order == 'newest' ) {
uasort($product_categories, function($a, $b) {
return $b->term_id - $a->term_id;
});
}
if ( $order == 'oldest' ) {
uasort($product_categories, function($a, $b) {
return $a->term_id - $b->term_id;
});
}
if ( $order == 'most-products' ) {
uasort($product_categories, function($a, $b) {
return $b->count - $a->count;
});
}
if ( $order == 'least-products' ) {
uasort($product_categories, function($a, $b) {
return $a->count - $b->count;
});
}
foreach( $product_categories as $category ) {
if ( $loop_count >= $count ) {
break;
}
// Skip if subcategories off and category is a subcategory
if ( $subcategories != 'yes' && !empty( $category->parent ) ) {
continue;
}
$link = get_term_link( $category->term_id, 'product_cat' );
$category_html .= '- ';
if ( get_theme_mod( 'homepage_categories_thumbnail' ) != 'no' ) {
$thumbnail_id = get_woocommerce_term_meta( $category->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
if ( $image ) {
$image_size = wc_get_image_size( 'woocommerce_thumbnail' );
$image_width = $image_size['width'];
$image_height = $image_size['height'];
$category_html .= '';
$category_html .= '';
$category_html .= '';
}
}
$category_html .= ''. esc_html( $category->name );
if ( get_theme_mod( 'homepage_categories_product_count' ) != 'no' ) {
$category_html .= ' ('. esc_html( $category->count ) .')';
}
$category_html .= '';
$category_html .= '
';
$loop_count++;
}
echo '';
echo '
'. esc_html( $title ) .'
';
echo '
';
echo $category_html;
echo '
';
echo '
';
}
}
//----------------------------------------------------------------------------------
// Remove "Add to Cart" button
//----------------------------------------------------------------------------------
function ct_modern_store_homepage_remove_add_to_cart() {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
}
add_action( 'woocommerce_after_shop_loop_item', 'ct_modern_store_homepage_remove_add_to_cart', 1 );
//----------------------------------------------------------------------------------
// Edit classes on products on homepage to make styling easier
//----------------------------------------------------------------------------------
function ct_modern_store_edit_homepage_product_classes( $classes ) {
if ( is_page_template( 'templates/homepage.php' ) ) {
// Remove the 'first' and 'last' classes that make custom row styling tough
$classes = array_diff( $classes, array(
array_search( 'first', $classes ) => 'first',
array_search( 'last', $classes ) => 'last'
) );
}
return $classes;
}
add_filter( 'post_class', 'ct_modern_store_edit_homepage_product_classes', 30 );
//----------------------------------------------------------------------------------
// Get and return the order of the homepage sections
//----------------------------------------------------------------------------------
function ct_modern_store_set_homepage_order() {
$homepage_order = get_option( 'ct_modern_store_homepage_order' );
if ( empty( $homepage_order ) ) {
$homepage_order = array(
'modern_store_homepage_featured_products' => 1,
'modern_store_homepage_on_sale_products' => 2,
'modern_store_homepage_categories' => 3,
'modern_store_homepage_top_rated_products' => 4,
'modern_store_homepage_latest_products' => 5
);
update_option( 'ct_modern_store_homepage_order', $homepage_order );
}
return $homepage_order;
}
//----------------------------------------------------------------------------------
// Turn of partial refresh for logo, so title shows up when logo is removed
//----------------------------------------------------------------------------------
function ct_modern_store_update_logo_refresh( $wp_customize ) {
$wp_customize->get_setting( 'custom_logo' )->transport = 'refresh';
}
add_action( 'customize_register', 'ct_modern_store_update_logo_refresh', 20 );
//----------------------------------------------------------------------------------
// Update spacing around logo if there is one
//----------------------------------------------------------------------------------
function ct_modern_store_logo_styles(){
$css = '';
if ( !empty( get_theme_mod( 'custom_logo' ) ) ) {
$css .= '@media all and (min-width: 50em) {
.title-container {
margin: 0.75em 3em 0.75em 0;
}
.rtl .title-container {
margin: 0.75em 0 0.75em 3em;
}
}';
}
if ( !empty( $css ) ) {
$css = ct_modern_store_sanitize_css($css);
wp_add_inline_style( 'ct-modern-store-style', $css );
}
}
add_action( 'wp_enqueue_scripts', 'ct_modern_store_logo_styles', 20 );
//----------------------------------------------------------------------------------
// Filter product images on the homepage to use product page image size
// They can display up to 588px wide and the WC default single image size is 600px
//----------------------------------------------------------------------------------
function ct_modern_store_homepage_image_size($size) {
if ( is_page_template( 'templates/homepage.php' ) ) {
return 'homepage-thumb';
} else {
return $size;
}
}
add_filter( 'single_product_archive_thumbnail_size', 'ct_modern_store_homepage_image_size' );