' . 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 = '
';
}
);
/**
* [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 .= '
';
}
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 = '';
}
);