Update coming soon docs to include more extensibility examples (#51160)
* Update docs * Small update * Changelog * Lint * Docs manifest * Add store pages extensibility * Docs manifest * Update docs/extension-development/integrating-coming-soon-mode.md Co-authored-by: Chi-Hsuan Huang <chihsuan.tw@gmail.com> --------- Co-authored-by: Chi-Hsuan Huang <chihsuan.tw@gmail.com>
This commit is contained in:
parent
43ce3c1c4d
commit
b4f1062783
|
@ -691,7 +691,7 @@
|
|||
"post_title": "Integrating with coming soon mode",
|
||||
"tags": "how-to, coming-soon",
|
||||
"edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/extension-development/integrating-coming-soon-mode.md",
|
||||
"hash": "910dbbab77c6fb4735e7704796242c38d86f3bf3b897de1075338eb47194f8f5",
|
||||
"hash": "8c2087952ae79bb4c3e3977c57d9e933fcfaa418a5bc643b3827059daa5879a7",
|
||||
"url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/extension-development/integrating-coming-soon-mode.md",
|
||||
"id": "787743efb6ef0ad509b17735eaf58b2a9a08afbc"
|
||||
},
|
||||
|
@ -1804,5 +1804,5 @@
|
|||
"categories": []
|
||||
}
|
||||
],
|
||||
"hash": "12e9abfbcdbeae7dd5cc12dc3af3818332f272cb4b3ad12993cc010299009013"
|
||||
"hash": "8199f0d3c854474839300ed606f03f9f286ace35f65d7c47ffc6477762eaf51e"
|
||||
}
|
|
@ -3,7 +3,7 @@ post_title: Integrating with coming soon mode
|
|||
tags: how-to, coming-soon
|
||||
---
|
||||
|
||||
This guide provides examples for third-party developers and hosting providers on how to integrate their systems with WooCommerce's coming soon mode. For more details, please read the [developer blog post](https://developer.woocommerce.com/2024/06/18/introducing-coming-soon-mode/).
|
||||
This guide provides examples for third-party developers and hosting providers on how to integrate their systems with WooCommerce's coming soon mode. For more details, please read the [developer blog post](https://developer.woocommerce.com/2024/06/18/introducing-coming-soon-mode/). For site visibility settings, please refer to the [admin documentation](https://woocommerce.com/document/configuring-woocommerce-settings/coming-soon-mode/).
|
||||
|
||||
## Introduction
|
||||
|
||||
|
@ -49,8 +49,8 @@ function sync_coming_soon_to_other_plugins( $old_value, $new_value, $option ) {
|
|||
$is_enabled = $new_value === 'yes';
|
||||
|
||||
// Implement your logic to sync coming soon status.
|
||||
if ( function_exists( 'set_your_plugin_status' ) ) {
|
||||
set_your_plugin_status( $is_enabled );
|
||||
if ( function_exists( 'your_plugin_set_coming_soon' ) ) {
|
||||
your_plugin_set_coming_soon( $is_enabled );
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -84,8 +84,8 @@ function sync_coming_soon_to_other_plugins( $old_value, $new_value, $option ) {
|
|||
$is_enabled = $new_value === 'yes';
|
||||
|
||||
// Implement your logic to sync coming soon status.
|
||||
if ( function_exists( 'set_your_plugin_status' ) ) {
|
||||
set_your_plugin_status( $is_enabled );
|
||||
if ( function_exists( 'your_plugin_set_coming_soon' ) ) {
|
||||
your_plugin_set_coming_soon( $is_enabled );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,6 +108,38 @@ function sync_coming_soon_from_other_plugins( $is_enabled ) {
|
|||
}
|
||||
```
|
||||
|
||||
#### One-way binding with option override
|
||||
|
||||
We could also programmatically bind the coming soon option from another plugin by overriding the `woocommerce_coming_soon` option. This is advantageous since it simplifies state management and prevents possible out-of-sync issues.
|
||||
|
||||
In the following example, we're binding the coming soon option from another plugin by overriding the `woocommerce_coming_soon` option.
|
||||
|
||||
```php
|
||||
add_filter( 'pre_option_woocommerce_coming_soon', 'override_option_woocommerce_coming_soon' );
|
||||
|
||||
function override_option_woocommerce_coming_soon( $current_value ) {
|
||||
// Implement your logic to sync coming soon status.
|
||||
if ( function_exists( 'your_plugin_is_coming_soon' ) ) {
|
||||
return your_plugin_is_coming_soon() ? 'yes' : 'no';
|
||||
}
|
||||
return $current_value;
|
||||
}
|
||||
|
||||
add_filter( 'pre_update_option_woocommerce_coming_soon', 'override_update_woocommerce_coming_soon', 10, 2 );
|
||||
|
||||
function override_update_woocommerce_coming_soon( $new_value, $old_value ) {
|
||||
// Check user capability.
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_die( 'You do not have sufficient permissions to access this page.' );
|
||||
}
|
||||
|
||||
// Implement your logic to sync coming soon status.
|
||||
if ( function_exists( 'your_plugin_set_coming_soon' ) ) {
|
||||
your_plugin_set_coming_soon( $new_value === 'yes' );
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Custom exclusions filter
|
||||
|
||||
It is possible for developers to add custom exclusions that bypass the coming soon protection. This is useful for exclusions like always bypassing the screen on a specific IP address, or making a specific landing page available.
|
||||
|
@ -134,3 +166,35 @@ add_filter( 'woocommerce_coming_soon_exclude', function( $is_excluded ) {
|
|||
return $is_excluded;
|
||||
}, 10 );
|
||||
```
|
||||
|
||||
#### Custom share links
|
||||
|
||||
The following example shows how to integrate with a custom share code. We recommend using cookies or other storage to persist the access when users navigate across the site:
|
||||
|
||||
```php
|
||||
add_filter( 'woocommerce_coming_soon_exclude', function( $exclude ) {
|
||||
// Implement your logic to get and validate share code.
|
||||
if ( function_exists( 'your_plugin_get_share_code' ) && function_exists( 'your_plugin_is_valid_share_code' ) ) {
|
||||
$share_code = your_plugin_get_share_code();
|
||||
if ( your_plugin_is_valid_share_code( $share_code ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return $exclude;
|
||||
} );
|
||||
```
|
||||
|
||||
### Extend "Apply to store pages only" setting
|
||||
|
||||
When using the `Apply to store pages only` setting, you may want to add a custom page to the list of store pages which will be restricted by coming soon mode. You can use the following example to add a custom page:
|
||||
|
||||
```php
|
||||
add_filter( 'woocommerce_store_pages', function( $pages ) {
|
||||
$page = get_page_by_path( 'your-page-slug' );
|
||||
if ( $page ) {
|
||||
$pages[] = $page->ID;
|
||||
}
|
||||
return $pages;
|
||||
} );
|
||||
```
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: tweak
|
||||
|
||||
Update coming soon extensibility documentation
|
Loading…
Reference in New Issue