| @@ -60,8 +60,10 @@ | ||
| 60 | 60 | add_action( 'wp_ajax_sellkit_steps_get_coupons', [ $this, 'get_coupons' ] ); |
| 61 | 61 | add_action( 'wp_loaded', [ $this, 'sellkit_steps_flush_rules' ] ); |
| 62 | 62 | add_action( 'sellkit_after_toggle_status_sellkit-funnels', [ $this, 'update_steps_post_status' ], 10, 2 ); |
| 63 | 63 | add_action( 'sellkit_funnels_after_delete_posts_sellkit-funnels', [ $this, 'remove_steps_pages' ], 10, 1 ); |
| 64 | + | |
| 65 | + add_action( 'wp_loaded', [ $this, 'sellkit_set_sellkit_translation_mode' ] ); | |
| 64 | 66 | } |
| 65 | 67 | |
| 66 | 68 | /** |
| 67 | 69 | * Removes steps pages. |
| @@ -77,9 +79,11 @@ | ||
| 77 | 79 | return; |
| 78 | 80 | } |
| 79 | 81 | |
| 80 | 82 | foreach ( $nodes[0] as $node ) { |
| 81 | - wp_delete_post( $node['page_id'] ); | |
| 83 | + if ( isset( $node['page_id'] ) ) { | |
| 84 | + wp_delete_post( $node['page_id'] ); | |
| 85 | + } | |
| 82 | 86 | } |
| 83 | 87 | } |
| 84 | 88 | |
| 85 | 89 | /** |
| @@ -91,12 +95,12 @@ | ||
| 91 | 95 | return [ |
| 92 | 96 | 'sales-page' => esc_html__( 'Sales Page', 'sellkit' ), |
| 93 | 97 | 'checkout' => esc_html__( 'Checkout', 'sellkit' ), |
| 94 | 98 | 'thankyou' => esc_html__( 'Thank You', 'sellkit' ), |
| 95 | - 'decision' => esc_html__( 'Decision', 'sellkit' ), | |
| 99 | + 'decision' => esc_html__( 'Condition', 'sellkit' ), | |
| 96 | 100 | 'upsell' => esc_html__( 'Upsell', 'sellkit' ), |
| 97 | 101 | 'downsell' => esc_html__( 'Downsell', 'sellkit' ), |
| 98 | - 'optin-confirmation' => esc_html__( 'Opt-in Confirmation' ), | |
| 102 | + 'optin-confirmation' => esc_html__( 'Opt-in Confirmation', 'sellkit' ), | |
| 99 | 103 | 'optin' => esc_html__( 'Opt-in', 'sellkit' ), |
| 100 | 104 | ]; |
| 101 | 105 | } |
| 102 | 106 | |
| @@ -111,9 +115,17 @@ | ||
| 111 | 115 | foreach ( $steps as $step_number => $step ) { |
| 112 | 116 | $step['funnel_id'] = $funnel_id; |
| 113 | 117 | $step['number'] = $step_number; |
| 114 | 118 | |
| 115 | - update_post_meta( $step['page_id'], 'step_data', $step ); | |
| 119 | + if ( array_key_exists( 'page_id', $step ) ) { | |
| 120 | + $translated_step = apply_filters( 'wpml_object_id', $step['page_id'], 'sellkit_step', true ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WPML API. | |
| 121 | + | |
| 122 | + if ( $step['page_id'] !== $translated_step ) { | |
| 123 | + update_post_meta( $translated_step, 'step_data', $step ); | |
| 124 | + } | |
| 125 | + | |
| 126 | + update_post_meta( $step['page_id'], 'step_data', $step ); | |
| 127 | + } | |
| 116 | 128 | } |
| 117 | 129 | } |
| 118 | 130 | |
| 119 | 131 | /** |
| @@ -213,9 +225,9 @@ | ||
| 213 | 225 | wp_send_json_error( __( 'Please install and activate WooCommerce.', 'sellkit' ) ); |
| 214 | 226 | } |
| 215 | 227 | |
| 216 | 228 | if ( empty( $products_id ) ) { |
| 217 | - wp_send_json_error( __( 'Please send some product ids' ) ); | |
| 229 | + wp_send_json_error( __( 'Please send some product ids', 'sellkit' ) ); | |
| 218 | 230 | } |
| 219 | 231 | |
| 220 | 232 | $products_id = is_array( $products_id ) ? $products_id : [ $products_id ]; |
| 221 | 233 | |
| @@ -222,12 +234,17 @@ | ||
| 222 | 234 | foreach ( $products_id as $product_id ) { |
| 223 | 235 | $product = wc_get_product( $product_id ); |
| 224 | 236 | |
| 225 | 237 | if ( empty( $product ) ) { |
| 226 | - wp_send_json_error( __( 'Product does not exist', 'sellkit' ) ); | |
| 227 | 238 | continue; |
| 228 | 239 | } |
| 229 | 240 | |
| 241 | + $data = $product->get_data(); | |
| 242 | + | |
| 243 | + if ( 'trash' === $data['status'] ) { | |
| 244 | + continue; | |
| 245 | + } | |
| 246 | + | |
| 230 | 247 | $attributes = $product->get_attributes(); |
| 231 | 248 | $label = $product->get_title(); |
| 232 | 249 | |
| 233 | 250 | if ( $product->get_type() === 'variation' ) { |
| @@ -310,9 +327,9 @@ | ||
| 310 | 327 | $nodes[ end( $old_node_keys ) + 1 ] = $last_node; |
| 311 | 328 | $keys = array_keys( $nodes ); |
| 312 | 329 | |
| 313 | 330 | if ( |
| 314 | - 'last-node' !== $origin_node && | |
| 331 | + 'last-node' !== $origin_node && ! empty( $nodes[ $origin_node ] ) && | |
| 315 | 332 | 'decision' !== $nodes[ $origin_node ]['type']['key'] && |
| 316 | 333 | 'upsell' !== $nodes[ $origin_node ]['type']['key'] && |
| 317 | 334 | 'downsell' !== $nodes[ $origin_node ]['type']['key'] |
| 318 | 335 | ) { |
| @@ -319,9 +336,9 @@ | ||
| 319 | 336 | $nodes[ $origin_node ]['targets'] = [ [ 'nodeId' => strval( end( $keys ) ) ] ]; |
| 320 | 337 | } |
| 321 | 338 | |
| 322 | 339 | if ( |
| 323 | - 'last-node' !== $origin_node && | |
| 340 | + 'last-node' !== $origin_node && isset( $nodes[ $origin_node ]['type'] ) && | |
| 324 | 341 | ( |
| 325 | 342 | 'decision' === $nodes[ $origin_node ]['type']['key'] || |
| 326 | 343 | 'upsell' === $nodes[ $origin_node ]['type']['key'] || |
| 327 | 344 | 'downsell' === $nodes[ $origin_node ]['type']['key'] |
| @@ -375,8 +392,12 @@ | ||
| 375 | 392 | if ( 'string' !== gettype( $template ) || ! is_object( $post ) || self::SELLKIT_STEP_POST_TYPE !== $post->post_type ) { |
| 376 | 393 | return $template; |
| 377 | 394 | } |
| 378 | 395 | |
| 396 | + if ( has_blocks( $post ) ) { | |
| 397 | + return $template; | |
| 398 | + } | |
| 399 | + | |
| 379 | 400 | remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' ); |
| 380 | 401 | add_filter( 'next_post_rel_link', '__return_empty_string' ); |
| 381 | 402 | add_filter( 'previous_post_rel_link', '__return_empty_string' ); |
| 382 | 403 | |
| @@ -500,8 +521,12 @@ | ||
| 500 | 521 | */ |
| 501 | 522 | public function update_steps_post_status( $funnel_id, $new_status ) { |
| 502 | 523 | $steps = get_post_meta( $funnel_id, 'sellkit_steps', true ); |
| 503 | 524 | |
| 525 | + if ( ! is_array( $steps ) ) { | |
| 526 | + return; | |
| 527 | + } | |
| 528 | + | |
| 504 | 529 | foreach ( $steps as $step ) { |
| 505 | 530 | if ( $step['page_id'] === $funnel_id ) { |
| 506 | 531 | continue; |
| 507 | 532 | } |
| @@ -509,8 +534,41 @@ | ||
| 509 | 534 | wp_update_post(array( |
| 510 | 535 | 'ID' => $step['page_id'], |
| 511 | 536 | 'post_status' => $new_status, |
| 512 | 537 | ) ); |
| 538 | + } | |
| 539 | + } | |
| 540 | + | |
| 541 | + /** | |
| 542 | + * Make SellKit custom post types translatable by default and set step_data custom field to "Copy". | |
| 543 | + * | |
| 544 | + * @since 2.3.2 | |
| 545 | + */ | |
| 546 | + public function sellkit_set_sellkit_translation_mode() { | |
| 547 | + if ( function_exists( 'wpml_load_settings_helper' ) ) { | |
| 548 | + global $sitepress; | |
| 549 | + | |
| 550 | + if ( $sitepress instanceof SitePress ) { | |
| 551 | + $settings_helper = wpml_load_settings_helper(); | |
| 552 | + | |
| 553 | + $post_types = [ | |
| 554 | + 'sellkit_step', | |
| 555 | + 'sellkit-discount', | |
| 556 | + 'sellkit-coupon', | |
| 557 | + 'sellkit-alert', | |
| 558 | + ]; | |
| 559 | + | |
| 560 | + foreach ( $post_types as $post_type ) { | |
| 561 | + $settings_helper->set_post_type_translatable( $post_type ); | |
| 562 | + $settings_helper->set_post_type_translation_unlocked_option( $post_type, true ); | |
| 563 | + | |
| 564 | + if ( class_exists( '\WPML\Settings\PostType\Automatic' ) ) { | |
| 565 | + \WPML\Settings\PostType\Automatic::set( $post_type, true ); | |
| 566 | + } | |
| 567 | + } | |
| 568 | + | |
| 569 | + do_action( 'wpml_save_custom_field_translation_option', 'step_data', WPML_COPY_CUSTOM_FIELD ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WPML API. | |
| 570 | + } | |
| 513 | 571 | } |
| 514 | 572 | } |
| 515 | 573 | } |
| 516 | 574 | |