Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rickalday/4cab3b9188ef2b88d25c8ac2df668381 to your computer and use it in GitHub Desktop.
Save rickalday/4cab3b9188ef2b88d25c8ac2df668381 to your computer and use it in GitHub Desktop.
//My custom Sell Media Loop
function my_sell_media_content_loop( $post_id, $i ){
$class = apply_filters( 'sell_media_grid_item_class', 'sell-media-grid-item', $post_id );
if ( ! sell_media_has_multiple_attachments( $post_id ) )
$class .= ' sell-media-grid-single-item';
$html = '<div id="sell-media-' . $post_id . '" class="' . $class . '">';
$parent = false;
if( !is_archive() ){
// if there is a post parent, change link to gallery
$parent = sell_media_attachment_parent_post( $post_id );
}
if ( $parent ) {
$link = add_query_arg( array(
'id' => $post_id
), get_permalink( $parent->ID ) );
$post_id = $parent->ID;
} else {
$link = get_permalink( $post_id );
}
$html .= '<a href="' . esc_url( $link ) . '" ' . sell_media_link_attributes( $post_id ) . ' class="sell-media-item">';
$html .= sell_media_item_icon( $post_id, apply_filters( 'sell_media_thumbnail', 'medium' ), false );
if ( ! sell_media_has_multiple_attachments( $post_id ) ) {
$attachment_id = sell_media_get_attachment_id( $post_id );
$html .= '<div class="sell-media-quick-view-disabled" data-product-id="' . esc_attr( $post_id ) . '" data-attachment-id="' . esc_attr( $attachment_id ) . '">' . apply_filters( 'sell_media_quick_view_text', __( 'Quick View', 'sell_media' ), $post_id, $attachment_id ) . '</div>';
}
else {
$html .= '<div class="sell-media-view-gallery">' . apply_filters( 'sell_media_view_gallery_text', __( 'View Gallery', 'sell_media' ) ) . '</div>';
}
$html .= '</a>';
$html .= '</div>';
return $html;
}
add_filter( 'sell_media_content_loop', 'my_sell_media_content_loop', 9, 2 );
//Replace Quick View text
function sell_media_custom_view_text(){
global $post;
$free_download_meta = get_post_meta( $post->ID, 'sell_media_free_downloads', true );
if ( ! empty ( $free_download_meta ) ) {
$title = "Download";
} else {
$title = "Buy";
}
return $title;
}
add_filter( 'sell_media_quick_view_text', 'sell_media_custom_view_text' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment