A library designed for WPFactory plugins, aimed at cross-selling by offering WPFactory product recommendations
Installation via Composer. Instructions to setup the composer.json
.
- Add these objects to the
repositories
array:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/wpcodefactory/wpfactory-cross-selling"
},
{
"type": "vcs",
"url": "https://github.com/wpcodefactory/wpfactory-admin-menu"
}
]
}
- Require the library and its dependencies:
{
"require": {
"wpfactory/wpfactory-cross-selling": "*",
"wpfactory/wpfactory-admin-menu": "*"
}
}
- Use
preferred-install
parameter set asdist
onconfig
.
{
"config": {
"preferred-install": "dist"
}
}
Full Example:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/wpcodefactory/wpfactory-cross-selling"
},
{
"type": "vcs",
"url": "https://github.com/wpcodefactory/wpfactory-admin-menu"
}
],
"require": {
"wpfactory/wpfactory-cross-selling": "*",
"wpfactory/wpfactory-admin-menu": "*"
},
"config": {
"preferred-install": "dist"
}
}
-
Create/Put the composer.json on the root folder.
-
Then initialize the library with
new \WPFactory\WPFactory_Cross_Selling\WPFactory_Cross_Selling()
from within the main plugin class. Probably the best place is inside the hookplugins_loaded
. If the main class is already being loaded with that hook, you can simply load the library in the class constructor.
Note
Try to remember to only run it inside a is_admin()
check.
Example:
add_action( 'plugins_loaded', function(){
$main_plugin_class = new Main_Plugin_Class();
} );
class Main_Plugin_Class(){
function __construct() {
$this->init_cross_selling_library();
}
function init_cross_selling_library(){
if ( ! is_admin() ) {
return;
}
// Composer.
require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
// Initializes WPFactory Key Manager library.
$cross_selling = new \WPFactory\WPFactory_Cross_Selling\WPFactory_Cross_Selling();
$cross_selling->setup( array( 'plugin_file_path' => __FILE__ ) );
$cross_selling->init()
}
}
Setups the library.
Parameters:
-
plugin_file_path
(string) - Plugin file path. -
recommendations_page
(array)action_link
(array)enable
(boolean) - Enables/Disables the plugin action link. Default value:true
.label
(string) - Label for the plugin action link. Default value:'Recommendations'
.
-
recommendations_box
(array)enable
(boolean) - Enables/Disables the Recommendation box. Default value:true
.wc_settings_tab_id
(string) - WooCommerce settings tab id.position
(array) - The position to place the Recommendation Box. Default value:array( 'wc_settings_tab' )
. Possible values:wc_settings_tab
Initializes the library.
$cross_selling = new \WPFactory\WPFactory_Cross_Selling\WPFactory_Cross_Selling();
$cross_selling->setup(array(
'plugin_file_path' => $this->get_filesystem_path(),
'recommendations_box' => array(
'enable' => true,
'wc_settings_tab_id' => 'alg_wc_cost_of_goods',
'position' => array( 'wc_settings_tab' ),
),
'recommendations_page' => array(
'action_link' => array(
'enable' => true,
'label' => 'Suggestions',
),
),
));
$cross_selling->init();