ID, '_addoshvi_video_attachment_id', true ); $video_url = $video_id ? wp_get_attachment_url( $video_id ) : ''; ?>
[addoshvi_feed layout="carousel"]
[addoshvi_feed layout="inline" ids="ID ); ?>"]
$label ) {
$new[ $key ] = $label;
if ( 'title' === $key ) {
$new['addoshvi_thumb'] = __( 'Preview', 'addonn-shoppable-video' );
$new['addoshvi_products'] = __( 'Products', 'addonn-shoppable-video' );
$new['addoshvi_stats'] = __( 'Views / Add-to-cart', 'addonn-shoppable-video' );
}
}
return $new;
}
public function render_columns( $column, $post_id ) {
if ( 'addoshvi_thumb' === $column ) {
if ( has_post_thumbnail( $post_id ) ) {
echo get_the_post_thumbnail( $post_id, array( 50, 70 ) );
} else {
echo '—';
}
}
if ( 'addoshvi_products' === $column ) {
$linked = get_post_meta( $post_id, '_addoshvi_products', true );
$linked = is_array( $linked ) ? $linked : array();
$names = array();
foreach ( $linked as $pid ) {
$p = wc_get_product( $pid );
if ( $p ) {
$names[] = $p->get_name();
}
}
echo esc_html( $names ? implode( ', ', $names ) : '—' );
}
if ( 'addoshvi_stats' === $column ) {
$views = (int) get_post_meta( $post_id, '_addoshvi_view_count', true );
$carts = (int) get_post_meta( $post_id, '_addoshvi_cart_count', true );
echo esc_html( sprintf( '%d / %d', $views, $carts ) );
}
}
/**
* AJAX: live product search for the meta box.
*/
public function ajax_search_products() {
check_ajax_referer( 'addoshvi_product_search', 'nonce' );
if ( ! current_user_can( 'edit_posts' ) ) {
wp_send_json_error();
}
$term = isset( $_GET['term'] ) ? sanitize_text_field( wp_unslash( $_GET['term'] ) ) : '';
$query = new WP_Query( array(
'post_type' => 'product',
'post_status' => 'publish',
's' => $term,
'posts_per_page' => 15,
) );
$results = array();
foreach ( $query->posts as $p ) {
$product = wc_get_product( $p->ID );
if ( ! $product ) {
continue;
}
$results[] = array(
'id' => $product->get_id(),
'name' => $product->get_name(),
'price' => $product->get_price_html(),
);
}
wp_send_json_success( $results );
}
public function add_shortcode_helper_notice() {
// Reserved for future onboarding notice.
}
}