control_groups['settings'] = [ 'title' => esc_html__( 'Settings', 'wpfnl' ), 'tab' => 'content', ]; $this->control_groups['style'] = [ 'title' => esc_html__( 'Style', 'wpfnl' ), 'tab' => 'content', ]; } /** * Set element controls */ public function set_controls() { // Settings $this->controls['offerAction'] = [ 'tab' => 'content', 'group' => 'settings', 'label' => esc_html__( 'Button Action', 'wpfnl' ), 'type' => 'select', 'options' => [ 'accept' => esc_html__( 'Accept Offer', 'wpfnl' ), 'reject' => esc_html__( 'Reject Offer', 'wpfnl' ), ], 'inline' => true, 'default' => 'accept', ]; $this->controls['buttonText'] = [ 'tab' => 'content', 'group' => 'settings', 'label' => esc_html__( 'Button Text', 'wpfnl' ), 'type' => 'text', 'default' => esc_html__( 'Yes, Add to My Order!', 'wpfnl' ), ]; $this->controls['showProductPrice'] = [ 'tab' => 'content', 'group' => 'settings', 'label' => esc_html__( 'Show Product Price', 'wpfnl' ), 'type' => 'select', 'options' => [ 'no' => esc_html__( 'No', 'wpfnl' ), 'yes' => esc_html__( 'Yes', 'wpfnl' ), ], 'inline' => true, 'default' => 'no', 'required' => [ 'offerAction', '=', 'accept' ], ]; $this->controls['buttonAlign'] = [ 'tab' => 'content', 'group' => 'settings', 'label' => esc_html__( 'Button Alignment', 'wpfnl' ), 'type' => 'select', 'options' => [ 'left' => esc_html__( 'Left', 'wpfnl' ), 'center' => esc_html__( 'Center', 'wpfnl' ), 'right' => esc_html__( 'Right', 'wpfnl' ), ], 'inline' => true, 'default' => 'left', ]; } /** * Render element */ public function render() { $settings = $this->settings; $offer_action = isset( $settings['offerAction'] ) ? $settings['offerAction'] : 'accept'; $button_text = isset( $settings['buttonText'] ) ? $settings['buttonText'] : __( 'Yes, Add to My Order!', 'wpfnl' ); $show_price = isset( $settings['showProductPrice'] ) ? $settings['showProductPrice'] : 'no'; $button_align = isset( $settings['buttonAlign'] ) ? $settings['buttonAlign'] : 'left'; // Get offer button type from settings or URL $offer_button_type = isset( $settings['offerType'] ) ? $settings['offerType'] : 'upsell'; $this->set_attribute( '_root', 'class', 'wp-block-wpfnl-offer-btn-' . esc_attr( $button_align ) ); // Get product data $response = \WPFunnels\Wpfnl_functions::get_product_data_for_widget( get_the_ID() ); $offer_product = isset($response['offer_product']) && $response['offer_product'] ? $response['offer_product'] : ''; $get_product_type = isset($response['get_product_type']) && $response['get_product_type'] ? $response['get_product_type'] : ''; echo "