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'
Return Return
(array)
Source Source
File: includes/class.llms.voucher.php
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;
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 3.24.0 | Unknown. |
| 2.0.0 | Introduced. |