id ) { wp_enqueue_script( 'wcf-product-page-setting', CARTFLOWS_URL . 'admin/assets/js/product-page.js', array( 'jquery' ), CARTFLOWS_VER, true ); } } /** * Add CartFlows tab. * * @param array $tabs tabs. */ public function add_tab( $tabs ) { $tabs['cartflows'] = array( 'label' => __( 'CartFlows', 'cartflows' ), 'target' => 'cartflows_product_data', 'class' => array(), 'priority' => 80, ); return $tabs; } /** * Function to search coupons. */ public function json_search_flows() { if ( ! current_user_can( 'cartflows_manage_flows_steps' ) ) { wp_send_json_error( array( 'message' => __( 'Permission denied.', 'cartflows' ) ) ); } if ( isset( $_POST['security'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['security'] ) ), 'wcf_json_search_flows' ) ) { global $wpdb; $term = isset( $_POST['term'] ) ? (string) urldecode( sanitize_text_field( wp_unslash( $_POST['term'] ) ) ) : ''; if ( empty( $term ) ) { die(); } $posts = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE post_type = %s AND post_title LIKE %s AND post_status = %s", CARTFLOWS_FLOW_POST_TYPE, $wpdb->esc_like( $term ) . '%', 'publish' ) ); // db call ok; no-cache ok. $flows_found = array(); if ( $posts ) { foreach ( $posts as $post ) { $flows_found[ $post->ID ] = get_the_title( $post->ID ); } } wp_send_json( $flows_found ); } } /** * Tab content. */ public function add_tab_content() { echo '
'; } /** * Woocommerce Select2 field. * * @param array $field field data. */ public function woocommerce_select2( $field ) { global $woocommerce; echo ''; if ( ! empty( $field['description'] ) ) { echo '' . wp_kses_post( $field['description'] ) . ''; } echo ''; echo '
'; } /** * Save product meta. * * @param int $post_id product id. */ public function save_product_meta( $post_id ) { $product = wc_get_product( $post_id ); // Calling this function on WooCommerce action. So no need for nonce verification. $next_step = isset( $_POST['cartflows_redirect_flow_id'] ) ? intval( $_POST['cartflows_redirect_flow_id'] ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing $add_to_cart_text = isset( $_POST['cartflows_add_to_cart_text'] ) ? sanitize_text_field( $_POST['cartflows_add_to_cart_text'] ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing $product->update_meta_data( 'cartflows_redirect_flow_id', $next_step ); $product->update_meta_data( 'cartflows_add_to_cart_text', $add_to_cart_text ); $product->save(); } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Wd_Flow_Product_Meta::get_instance();