0 ), $atts, 'xpay-buy' ); if ( ! get_option( 'xpay_wc_widget_enabled', 0 ) ) { return ''; } $product_id = (int) $atts['product_id']; if ( ! $product_id ) { $product_id = (int) get_the_ID(); } return $this->render( $product_id ); } public function register_block() { if ( ! function_exists( 'register_block_type' ) ) { return; } register_block_type( 'xpay/buy-in-ai-chat', array( 'render_callback' => array( $this, 'render_block' ), 'attributes' => array( 'productId' => array( 'type' => 'number', 'default' => 0, ), ), ) ); } public function render_block( $attrs ) { $id = isset( $attrs['productId'] ) ? (int) $attrs['productId'] : (int) get_the_ID(); return $this->render( $id ); } private function render( $product_id ) { if ( ! $product_id || ! function_exists( 'wc_get_product' ) ) { return ''; } $product = wc_get_product( $product_id ); if ( ! $product ) { return ''; } $name = wp_strip_all_tags( $product->get_name() ); $q = rawurlencode( sprintf( 'Buy "%s" from %s', $name, get_bloginfo( 'name' ) ) ); $buttons = array( 'ChatGPT' => 'https://chat.openai.com/?q=' . $q, 'Claude' => 'https://claude.ai/new?q=' . $q, 'Perplexity' => 'https://www.perplexity.ai/search?q=' . $q, 'Gemini' => 'https://gemini.google.com/app?q=' . $q, ); $out = '
'; return $out; } }