' . esc_html( gstore_email() ) . ''; } ); /** * [gstore_link page="slug" text="..."] Enlace a una página o a la tienda/cuenta. */ add_shortcode( 'gstore_link', function ( $atts ) { $atts = shortcode_atts( array( 'page' => 'shop', 'text' => gstore_t( 'home_more' ), 'class' => 'gmk-btn' ), $atts ); if ( in_array( $atts['page'], array( 'shop', 'myaccount', 'cart' ), true ) && function_exists( 'wc_get_page_permalink' ) ) { $url = wc_get_page_permalink( $atts['page'] ); } elseif ( 0 === strpos( $atts['page'], 'cat:' ) ) { $term = get_term_by( 'slug', substr( $atts['page'], 4 ), 'product_cat' ); $url = $term ? get_term_link( $term ) : home_url( '/' ); } else { $url = gstore_page_url( $atts['page'] ); } return '' . esc_html( $atts['text'] ) . ''; } ); /** * [gstore_categories] Rejilla de categorías con imagen. */ add_shortcode( 'gstore_categories', function () { $out = '
'; foreach ( gstore_product_cats() as $term ) { $img = (int) get_term_meta( $term->term_id, 'thumbnail_id', true ); $out .= ''; $out .= '' . ( $img ? gstore_shortcodes_kses( wp_get_attachment_image( $img, 'woocommerce_thumbnail' ) ) : '' ) . ''; $out .= '' . esc_html( $term->name ) . ''; $out .= '' . wp_kses_post( str_replace( '%d', '' . (int) $term->count . '', esc_html( 1 === (int) $term->count ? gstore_t( 'home_count_one' ) : gstore_t( 'home_count_many' ) ) ) ) . ''; } return $out . '
'; } ); /** * [gstore_tiles cats="slug1,slug2,slug3,slug4"] Tarjetas estilo marketplace: 4 productos por categoría. */ add_shortcode( 'gstore_tiles', function ( $atts ) { if ( ! function_exists( 'wc_get_products' ) ) { return ''; } $atts = shortcode_atts( array( 'cats' => '' ), $atts ); $out = '
'; foreach ( array_filter( array_map( 'trim', explode( ',', $atts['cats'] ) ) ) as $slug ) { $term = get_term_by( 'slug', $slug, 'product_cat' ); if ( ! $term ) { continue; } $products = wc_get_products( array( 'category' => array( $slug ), 'limit' => 4, 'status' => 'publish', 'orderby' => 'rand' ) ); $out .= '

' . esc_html( $term->name ) . '

' . esc_html( gstore_t( 'home_tile_more' ) . ' ' . $term->name ) . '
'; } return $out . '
'; } ); /** * [gstore_row title="..." cat="slug" type="featured|sale|new" limit="10" link="url opcional"] Fila de productos con desplazamiento horizontal. */ add_shortcode( 'gstore_row', function ( $atts ) { if ( ! function_exists( 'wc_get_products' ) ) { return ''; } $atts = shortcode_atts( array( 'title' => '', 'cat' => '', 'type' => 'new', 'limit' => 10, 'link' => '' ), $atts ); $args = array( 'limit' => (int) $atts['limit'], 'status' => 'publish', 'visibility' => 'catalog' ); if ( $atts['cat'] ) { $args['category'] = array( $atts['cat'] ); } if ( 'featured' === $atts['type'] ) { $args['featured'] = true; } elseif ( 'sale' === $atts['type'] ) { $args['include'] = wc_get_product_ids_on_sale() ? wc_get_product_ids_on_sale() : array( 0 ); } else { $args['orderby'] = 'date'; } $products = wc_get_products( $args ); if ( ! $products ) { return ''; } $more = ''; if ( $atts['cat'] ) { $term = get_term_by( 'slug', $atts['cat'], 'product_cat' ); $more = $term ? get_term_link( $term ) : ''; } elseif ( 'sale' === $atts['type'] ) { $more = add_query_arg( 'on_sale', 1, wc_get_page_permalink( 'shop' ) ); } else { $more = wc_get_page_permalink( 'shop' ); } if ( $atts['link'] ) { $more = $atts['link']; } $out = '

' . esc_html( $atts['title'] ) . '

' . esc_html( gstore_t( 'home_more' ) ) . '
'; foreach ( $products as $product ) { $out .= ''; $out .= '' . gstore_shortcodes_kses( $product->get_image( 'woocommerce_thumbnail' ) ) . ( $product->is_on_sale() ? '' . esc_html( gstore_t( 'sale_badge' ) ) . '' : '' ) . ''; $out .= '' . esc_html( $product->get_name() ) . ''; $out .= '' . gstore_shortcodes_kses( $product->get_price_html() ) . ''; } return $out . '
'; } );