action_string( self::DISMISS_SELLING_NOTICE ), array( $this, 'action_dismiss_selling_notice' ) ); } if ( ! WooCommerceInterface::is_selling_enabled() ) { return; } add_filter( 'product_type_selector', array( $this, 'product_type_selector' ) ); add_filter( 'woocommerce_product_data_tabs', array( $this, 'product_data_tabs' ) ); add_action( 'woocommerce_product_data_panels', array( $this, 'product_data_panel' ) ); add_action( 'woocommerce_admin_process_product_object', array( $this, 'process_product_object' ) ); add_action( 'admin_footer', array( $this, 'product_type_scripts' ) ); add_action( 'edit_form_after_title', array( $this, 'purchased_ad_notice' ) ); } /** * Display a dismissible notice suggesting to enable ad selling. * * @return void */ public function enable_selling_notice() { if ( ! current_user_can( 'manage_options' ) || Util::truthy( Options::instance()->get( 'woo_selling_notice_dismissed' ) ) ) { return; } ?>

', '' ); ?>

nonce_string( self::DISMISS_SELLING_NOTICE ), 'security' ); if ( ! current_user_can( 'manage_options' ) ) { wp_die(); } Options::instance()->update( 'woo_selling_notice_dismissed', 1 ); wp_send_json_success( array( 'action' => self::DISMISS_SELLING_NOTICE, ) ); } /** * Add the ad product type to the WooCommerce product type dropdown. * * @param array $types The current product types. * * @return array */ public function product_type_selector( $types ) { $types[ WooCommerceInterface::product_type() ] = __( 'Ad (Ad Commander)', 'ad-commander' ); return $types; } /** * Add the Ad Product Settings tab to the WooCommerce product data tabs. * * @param array $tabs The current product data tabs. * * @return array */ public function product_data_tabs( $tabs ) { $product_type = WooCommerceInterface::product_type(); /** * Mimic a virtual simple product: hide shipping, allow inventory (e.g., to limit available ad slots). */ if ( isset( $tabs['shipping'] ) ) { $tabs['shipping']['class'][] = 'hide_if_' . $product_type; } if ( isset( $tabs['inventory'] ) ) { $tabs['inventory']['class'][] = 'show_if_' . $product_type; } $tabs['adcmdr_ad_settings'] = array( 'label' => __( 'Ad Product Settings', 'ad-commander' ), 'target' => 'adcmdr_ad_settings_panel', 'class' => array( 'show_if_' . $product_type ), 'priority' => 15, ); return $tabs; } /** * Render the Ad Product Settings panel. * * @return void */ public function product_data_panel() { global $product_object; $keys = WooCommerceInterface::product_meta_keys(); ?> get_type() !== WooCommerceInterface::product_type() ) { return; } $keys = WooCommerceInterface::product_meta_keys(); // phpcs:disable WordPress.Security.NonceVerification.Missing -- Nonce verified by WooCommerce. $adtype = isset( $_POST[ $keys['adtype'] ] ) ? sanitize_key( wp_unslash( $_POST[ $keys['adtype'] ] ) ) : ''; if ( ! array_key_exists( $adtype, WooCommerceInterface::sellable_ad_types() ) ) { $sellable = array_keys( WooCommerceInterface::sellable_ad_types() ); $adtype = ! empty( $sellable ) ? $sellable[0] : ''; } $product->update_meta_data( $keys['adtype'], $adtype ); // phpcs:enable WordPress.Security.NonceVerification.Missing } /** * Toggle ad product fields on the product edit screen. * * @return void */ public function product_type_scripts() { $screen = get_current_screen(); if ( ! $screen || $screen->id !== 'product' ) { return; } ?> post_type !== AdCommander::posttype_ad() ) { return; } $wo_meta = new WOMeta( AdCommander::ns() ); $order_id = absint( get_post_meta( $post->ID, $wo_meta->make_key( 'woo_order_id' ), true ) ); if ( ! $order_id ) { return; } $order = wc_get_order( $order_id ); if ( ! $order ) { return; } $customer = $order->get_user(); ?>

get_edit_order_url() ) . '">#' . esc_html( $order->get_order_number() ) . '', esc_html( $customer ? $customer->display_name : $order->get_formatted_billing_full_name() ) ); ?>