get( 'enable_woo_selling', 'selling', true ); } /** * Check if the Pro selling features are available. * Per-day pricing, banner constraints, and customer ad management require a compatible version of Pro. * * @return bool */ public static function is_pro_selling_available() { return ProBridge::instance()->pro_feature_check( 'selfserveads' ); } /** * Check if purchasers can create and modify their own ads. * Requires the selling and purchaser management settings, and a compatible version of Pro. * * @return bool */ public static function is_purchaser_management_enabled() { return self::is_selling_enabled() && Options::instance()->get( 'woo_purchaser_management', 'selling', true ) && self::is_pro_selling_available(); } /** * The namespaced WooCommerce product type for ads. * * @return string */ public static function product_type() { return AdCommander::ns() . '_ad'; } /** * Ad types that can be sold as WooCommerce products. * * Labels are always sourced from AdPostMeta::ad_types(). Unknown keys are dropped. * * @return array */ public static function sellable_ad_types() { /** * Filter the ad type keys that are available for purchase. * * @param array $ad_type_keys The sellable ad type keys. */ $sellable = apply_filters( 'adcmdr_woo_sellable_ad_types', array( 'bannerad', 'richcontent' ) ); $sellable = array_map( 'sanitize_key', Util::arrayify( $sellable ) ); return array_intersect_key( AdPostMeta::ad_types(), array_flip( $sellable ) ); } /** * The default maximum banner upload file size, in KB. * * @return int */ public static function default_max_filesize_kb() { return 1024; } /** * The maximum file size (in KB) for images uploaded by ad purchasers. * Applies to customer uploads only; administrators are not restricted. * * @return int The maximum size in KB, or 0 for no plugin-imposed limit. */ public static function max_upload_filesize_kb() { $max_kb = Options::instance()->get( 'woo_max_filesize_kb', 'selling' ); if ( $max_kb === null || $max_kb === '' ) { return self::default_max_filesize_kb(); } return absint( $max_kb ); } /** * The WooCommerce product meta keys used by ad products. * * These are stored on the WooCommerce product, not on an ad post, * so they are managed with the product CRUD instead of WOMeta. * * @return array */ public static function product_meta_keys() { return array( 'adtype' => '_adcmdr_product_adtype', ); } /** * Get a single ad product meta key. * * @param string $key The short key. * * @return string|null */ public static function product_meta_key( $key ) { $keys = self::product_meta_keys(); return isset( $keys[ $key ] ) ? $keys[ $key ] : null; } /** * The WooCommerce order item meta keys used by purchased ad products. * * @return array */ public static function order_item_meta_keys() { return array( 'ad_product' => '_adcmdr_ad_product', 'adtype' => '_adcmdr_adtype', ); } /** * Get a single order item meta key. * * @param string $key The short key. * * @return string|null */ public static function order_item_meta_key( $key ) { $keys = self::order_item_meta_keys(); return isset( $keys[ $key ] ) ? $keys[ $key ] : null; } /** * Get an ad product setting from a WooCommerce product. * * @param \WC_Product $product The WooCommerce product. * @param string $key The short meta key. * @param mixed $default_value The default value if none is saved. * * @return mixed */ public static function get_product_setting( $product, $key, $default_value = null ) { $meta_key = self::product_meta_key( $key ); if ( ! $meta_key ) { return $default_value; } $value = $product->get_meta( $meta_key, true ); return ( $value === '' || $value === null ) ? $default_value : $value; } /** * Order statuses during which a purchased ad can be created and managed. * * @return array */ public static function ad_order_statuses() { /** * Filter the order statuses during which a purchased ad can be created and managed. * * @param array $statuses The order statuses (unprefixed). */ return apply_filters( 'adcmdr_woo_ad_order_statuses', array( 'on-hold', 'processing', 'completed' ) ); } /** * Determine if a WooCommerce order item is a purchased ad product. * * @param \WC_Order_Item $item The WooCommerce order item. * * @return bool */ public static function is_ad_order_item( $item ) { if ( ! $item instanceof \WC_Order_Item_Product ) { return false; } return Util::truthy( $item->get_meta( self::order_item_meta_key( 'ad_product' ), true ) ); } }