LLMS_Voucher::get_products( string $post_type = 'any' )

Get an array of IDs for products associated with this voucher


Parameters Parameters

$post_type

(string) (Optional) Allows filtering of products by post type.

Default value: 'any'


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/class.llms.voucher.php

447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
public function get_products( $post_type = 'any' ) {
 
    global $wpdb;
 
    $table = $this->get_product_to_voucher_table_name();
 
    $products = $wpdb->get_col( $wpdb->prepare( "SELECT product_id FROM {$table} WHERE `voucher_id` = %d;", $this->id ) ); //phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
 
    if ( ! empty( $products ) ) {
 
        // Filter any products that don't match the supplied post type.
        if ( 'any' !== $post_type ) {
            foreach ( $products as $i => $id ) {
                if ( get_post_type( $id ) !== $post_type ) {
                    unset( $products[ $i ] );
                }
            }
        }
 
        // Convert all elements to ints.
        $products = array_map( 'intval', $products );
 
    }
 
    return $products;
}


Top ↑

Changelog Changelog

Changelog
Version Description
3.24.0 Unknown.
2.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.