| 1 |
<?php |
| 2 |
/** |
| 3 |
* CartFlows Learn Data Query. |
| 4 |
* |
| 5 |
* @package CartFlows |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace CartflowsAdmin\AdminCore\Api; |
| 9 |
|
| 10 |
// Exit if accessed directly. |
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; |
| 13 |
} |
| 14 |
|
| 15 |
use CartflowsAdmin\AdminCore\Api\ApiBase; |
| 16 |
|
| 17 |
/** |
| 18 |
* Class Learn. |
| 19 |
*/ |
| 20 |
class Learn extends ApiBase { |
| 21 |
|
| 22 |
/** |
| 23 |
* Route base. |
| 24 |
* |
| 25 |
* @var string |
| 26 |
*/ |
| 27 |
protected $rest_base = '/admin/learn/'; |
| 28 |
|
| 29 |
/** |
| 30 |
* Instance |
| 31 |
* |
| 32 |
* @access private |
| 33 |
* @var object Class object. |
| 34 |
* @since 2.2.2 |
| 35 |
*/ |
| 36 |
private static $instance; |
| 37 |
|
| 38 |
/** |
| 39 |
* Initiator |
| 40 |
* |
| 41 |
* @since 2.2.2 |
| 42 |
* @return object initialized object of class. |
| 43 |
*/ |
| 44 |
public static function get_instance() { |
| 45 |
if ( ! isset( self::$instance ) ) { |
| 46 |
self::$instance = new self(); |
| 47 |
} |
| 48 |
return self::$instance; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Init Hooks. |
| 53 |
* |
| 54 |
* @since 1.0.0 |
| 55 |
* @return void |
| 56 |
*/ |
| 57 |
public function register_routes() { |
| 58 |
|
| 59 |
$namespace = $this->get_api_namespace(); |
| 60 |
|
| 61 |
register_rest_route( |
| 62 |
$namespace, |
| 63 |
$this->rest_base, |
| 64 |
array( |
| 65 |
array( |
| 66 |
'methods' => \WP_REST_Server::READABLE, |
| 67 |
'callback' => array( $this, 'get_learn_sections' ), |
| 68 |
'permission_callback' => array( $this, 'get_items_permissions_check' ), |
| 69 |
'args' => array(), |
| 70 |
), |
| 71 |
) |
| 72 |
); |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
/** |
| 77 |
* Get learn sections. |
| 78 |
* |
| 79 |
* @param WP_REST_Request $request Full details about the request. |
| 80 |
* @return \WP_REST_Response |
| 81 |
*/ |
| 82 |
public function get_learn_sections( $request ) { |
| 83 |
|
| 84 |
// Resolved completion state — manual checks plus auto-derived state. |
| 85 |
$learn_progress = \Cartflows_Learn_Progress::get_instance(); |
| 86 |
|
| 87 |
$sections = array( |
| 88 |
array( |
| 89 |
'id' => 'funnel-basics', |
| 90 |
'title' => __( 'Funnel Basics', 'cartflows' ), |
| 91 |
'description' => __( 'Build a solid foundation for your first funnel.', 'cartflows' ), |
| 92 |
'modules' => array( |
| 93 |
array( |
| 94 |
'id' => 'install-woocommerce', |
| 95 |
'title' => __( 'Install WooCommerce', 'cartflows' ), |
| 96 |
'description' => __( 'Install WooCommerce to enable products, checkout, and payments.', 'cartflows' ), |
| 97 |
'cta' => __( 'WooCommerce', 'cartflows' ), |
| 98 |
'action' => 'Installs WooCommerce Instantly', |
| 99 |
'action_type' => 'install_plugin', |
| 100 |
'action_data' => array( |
| 101 |
'plugin_slug' => 'woocommerce', |
| 102 |
'plugin_init' => 'woocommerce/woocommerce.php', |
| 103 |
), |
| 104 |
'learn_how' => false, |
| 105 |
'is_pro' => false, |
| 106 |
'completed' => $learn_progress->is_completed( 'install-woocommerce' ), |
| 107 |
'plugin_status' => \Cartflows_Helper::get_plugin_status( 'woocommerce/woocommerce.php', true ), |
| 108 |
), |
| 109 |
array( |
| 110 |
'id' => 'create-your-first-funnel', |
| 111 |
'title' => __( 'Create Your First Funnel', 'cartflows' ), |
| 112 |
'description' => __( 'Start by creating a funnel and selecting a ready-made template.', 'cartflows' ), |
| 113 |
'cta' => __( 'Create Funnel', 'cartflows' ), |
| 114 |
'action' => 'Redirects to Funnel Templates Library', |
| 115 |
'action_type' => 'redirect', |
| 116 |
'action_data' => array( |
| 117 |
'url' => admin_url( 'admin.php?page=cartflows&path=flows' ), |
| 118 |
), |
| 119 |
'learn_how' => esc_url( \Cartflows_Helper::get_kb_doc_link( 'https://cartflows.com/docs/how-to-create-your-first-cartflows-funnel/', array( 'utm_campaign' => 'learn_how' ) ) ), |
| 120 |
'is_pro' => false, |
| 121 |
'completed' => $learn_progress->is_completed( 'create-your-first-funnel' ), |
| 122 |
), |
| 123 |
), |
| 124 |
), |
| 125 |
array( |
| 126 |
'id' => 'design-customize-pages', |
| 127 |
'title' => __( 'Design & Customize Pages', 'cartflows' ), |
| 128 |
'description' => __( 'Make your funnel pages match your brand and goals.', 'cartflows' ), |
| 129 |
'modules' => array( |
| 130 |
array( |
| 131 |
'id' => 'edit-design-funnel-pages-steps', |
| 132 |
'title' => __( 'Edit & Design Funnel Pages/Steps', 'cartflows' ), |
| 133 |
'description' => __( 'Customize your landing, checkout, and thank you pages using your preferred page builder.', 'cartflows' ), |
| 134 |
'cta' => __( 'Edit Steps', 'cartflows' ), |
| 135 |
'action' => 'Redirects to Funnel Editor', |
| 136 |
'action_type' => 'redirect', |
| 137 |
'action_data' => array( |
| 138 |
'url' => admin_url( 'admin.php?page=cartflows&path=flows' ), |
| 139 |
), |
| 140 |
'learn_how' => esc_url( \Cartflows_Helper::get_kb_doc_link( 'https://cartflows.com/docs/editing-and-customising-funnel-steps/', array( 'utm_campaign' => 'learn_how' ) ) ), |
| 141 |
'is_pro' => false, |
| 142 |
'completed' => $learn_progress->is_completed( 'edit-design-funnel-pages-steps' ), |
| 143 |
), |
| 144 |
), |
| 145 |
), |
| 146 |
array( |
| 147 |
'id' => 'setup-products', |
| 148 |
'title' => __( 'Setup Products', 'cartflows' ), |
| 149 |
'description' => __( 'Add and manage the products you\'ll sell through your funnels.', 'cartflows' ), |
| 150 |
'modules' => array( |
| 151 |
array( |
| 152 |
'id' => 'add-products', |
| 153 |
'title' => __( 'Add Products', 'cartflows' ), |
| 154 |
'description' => __( 'Create or import products to use in your CartFlows funnel.', 'cartflows' ), |
| 155 |
'cta' => __( 'Add Products', 'cartflows' ), |
| 156 |
'action' => 'Redirects to WooCommerce > Products', |
| 157 |
'action_type' => 'redirect', |
| 158 |
'action_data' => array( |
| 159 |
'url' => admin_url( 'edit.php?post_type=product' ), |
| 160 |
), |
| 161 |
'learn_how' => esc_url( \Cartflows_Helper::get_kb_doc_link( 'https://cartflows.com/docs/how-to-add-products-in-woocommerce/', array( 'utm_campaign' => 'learn_how' ) ) ), |
| 162 |
'is_pro' => false, |
| 163 |
'completed' => $learn_progress->is_completed( 'add-products' ), |
| 164 |
), |
| 165 |
array( |
| 166 |
'id' => 'assign-products-to-checkout', |
| 167 |
'title' => __( 'Assign Products to Checkout', 'cartflows' ), |
| 168 |
'description' => __( 'Attach products to your checkout step and control pricing & quantity.', 'cartflows' ), |
| 169 |
'cta' => __( 'Select Products', 'cartflows' ), |
| 170 |
'action' => 'Redirects to Funnel > Checkout Step > Products', |
| 171 |
'action_type' => 'redirect', |
| 172 |
'action_data' => array( |
| 173 |
'url' => admin_url( 'admin.php?page=cartflows&path=flows' ), |
| 174 |
), |
| 175 |
'learn_how' => esc_url( \Cartflows_Helper::get_kb_doc_link( 'https://cartflows.com/docs/how-to-add-assign-products-to-a-checkout-step-in-cartflows/', array( 'utm_campaign' => 'learn_how' ) ) ), |
| 176 |
'is_pro' => false, |
| 177 |
'completed' => $learn_progress->is_completed( 'assign-products-to-checkout' ), |
| 178 |
), |
| 179 |
), |
| 180 |
), |
| 181 |
array( |
| 182 |
'id' => 'setup-payments', |
| 183 |
'title' => __( 'Setup Payments', 'cartflows' ), |
| 184 |
'description' => __( 'Accept payments securely with your preferred gateways.', 'cartflows' ), |
| 185 |
'modules' => array( |
| 186 |
array( |
| 187 |
'id' => 'connect-payment-gateway', |
| 188 |
'title' => __( 'Connect Payment Gateway', 'cartflows' ), |
| 189 |
'description' => __( 'Set up Stripe, PayPal, or other WooCommerce-supported payment methods.', 'cartflows' ), |
| 190 |
'cta' => __( 'Setup Payments', 'cartflows' ), |
| 191 |
'action' => 'Redirects to WooCommerce > Payments', |
| 192 |
'action_type' => 'redirect', |
| 193 |
'action_data' => array( |
| 194 |
'url' => admin_url( 'admin.php?page=wc-settings&tab=checkout' ), |
| 195 |
), |
| 196 |
'learn_how' => false, |
| 197 |
'is_pro' => false, |
| 198 |
'completed' => $learn_progress->is_completed( 'connect-payment-gateway' ), |
| 199 |
), |
| 200 |
), |
| 201 |
), |
| 202 |
array( |
| 203 |
'id' => 'setup-cart-abandonment-recovery', |
| 204 |
'title' => __( 'Setup Cart Abandonment Recovery', 'cartflows' ), |
| 205 |
'description' => __( 'Recover lost revenue from incomplete checkouts.', 'cartflows' ), |
| 206 |
'modules' => array( |
| 207 |
array( |
| 208 |
'id' => 'enable-cart-abandonment-tracking', |
| 209 |
'title' => __( 'Enable Cart Abandonment Tracking', 'cartflows' ), |
| 210 |
'description' => __( 'Start tracking abandoned carts automatically.', 'cartflows' ), |
| 211 |
'cta' => __( 'Cart Abandonment Recovery', 'cartflows' ), |
| 212 |
'action' => 'Installs CAR Free Instantly', |
| 213 |
'action_type' => 'install_plugin', |
| 214 |
'action_data' => array( |
| 215 |
'plugin_slug' => 'woo-cart-abandonment-recovery', |
| 216 |
'plugin_init' => 'woo-cart-abandonment-recovery/woo-cart-abandonment-recovery.php', |
| 217 |
), |
| 218 |
'learn_how' => false, |
| 219 |
'is_pro' => false, |
| 220 |
'completed' => $learn_progress->is_completed( 'enable-cart-abandonment-tracking' ), |
| 221 |
'plugin_status' => \Cartflows_Helper::get_plugin_status( 'woo-cart-abandonment-recovery/woo-cart-abandonment-recovery.php', true ), |
| 222 |
), |
| 223 |
array( |
| 224 |
'id' => 'setup-recovery-emails', |
| 225 |
'title' => __( 'Setup Recovery Emails', 'cartflows' ), |
| 226 |
'description' => __( 'Edit and setup recovery emails to start recovering lost sales automatically.', 'cartflows' ), |
| 227 |
'cta' => __( 'Setup Emails', 'cartflows' ), |
| 228 |
'action' => 'Redirects to CAR > Follow Ups', |
| 229 |
'action_type' => 'redirect', |
| 230 |
'action_data' => array( |
| 231 |
'url' => admin_url( 'admin.php?page=woo-cart-abandonment-recovery&path=follow-up-templates' ), |
| 232 |
), |
| 233 |
'learn_how' => false, |
| 234 |
'is_pro' => false, |
| 235 |
'completed' => $learn_progress->is_completed( 'setup-recovery-emails' ), |
| 236 |
), |
| 237 |
), |
| 238 |
), |
| 239 |
array( |
| 240 |
'id' => 'modernise-your-cart', |
| 241 |
'title' => __( 'Modernise Your Cart', 'cartflows' ), |
| 242 |
'description' => __( 'Deliver a faster, cleaner, and more conversion-focused cart experience.', 'cartflows' ), |
| 243 |
'modules' => array( |
| 244 |
array( |
| 245 |
'id' => 'enable-modern-cart', |
| 246 |
'title' => __( 'Enable Modern Cart', 'cartflows' ), |
| 247 |
'description' => __( 'Switch to the modern cart layout for better UX and performance.', 'cartflows' ), |
| 248 |
'cta' => __( 'Modern Cart', 'cartflows' ), |
| 249 |
'action' => 'Installs MCW Free Instantly', |
| 250 |
'action_type' => 'install_plugin', |
| 251 |
'action_data' => array( |
| 252 |
'plugin_slug' => 'modern-cart', |
| 253 |
'plugin_init' => 'modern-cart/modern-cart.php', |
| 254 |
), |
| 255 |
'learn_how' => false, |
| 256 |
'is_pro' => false, |
| 257 |
'completed' => $learn_progress->is_completed( 'enable-modern-cart' ), |
| 258 |
'plugin_status' => \Cartflows_Helper::get_plugin_status( 'modern-cart/modern-cart.php', true ), |
| 259 |
), |
| 260 |
array( |
| 261 |
'id' => 'setup-your-cart', |
| 262 |
'title' => __( 'Setup Your Cart', 'cartflows' ), |
| 263 |
'description' => __( 'Set up and customize your cart settings to match your brand style.', 'cartflows' ), |
| 264 |
'cta' => __( 'Setup Cart', 'cartflows' ), |
| 265 |
'action' => 'Redirects to MCW > Settings', |
| 266 |
'action_type' => 'redirect', |
| 267 |
'action_data' => array( |
| 268 |
'url' => admin_url( 'admin.php?page=moderncart_settings' ), |
| 269 |
), |
| 270 |
'learn_how' => false, |
| 271 |
'is_pro' => false, |
| 272 |
'completed' => $learn_progress->is_completed( 'setup-your-cart' ), |
| 273 |
), |
| 274 |
), |
| 275 |
), |
| 276 |
array( |
| 277 |
'id' => 'setup-offers', |
| 278 |
'title' => __( 'Setup Offers', 'cartflows' ), |
| 279 |
'description' => __( 'Increase order value with smart one-click offers.', 'cartflows' ), |
| 280 |
'modules' => array( |
| 281 |
array( |
| 282 |
'id' => 'add-order-bump', |
| 283 |
'title' => __( 'Add Order Bump', 'cartflows' ), |
| 284 |
'description' => __( 'Offer complementary products directly on the checkout page.', 'cartflows' ), |
| 285 |
'cta' => __( 'Add Order Bump', 'cartflows' ), |
| 286 |
'action' => 'Redirects to Funnel > Checkout Step > Order Bump', |
| 287 |
'action_type' => 'redirect', |
| 288 |
'action_data' => array( |
| 289 |
'url' => admin_url( 'admin.php?page=cartflows&path=flows' ), |
| 290 |
), |
| 291 |
'learn_how' => esc_url( \Cartflows_Helper::get_kb_doc_link( 'https://cartflows.com/docs/how-to-add-order-bumps-to-woocommerce-sales-funnel/', array( 'utm_campaign' => 'learn_how' ) ) ), |
| 292 |
'is_pro' => ! _is_cartflows_pro(), |
| 293 |
'completed' => $learn_progress->is_completed( 'add-order-bump' ), |
| 294 |
), |
| 295 |
array( |
| 296 |
'id' => 'setup-upsell-downsell-offers', |
| 297 |
'title' => __( 'Setup Upsell / Downsell Offers', 'cartflows' ), |
| 298 |
'description' => __( 'Create one-click post-checkout offers to boost revenue.', 'cartflows' ), |
| 299 |
'cta' => __( 'Add Offer Step', 'cartflows' ), |
| 300 |
'action' => 'Redirects to Funnel > Checkout Step > Order Bump', |
| 301 |
'action_type' => 'redirect', |
| 302 |
'action_data' => array( |
| 303 |
'url' => admin_url( 'admin.php?page=cartflows&path=flows' ), |
| 304 |
), |
| 305 |
'learn_how' => esc_url( \Cartflows_Helper::get_kb_doc_link( 'https://cartflows.com/docs/how-to-create-one-click-upsell-and-downsell-offers-in-cartflows/', array( 'utm_campaign' => 'learn_how' ) ) ), |
| 306 |
'is_pro' => ! _is_cartflows_pro(), |
| 307 |
'completed' => $learn_progress->is_completed( 'setup-upsell-downsell-offers' ), |
| 308 |
), |
| 309 |
), |
| 310 |
), |
| 311 |
); |
| 312 |
|
| 313 |
$response = new \WP_REST_Response( $sections ); |
| 314 |
$response->set_status( 200 ); |
| 315 |
|
| 316 |
return $response; |
| 317 |
} |
| 318 |
|
| 319 |
/** |
| 320 |
* Check whether a given request has permission to read notes. |
| 321 |
* |
| 322 |
* @param WP_REST_Request $request Full details about the request. |
| 323 |
* @return \WP_Error|boolean |
| 324 |
*/ |
| 325 |
public function get_items_permissions_check( $request ) { |
| 326 |
|
| 327 |
if ( ! current_user_can( 'cartflows_manage_settings' ) ) { |
| 328 |
return new \WP_Error( 'cartflows_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'cartflows' ), array( 'status' => rest_authorization_required_code() ) ); |
| 329 |
} |
| 330 |
|
| 331 |
return true; |
| 332 |
} |
| 333 |
} |
| 334 |
|