ec91ad78 by Jeff Balicki

create product

Signed-off-by: Jeff <jeff@gotenzing.com>
1 parent c3e9dd24
Showing 70 changed files with 3005 additions and 0 deletions
---
name: Bug report
about: Create a report to help us improve
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
1. Role Based Price For WooCommerce Settings
2. WC Price Editor View (For the product which has the issue)
If applicable, add screenshots to help explain your problem.
**Software Versions**
1. WordPress :
2. WooCommerce :
3. Role Based Price For WooCommerce :
**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
**Additional context**
Add any other context about the problem here.
---
name: Feature request
about: Suggest an idea for this project
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.
name: PHP CI/CD
env:
VS_WORKFLOW_TYPE: "php-cicd"
on:
push:
branches:
- master
- main
paths:
- '**.php'
jobs:
apigen_docs:
name: "ApiGen Docs"
runs-on: ubuntu-latest
steps:
- name: "📥 Fetching Repository Contents"
uses: actions/checkout@main
- name: "💾 Github Repository Metadata"
uses: varunsridharan/action-repository-meta@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "💫 VS Utility"
uses: varunsridharan/action-vs-utility@main
- name: " Repository - Before Hook"
run: |
echo " "
if [ -f $VS_BEFORE_HOOK_FILE_LOCATION ]; then
echo "✅ Before Hook File Found : $VS_BEFORE_HOOK_FILE_LOCATION"
sh $VS_BEFORE_HOOK_FILE_LOCATION
else
echo "⚠️ No Before Hook File Found : $VS_BEFORE_HOOK_FILE_LOCATION"
fi
echo " "
- name: "📚 Generating Code Documentation"
uses: varunsridharan/action-apigen@2.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: " Repository - After Hook"
run: |
echo " "
if [ -f $VS_AFTER_HOOK_FILE_LOCATION ]; then
echo "✅ After Hook File Found : $VS_AFTER_HOOK_FILE_LOCATION"
sh $VS_AFTER_HOOK_FILE_LOCATION
else
echo "⚠️ No After Hook File Found : $VS_AFTER_HOOK_FILE_LOCATION"
fi
echo " "
\ No newline at end of file
name: Twitter Post On Release
env:
VS_WORKFLOW_TYPE: "twitter-post"
on:
release:
types:
- published
jobs:
twitter_post:
name: "🐦 Tweet"
runs-on: ubuntu-latest
steps:
- name: "📥 Fetching Repository Contents"
uses: actions/checkout@main
- name: "💾 Github Repository Metadata"
uses: varunsridharan/action-repository-meta@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "💫 VS Utility"
uses: varunsridharan/action-vs-utility@main
env:
SVA_ONL_TOKEN: ${{ secrets.SVA_ONL_TOKEN }}
- name: " Repository - Before Hook"
run: |
echo " "
if [ -f $VS_BEFORE_HOOK_FILE_LOCATION ]; then
echo "✅ Before Hook File Found : $VS_BEFORE_HOOK_FILE_LOCATION"
sh $VS_BEFORE_HOOK_FILE_LOCATION
else
echo "⚠️ No Before Hook File Found : $VS_BEFORE_HOOK_FILE_LOCATION"
fi
echo " "
- name: "🚀 Publishing Tweet 🐦 "
uses: m1ner79/Github-Twittction@master
with:
twitter_status: ${{ env.TWITTER_STATUS }}
twitter_consumer_key: ${{ secrets.TWITTER_API_KEY }}
twitter_consumer_secret: ${{ secrets.TWITTER_API_SECRET_KEY }}
twitter_access_token_key: ${{ secrets.TWITTER_ACCESS_TOKEN }}
twitter_access_token_secret: ${{ secrets.TWITTER_ACCESS_SECRET_TOKEN }}
- name: " Repository - After Hook"
run: |
echo " "
if [ -f $VS_AFTER_HOOK_FILE_LOCATION ]; then
echo "✅ After Hook File Found : $VS_AFTER_HOOK_FILE_LOCATION"
sh $VS_AFTER_HOOK_FILE_LOCATION
else
echo "⚠️ No After Hook File Found : $VS_AFTER_HOOK_FILE_LOCATION"
fi
echo " "
\ No newline at end of file
name: "Release - WordPress.org"
env:
DIST_LOCATION: "./dist/"
VS_WORKFLOW_TYPE: "wordpress-org-release"
on:
release:
types:
- published
jobs:
publish-wordpress-org:
name: "🚀 WordPress Publisher"
runs-on: ubuntu-latest
steps:
- name: "📥 Fetching Repository Contents"
uses: actions/checkout@main
- name: "💾 Github Repository Metadata"
uses: varunsridharan/action-repository-meta@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "💫 VS Utility"
uses: varunsridharan/action-vs-utility@main
- name: " Repository - Before Hook"
run: |
echo " "
if [ -f $VS_BEFORE_HOOK_FILE_LOCATION ]; then
echo "✅ Before Hook File Found : $VS_BEFORE_HOOK_FILE_LOCATION"
sh $VS_BEFORE_HOOK_FILE_LOCATION
else
echo "⚠️ No Before Hook File Found : $VS_BEFORE_HOOK_FILE_LOCATION"
fi
echo " "
- name: "💽 Installing Composer"
uses: g-actions/composer-action@main
with:
command: install --no-dev
- name: "🚀 Publishing Release"
uses: varunsridharan/action-wp-org-deploy@main
with:
WORDPRESS_PASSWORD: ${{ secrets.WP_PASSWORD }}
WORDPRESS_USERNAME: ${{ secrets.WP_USERNAME }}
SLUG: ${{ env.GITHUB_REPOSITORY_NAME }}
IGNORE_FILE: ${{ env.WORDPRESS_DIST_IGNORE }}
ASSETS_IGNORE_FILE: ${{ env.WORDPRESS_ASSETS_DIST_IGNORE }}
DIST_LOCATION: ${{ env.DIST_LOCATION }}
- name: "📦 Upload ZIP To Release in Github"
uses: Roang-zero1/github-upload-release-artifacts-action@master
with:
args: ${{ env.DIST_LOCATION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: " Repository - After Hook"
run: |
echo " "
if [ -f $VS_AFTER_HOOK_FILE_LOCATION ]; then
echo "✅ After Hook File Found : $VS_AFTER_HOOK_FILE_LOCATION"
sh $VS_AFTER_HOOK_FILE_LOCATION
else
echo "⚠️ No After Hook File Found : $VS_AFTER_HOOK_FILE_LOCATION"
fi
echo " "
\ No newline at end of file
plugins/price-add-to-cart-visibility/Thumbs.db
<?php
/**
* Plugin Main File
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
* @package Role Based Price For WooCommerce
* @subpackage Role Based Price For WooCommerce/core
* @since 3.0
*/
if ( ! defined( 'WPINC' ) ) {
die;
}
class WooCommerce_Role_Based_Price {
protected static $_instance = null;
protected static $functions = null;
protected static $admin = null; # Required Plugin Class Instance
protected static $settings = null; # Required Plugin Class Instance
protected static $frontend = null; # Required Plugin Class Instance
protected static $shortcode_handler = null; # Required Plugin Class Instance
public $version = '3.3.5'; # Required Plugin Class INstance
public $plugin_vars = array(); # Required Plugin Class INstance
/**
* Class Constructor
*/
public function __construct() {
$this->define_constant();
$this->load_required_files();
$this->init_hooks();
do_action( 'wc_rbp_loaded' );
}
/**
* Define Required Constant
*/
private function define_constant() {
$this->define( 'WC_RBP_NAME', 'Role Based Price For WooCommerce' ); # Plugin Name
$this->define( 'WC_RBP_SLUG', 'woocommerce-role-based-price' ); # Plugin Slug
$this->define( 'WC_RBP_TXT', 'woocommerce-role-based-price' ); #plugin lang Domain
$this->define( 'WC_RBP_DB', 'wc_rbp_' );
$this->define( 'WC_RBP_V', $this->version ); # Plugin Version
$this->define( 'WC_RBP_LANGUAGE_PATH', WC_RBP_PATH . 'languages' ); # Plugin Language Folder
$this->define( 'WC_RBP_ADMIN', WC_RBP_INC . 'admin/' ); # Plugin Admin Folder
$this->define( 'WC_RBP_SETTINGS', WC_RBP_ADMIN . 'settings/' ); # Plugin Settings Folder
$this->define( 'WC_RBP_PLUGIN', WC_RBP_PATH . 'plugins/' );
$this->define( 'WC_RBP_URL', plugins_url( '', __FILE__ ) . '/' ); # Plugin URL
$this->define( 'WC_RBP_PLUGIN_URL', WC_RBP_URL . 'plugins/' ); # Plugin URL
$this->define( 'WC_RBP_CSS', WC_RBP_URL . 'includes/css/' ); # Plugin CSS URL
$this->define( 'WC_RBP_IMG', WC_RBP_URL . 'includes/img/' ); # Plugin IMG URL
$this->define( 'WC_RBP_JS', WC_RBP_URL . 'includes/js/' ); # Plugin JS URL
}
/**
* Define constant if not already set
*
* @param string $name
* @param string|bool $value
*/
protected function define( $key, $value ) {
if ( ! defined( $key ) ) {
define( $key, $value );
}
}
/**
* Loads Required Plugins For Plugin
*/
private function load_required_files() {
$this->load_files( WC_RBP_INC . 'abstract-*.php' );
$this->load_files( WC_RBP_INC . 'helpers/class-admin-notice.php' );
$this->load_files( WC_RBP_INC . 'class-*.php' );
$this->load_files( WC_RBP_ADMIN . 'settings_framework/class-wp-plugin-options.php' );
$this->load_files( WC_RBP_ADMIN . 'settings_framework/class-wp-*.php' );
if ( wc_rbp_is_request( 'admin' ) ) {
$this->load_files( WC_RBP_ADMIN . 'class-*.php' );
}
do_action( 'wc_rbp_before_addons_load' );
$this->load_addons();
}
/**
* Loads Files Based On Give Path & regex
*/
protected function load_files( $path, $type = 'require' ) {
foreach ( glob( $path ) as $files ) {
if ( $type == 'require' ) {
require_once( $files );
} elseif ( $type == 'include' ) {
include_once( $files );
}
}
}
public function load_addons() {
$addons = wc_rbp_get_active_addons();
if ( ! empty( $addons ) ) {
foreach ( $addons as $addon ) {
if ( apply_filters( 'wc_rbp_load_addon', true, $addon ) ) {
do_action( 'wc_rbp_before_' . $addon . '_addon_load' );
$this->load_addon( $addon );
do_action( 'wc_rbp_after_' . $addon . '_addon_load' );
}
}
}
}
public function load_addon( $file ) {
$other_file = apply_filters( 'wc_rbp_addon_file_location', $file );
if ( file_exists( WC_RBP_PLUGIN . $file ) ) {
$this->load_files( WC_RBP_PLUGIN . $file );
} elseif ( file_exists( $other_file ) ) {
$this->load_files( $other_file );
} else {
if ( has_action( 'wc_rbp_addon_' . $file . '_load' ) ) {
do_action( 'wc_rbp_addon_' . $file . '_load' );
} else {
wc_rbp_deactivate_addon( $file );
}
}
}
public function init_hooks() {
add_action( 'plugins_loaded', array( $this, 'after_plugins_loaded' ) );
add_filter( 'load_textdomain_mofile', array( $this, 'load_plugin_mo_files' ), 10, 2 );
add_action( 'init', array( $this, 'init' ), 0 );
}
/**
* Creates or returns an instance of this class.
*/
public static function get_instance() {
if ( null == self::$_instance ) {
self::$_instance = new self;
}
return self::$_instance;
}
# Returns Plugin's Functions Instance
/**
* Throw error on object clone.
*
* Cloning instances of the class is forbidden.
*
* @since 1.0
* @return void
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, __( 'Cloning instances of the class is forbidden.', WC_RBP_TXT ), WC_RBP_V );
}
# Returns Plugin's Functions Instance
/**
* Disable unserializing of the class
*
* Unserializing instances of the class is forbidden.
*
* @since 1.0
* @return void
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Unserializing instances of the class is forbidden.', WC_RBP_TXT ), WC_RBP_V );
}
# Returns Plugin's Settings Instance
/**
* Inits loaded Class
*/
public function init() {
do_action( 'wc_rbp_before_init' );
self::$functions = new WooCommerce_Role_Based_Price_Functions;
self::$settings = new WooCommerce_Role_Based_Price_Settings_Framework;
self::$shortcode_handler = new WooCommerce_Role_Based_Price_Shortcode_Handler;
if ( wc_rbp_is_request( 'admin' ) ) {
self::$admin = new WooCommerce_Role_Based_Price_Admin;
} else {
self::$frontend = new WooCommerce_Role_Based_Price_Product_Pricing;
}
do_action( 'wc_rbp_init' );
}
# Returns Plugin's Admin Instance
public function func() {
return self::$functions;
}
public function frontend() {
return self::$frontend;
}
public function settings() {
return self::$settings;
}
public function admin() {
return self::$admin;
}
/**
* Set Plugin Text Domain
*/
public function after_plugins_loaded() {
load_plugin_textdomain( WC_RBP_TXT, false, WC_RBP_LANGUAGE_PATH );
}
/**
* load translated mo file based on wp settings
*/
public function load_plugin_mo_files( $mofile, $domain ) {
if ( WC_RBP_TXT === $domain ) {
return WC_RBP_LANGUAGE_PATH . '/' . get_locale() . '.mo';
}
return $mofile;
}
}
\ No newline at end of file
<?php
/**
*
* Addons Handler
*
* @link https://codecanyon.net/item/advanced-product-reviews-for-woocommerce/15385857
* @package APRWC
* @subpackage APRWC/FrontEnd
* @since 2.0
*/
if( ! defined('WPINC') ) {
die;
}
class WooCommerce_Role_Based_Price_Addon_Handler {
public function __construct() {
add_filter('wc_rbp_addon_sections', array( $this, 'register_section' ));
add_filter('wc_rbp_addon_fields', array( $this, 'register_fields' ));
add_action('wp_enqueue_scripts', array( $this, 'frontend_style' ));
add_action('wp_enqueue_scripts', array( $this, 'frontend_script' ));
if( is_admin() ) {
add_action('wc_rbp_admin_styles', array( $this, 'admin_style' ));
add_action('wc_rbp_admin_scripts', array( $this, 'admin_script' ));
}
add_action('wc_rbp_loaded', array( $this, 'init_class' ));
}
public function register_section($settings_section) {
return $settings_section;
}
public function register_fields($settings_fields) {
return $settings_fields;
}
public function init_class() {
}
public function admin_style($screen = '') {
}
public function admin_script($screen = '') {
}
public function frontend_style() {
}
public function frontend_script() {
}
public function addon_path($file = __DIR__) {
return plugin_dir_path($file);
}
public function addon_url($file = __FILE__) {
return plugin_dir_url($file);
}
}
\ No newline at end of file
<?php
/**
* Plugin's Admin code
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
* @package Role Based Price For WooCommerce
* @subpackage Role Based Price For WooCommerce/Admin
* @since 3.0
*/
if ( ! defined( 'WPINC' ) ) {
die;
}
class WooCommerce_Role_Based_Price_Admin {
/**
* Initialize the class and set its properties.
*
* @since 0.1
*/
public function __construct() {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ), 99 );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'admin_init', array( $this, 'admin_init' ) );
add_filter( 'woocommerce_screen_ids', array( $this, 'set_wc_screen_ids' ), 99 );
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_links' ), 10, 2 );
add_filter( 'plugin_action_links_' . WC_RBP_FILE, array( $this, 'plugin_action_links' ), 10, 10 );
//add_action( 'admin_menu',array($this,'add_welcome_menu'));
}
public function set_wc_screen_ids( $screens ) {
$screen = $screens;
$screen[] = 'woocommerce_page_woocommerce-role-based-price-settings';
$screen[] = 'product_page_rbp_global_addons';
return $screen;
}
/**
* Inits Admin Sttings
*/
public function admin_init() {
//$this->handle_welcome_page();
new WooCommerce_Role_Based_Price_Admin_Ajax_Handler;
new WooCommerce_Role_Based_Price_Addons;
}
public function handle_welcome_page() {
if ( ! get_transient( '_welcome_redirect_wcrbp' ) ) {
return;
}
delete_transient( '_welcome_redirect_wcrbp' );
if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
return;
}
wp_safe_redirect( add_query_arg( array( 'page' => 'wcrbp_welcome_page' ), admin_url( 'plugins.php' ) ) );
}
public function add_welcome_menu() {
if ( ! get_transient( '_welcome_redirect_wcrbp' ) ) {
//return;
}
if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
return;
}
add_submenu_page( 'plugins.php', __( 'Role Based Price For WooCommerce Welcome Page', 'WPW' ), __( 'Role Based Price For WooCommerce Welcome Page', 'WPW' ), 'read', 'wcrbp_welcome_page', array(
$this,
'wcrbp_welcome_page_content',
) );
}
public function wcrbp_welcome_page_content() {
include( WC_RBP_ADMIN . 'views/plugin-welcome-page.php' );
}
/**
* Register the stylesheets for the admin area.
*/
public function enqueue_styles() {
$current_screen = wc_rbp_current_screen();
$addon_url = admin_url( 'admin-ajax.php?action=wc_rbp_addon_custom_css' );
wp_register_style( WC_RBP_SLUG . '_backend_style', WC_RBP_CSS . 'backend.css', array(), WC_RBP_V, 'all' );
wp_register_style( WC_RBP_SLUG . '_addons_style', $addon_url, array(), WC_RBP_V, 'all' );
wp_register_style( WC_RBP_SLUG . '_settings_selectize_style', WC_RBP_CSS . 'selectize.js.css', array(), WC_RBP_V, 'all' );
wp_register_style( WC_RBP_SLUG . '_tabs_style', WC_RBP_CSS . 'tabs.css', array(), WC_RBP_V, 'all' );
wp_enqueue_style( WC_RBP_SLUG . '_backend_style' );
wp_enqueue_style( WC_RBP_SLUG . '_addons_style' );
if ( 'woocommerce_page_woocommerce-role-based-price-settings' == $current_screen ) {
wp_enqueue_style( WC_RBP_SLUG . '_settings_selectize_style' );
add_thickbox();
}
if ( 'product' == $current_screen ) {
wp_enqueue_style( WC_RBP_SLUG . '_tabs_style' );
wp_enqueue_style( WC_RBP_SLUG . '_settings_selectize_style' );
}
do_action( 'wc_rbp_admin_styles', $current_screen );
}
/**
* Register the JavaScript for the admin area.
*/
public function enqueue_scripts() {
$current_screen = wc_rbp_current_screen();
$addon_url = admin_url( 'admin-ajax.php?action=wc_rbp_addon_custom_js' );
wp_register_script( WC_RBP_SLUG . '_backend_script', WC_RBP_JS . 'backend.js', array( 'jquery' ), WC_RBP_V, false );
wp_register_script( WC_RBP_SLUG . '_addons_script', $addon_url, array( 'jquery' ), WC_RBP_V, false );
wp_register_script( WC_RBP_SLUG . '_settings_selectize.js', WC_RBP_JS . 'selectize.js', array( 'jquery' ), WC_RBP_V, false );
wp_register_script( WC_RBP_SLUG . '_settings_checkbox.js', WC_RBP_JS . 'checkbox.js', array( 'jquery' ), WC_RBP_V, false );
wp_register_script( WC_RBP_SLUG . '_settings_js', WC_RBP_JS . 'settings-page.js', array(
'jquery',
WC_RBP_SLUG . '_settings_selectize.js',
), WC_RBP_V, false );
wp_register_script( WC_RBP_SLUG . '_settings_checkbox.js', WC_RBP_JS . 'checkbox.js', array( 'jquery' ), WC_RBP_V, false );
wp_register_script( WC_RBP_SLUG . '_jquery-tabs-script', WC_RBP_JS . 'tabs.js', array( 'jquery' ), WC_RBP_V, false );
wp_enqueue_script( WC_RBP_SLUG . '_backend_script', WC_RBP_JS . 'backend.js', array( 'jquery' ), WC_RBP_V, false );
if ( in_array( $current_screen, wc_rbp_get_screen_ids() ) ) {
}
if ( 'woocommerce_page_woocommerce-role-based-price-settings' == $current_screen ) {
wp_enqueue_script( WC_RBP_SLUG . '_settings_selectize.js' );
wp_enqueue_script( WC_RBP_SLUG . '_settings_checkbox.js' );
wp_enqueue_script( WC_RBP_SLUG . '_settings_js' );
$msg = '<h3>' . __( 'Thanks For Your Continued Support For %1$s' ) . '</h3>';
$msg .= __( 'We Are Already In A Process For Created Version 4.0 For This Plugin' );
$msg .= '<br/><br/><a href="https://forms.gle/waxC4Mm9SZFWuq3A8" class="button button-secondary">' . __( 'Join Newsletter / Request Beta Access' ) . '</a>';
$msg = sprintf( $msg, WC_RBP_NAME );
wc_rbp_admin_update( $msg, 1, array(), array() );
}
if ( 'product' == $current_screen ) {
wp_enqueue_script( WC_RBP_SLUG . '_settings_checkbox.js' );
wp_enqueue_script( WC_RBP_SLUG . '_jquery-tabs-script' );
wp_enqueue_script( WC_RBP_SLUG . '_jquery-product-script' );
wp_enqueue_script( WC_RBP_SLUG . '_settings_selectize.js' );
}
do_action( 'wc_rbp_admin_scripts', $current_screen );
wp_enqueue_script( WC_RBP_SLUG . '_addons_script', $addon_url, array( 'jquery' ), WC_RBP_V, false );
}
/**
* Adds Some Plugin Options
*
* @param array $plugin_meta
* @param string $plugin_file
*
* @return array
* @since 0.11
*/
public function plugin_action_links( $action, $file, $plugin_meta, $status ) {
$url = admin_url( 'admin.php?page=woocommerce-role-based-price-settings' );
$addonurl = admin_url( 'admin.php?page=woocommerce-role-based-price-settings&tab=wcrbpaddons' );
$actions[] = sprintf( '<a href="%s">%s</a>', $url, __( 'Settings', WC_RBP_TXT ) );
$actions[] = sprintf( '<a href="%s">%s</a>', $addonurl, __( 'Add-ons', WC_RBP_TXT ) );
$action = array_merge( $actions, $action );
return $action;
}
/**
* Adds Some Plugin Options
*
* @param array $plugin_meta
* @param string $plugin_file
*
* @return array
* @since 0.11
*/
public function plugin_row_links( $plugin_meta, $plugin_file ) {
if ( WC_RBP_FILE == $plugin_file ) {
$plugin_meta[] = sprintf( '<a href="%s">%s</a>', '#', __( 'Docs', WC_RBP_TXT ) );
$plugin_meta[] = sprintf( '<a href="%s">%s</a>', 'https://github.com/varunsridharan/woocommerce-role-based-price', __( 'View On Github', WC_RBP_TXT ) );
$plugin_meta[] = sprintf( '<a href="%s">%s</a>', 'https://github.com/varunsridharan/woocommerce-role-based-price/issues', __( 'Report Issue', WC_RBP_TXT ) );
$plugin_meta[] = sprintf( '&hearts; <a href="%s">%s</a>', 'https://www.paypal.me/varunsridharan23', __( 'Donate', WC_RBP_TXT ) );
$plugin_meta[] = sprintf( '<a href="%s">%s</a>', 'http://varunsridharan.in/plugin-support/', __( 'Contact Author', WC_RBP_TXT ) );
}
return $plugin_meta;
}
}
<?php
/**
* The admin-specific functionality of the plugin.
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
* @package Role Based Price For WooCommerce
* @subpackage Role Based Price For WooCommerce/Admin
* @since 3.0
*/
if( ! defined('WPINC') ) {
die;
}
class WooCommerce_Role_Based_Price_Admin_Ajax_Handler {
public function __construct() {
add_action('wp_ajax_wc_rbp_clear_variation_cache', array( $this, 'clear_variation_cache' ));
add_action('wp_ajax_wc_rbp_save_product_prices', array( $this, 'save_product_rbp_price' ));
add_action('wp_ajax_nopriv_wc_rbp_addon_custom_css', array( $this, 'render_addon_css' ));
add_action('wp_ajax_wc_rbp_addon_custom_css', array( $this, 'render_addon_css' ));
add_action('wp_ajax_nopriv_wc_rbp_addon_custom_js', array( $this, 'render_addon_js' ));
add_action('wp_ajax_wc_rbp_addon_custom_js', array( $this, 'render_addon_js' ));
add_action('wp_ajax_wc_rbp_metabox_refersh', array( $this, 'refresh_metabox' ));
}
public function clear_variation_cache() {
if( ! isset($_REQUEST['post_id']) ) {
wp_send_json_error(__('Invalid Product ID', WC_RBP_TXT));
}
$id = sanitize_text_field($_REQUEST['post_id']);
$parent = wp_get_post_parent_id($id);
if( $parent !== FALSE ) {
$allowed_roles = array_keys(wc_rbp_get_user_roles_selectbox());
foreach( $allowed_roles as $role ) {
wc_rbp_delete_variation_data($id, $role);
}
}
wp_send_json_success(array( __("Success") ));
}
public function refresh_metabox() {
if( ! isset($_REQUEST['pid']) ) {
wp_send_json_error(__('Invalid Product ID', WC_RBP_TXT));
}
if( ! isset($_REQUEST['parentID']) ) {
wp_send_json_error(__('Invalid Product ID', WC_RBP_TXT));
}
$id = sanitize_text_field($_REQUEST['pid']);
$parentid = sanitize_text_field($_REQUEST['parentID']);
$metabox = new WooCommerce_Role_Based_Price_Product_Metabox;
ob_start();
//$metabox->generate_variation_selectbox($parentid,$id);
$metabox->render_price_editor_metabox($id);
$content = ob_get_contents();
ob_end_clean();
wp_send_json_success($content);
wp_die();
}
public function render_addon_css() {
header('Content-Type: text/css');
do_action('wc_rbp_addon_styles');
wp_die();
}
public function render_addon_js() {
header('Content-Type: text/javascript');
do_action('wc_rbp_addon_scripts');
wp_die();
}
public function save_product_rbp_price() {
$is_verifyed_nounce = wp_verify_nonce($_POST['wc_rbp_nounce'], 'wc_rbp_save_product_prices');
$error = array();
$type = isset($_POST['type']) ? $_POST['type'] : 'default';
$success = array( 'hidden_fields' => wc_rbp_get_editor_fields($type) );
$posted_values = $_POST;
if( $is_verifyed_nounce ) {
do_action_ref_array('wc_rbp_product_save_' . $type, array( &$posted_values, &$success, &$error ));
} else {
$error['html'] = '<h3>' . __("Unable To Process Your Request Please Try Again later", WC_RBP_TXT) . '</h3>';
}
if( empty($error) ) {
wp_send_json_success($success);
} else {
$error['hidden_fields'] = wc_rbp_get_editor_fields($type);
wp_send_json_error($error);
}
wp_die();
}
}
\ No newline at end of file
<?php
/**
* The admin-specific functionality of the plugin.
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
* @package Role Based Price For WooCommerce
* @subpackage Role Based Price For WooCommerce/Admin
* @since 3.0
*/
if( ! defined('WPINC') ) {
die;
}
class WooCommerce_Role_Based_Price_Admin_Sample_Class {
public function __construct() {
}
}
\ No newline at end of file
<?php
class WooCommerce_Role_Based_Price_Product_Metabox {
public function __construct() {
add_action('add_meta_boxes_product', array( $this, 'add_metabox' ));
}
public function add_metabox($post) {
add_meta_box('wc-rbp-product-editor', __('Role Based Price For WooCommerce Editor', WC_RBP_TXT), array(
$this,
'render_price_editor_metabox',
), 'product', 'advanced', 'high');
}
public function render_price_editor_metabox($post) {
if( is_object($post) ) {
$id = $post->ID;
} else {
$id = $post;
}
$prod = NULL;
$prodType = $this->get_post_type($id);
$url = admin_url('admin-ajax.php?action=wc_rbp_save_product_prices');
$render_info = '<div class="wc-rbp-metabox-container" method="POST" action="' . $url . '" > ';
$render_info .= wc_rbp_get_ajax_overlay();
$this->allowed_roles = wc_rbp_allowed_roles();
$this->registered_roles = wc_rbp_get_wp_roles();
$args = array();
$args['render_default'] = TRUE;
$args['html'] = '';
$args['postid'] = $id;
$args['mb'] = $this;
$args['parentID'] = isset($_REQUEST['parentID']) ? sanitize_text_field($_REQUEST['parentID']) : $id;
$args['selectedID'] = isset($_REQUEST['pid']) ? sanitize_text_field($_REQUEST['pid']) : $id;
$args = apply_filters_ref_array('wc_rbp_metabox_render', array( &$args ));
if( $args['render_default'] ) {
$render_info .= $this->render_default_metabox($id, $post, $args);
} else {
$render_info .= $args['html'];
}
$render_info .= '</div>';
echo $render_info;
}
public function get_post_type($id) {
$product_type = '';
if( $terms = wp_get_object_terms($id, 'product_type') ) {
$product_type = sanitize_title(current($terms)->name);
} else {
$product_type = apply_filters('default_product_type', 'simple');
}
return $product_type;
}
public function render_default_metabox($id, $post, $args, $type = 'default') {
$product_type = $this->get_post_type($id);
$render_info = '';
$post_type = get_post_type($id);
if( $product_type == 'variable' || $post_type == 'product_variation' ) {
$render_info .= $this->generate_variation_selectbox($args['parentID'], $id);
} else {
ob_start();
do_action("wc_rbp_metabox_header", $id, $product_type, $post, $this);
$render_info .= ob_get_contents();
ob_end_clean();
}
$prod = wc_get_product($id);
$prodType = 'simple';
if( is_object($prod) ) {
if( wc_rbp_is_wc_v('>=', '3.0.0') ) {
$prodType = $prod->get_type();
} else {
$prodType = $prod->product_type;
}
}
ob_start();
do_action('wc_rbp_before_metabox_content', $prod, $prodType);
$render_info .= ob_get_contents();
ob_end_clean();
$tabs = $this->get_metabox_tabs($id, $prodType);
$content = $this->get_metabox_content($id, $tabs, $prod, $prodType);
$render_info .= wc_rbp_generate_tabs($tabs, $content);
$render_info .= wc_rbp_get_editor_fields($type);
$render_info .= '<input type="hidden" id="wc_rbp_product_id" name="product_id" value="' . $id . '" /> ';
ob_start();
do_action('wc_rbp_after_metabox_content', $prod, $prodType);
$render_info .= ob_get_contents();
ob_end_clean();
$render_info .= $this->render_metabox_footer($id);
return $render_info;
}
public function generate_variation_selectbox($id, $selected = '') {
$header = $this->render_selectbox_header();
$args = array(
'post_type' => 'product_variation',
'post_status' => array( 'private', 'publish' ),
'posts_per_page' => -1,
'orderby' => array( 'menu_order' => 'ASC', 'ID' => 'DESC' ),
'post_parent' => $id,
'fields' => 'ids',
);
$variations = get_children($args);
$return = ' <optgroup label="' . __("Variations", WC_RBP_TXT) . '"> ';
foreach( $variations as $ids ) {
$prod = wc_get_product($ids);
$name = '#' . $ids . ' | ';
if( wc_rbp_is_wc_v('>=', '3.0') ) {
$name .= ' ' . wc_get_formatted_variation($prod, TRUE);
} else {
$name .= ' ' . $prod->get_formatted_variation_attributes(TRUE);
}
$selecteds = '';
if( $selected == $ids ) {
$selecteds = 'selected';
}
$return .= '<option data-type="variation" value="' . $ids . '" ' . $selecteds . '>' . $name . '</option>';
}
$return .= ' </optgroup> ';
$footer = $this->render_selectbox_footer();
$return = apply_filters("role_based_price_metabox_variation_select", $return, $selected, $id);
$return = $header . $return . $footer;
return $return;
}
public function render_selectbox_header($placeholder = '') {
if( empty($placeholder) ) {
$placeholder = __("Select A Variation : ", WC_RBP_TXT);
}
$header = '<select id="wc_rbp_variation_select" style="width: 30%; display: inline-block; vertical-align: middle; margin-left: 10px;" name="wc_rbp_variation_select" class="wcrbpvariationbx"> <option value="">' . $placeholder . '</option>';
return apply_filters("role_based_price_admin_selectbox_header", $header);
}
public function render_selectbox_footer() {
return apply_filters("role_based_price_admin_selectbox_header", '</select>');
}
public function get_metabox_tabs($id, $prodType) {
$tabs = apply_filters('wc_rbp_before_default_product_tabs', array(), $id, $prodType);
$registered_roles = $this->registered_roles;
foreach( $this->allowed_roles as $role ) {
if( isset($registered_roles[$role]) ) {
$icon = 'dashicons dashicons-admin-users';
$tabs[$role] = array(
'title' => $registered_roles[$role]['name'],
'icon' => $icon,
'show_status' => TRUE,
);
}
}
$tabs = apply_filters('wc_rbp_after_default_product_tabs', $tabs, $id, $prodType);
return $tabs;
}
public function get_metabox_content($id, $tabs, $prod, $prodType) {
$content = array();
foreach( $tabs as $tab_id => $val ) {
ob_start();
do_action('wc_rbp_price_edit_tab_' . $tab_id . '_before', $id, $prodType, $prod, $tab_id);
do_action('wc_rbp_price_edit_tab_' . $tab_id, $id, $prodType, $prod, $tab_id);
do_action('wc_rbp_price_edit_tab_' . $tab_id . '_after', $id, $prodType, $prod, $tab_id);
$content[$tab_id] = ob_get_contents();
ob_end_clean();
}
return $content;
}
public function render_metabox_footer($id) {
$base_price = $this->get_base_price($id);
$clbtn = '';
$product_type = wp_get_post_terms($id, 'product_type', array( 'fields' => 'names' ));
if( in_array('variable', $product_type) || get_post_type($id) == 'product_variation' ) {
$clbtn = '<button style="float:left;" type="button" id="wc_rbp_clear_trasient" class="button button-secondary">' . __('Clear Cache', WC_RBP_TXT) . '</button>';
}
return ' <h2 class="" style="margin: 0px -12px -12px; border-top: 1px solid #eee; text-align:right;">
<span class="wc_rbp_base_product_price">' . $base_price . '</span>
' . $clbtn . '
<button type="button" id="wc_rbp_update_price" class="button button-primary">' . __('Save Price', WC_RBP_TXT) . '</button></h2> ';
}
public function get_base_price($id) {
$pro = wc_get_product($id);
$price = '';
if( is_object($pro) ) {
$price = array();
$this->hook_filter(TRUE);
$price['regular_price'] = wc_rbp_price_types('regular_price') . ' : ';
$price['regular_price'] .= wc_price($pro->get_regular_price());
$price['selling_price'] = wc_rbp_price_types('selling_price') . ' : ';
$price['selling_price'] .= wc_price($pro->get_sale_price());
$this->hook_filter(FALSE);
$price = implode(' | ', $price);
}
$head = '<span class="headTxt">' . __("WC Product Price : ") . '</span>' . $price;
return $head;
}
public function hook_filter($hook = TRUE) {
if( $hook == TRUE ) {
add_filter('role_based_price_status', array( $this, 'base_price_return_false' ));
}
if( ! $hook == TRUE ) {
remove_filter('role_based_price_status', array( $this, 'base_price_return_false' ));
}
}
public function base_price_return_false($s) {
return FALSE;
}
}
return new WooCommerce_Role_Based_Price_Product_Metabox;
\ No newline at end of file
<?php
/**
* The admin-specific functionality of the plugin.
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
* @package Role Based Price For WooCommerce
* @subpackage Role Based Price For WooCommerce/Admin
* @since 3.0
*/
if( ! defined('WPINC') ) {
die;
}
class WooCommerce_Role_Based_Price_Admin_Price_Editor_Fields {
public function __construct() {
add_action("wc_rbp_before_metabox_content", array( $this, 'register_price_fields' ));
add_filter('wc_rbp_before_default_product_tabs', array( $this, 'add_general_tab' ));
add_action('wc_rbp_price_edit_tab_general', array( $this, 'add_status_field' ), 10, 4);
}
public function add_general_tab($tabs) {
$tabs['general'] = array( 'title' => __('General', WC_RBP_TXT),
'icon' => 'dashicons-admin-tools',
'show_status' => FALSE,
);
return $tabs;
}
public function add_status_field($product_id, $prodType, $prod, $tab_id) {
$status = product_rbp_status($product_id) == 'true' ? 'checked' : '';
$content = '<div class="wc_rbp_price_container wc_rbp_popup_section wc_rbp_popup_section_' . $tab_id . '">';
$content .= '<div class="enable_field_container">';
$content .= '<p class="form-field ">';
$content .= '<label class="enable_text" for="enable_role_based_price">' . __('Enable Role Based Pricing', WC_RBP_TXT) . ' </label> ';
$content .= ' <input type="checkbox" data-secondaryColor="#999" data-size="small" class="wc_rbp_checkbox" id="enable_role_based_price" name="enable_role_based_price" ' . $status . '/> ';
$content .= '</p>';
$content .= '</div>';
$content .= '</div>';
echo $content;
}
public function register_price_fields() {
$allowed_roles = wc_rbp_allowed_roles();
foreach( $allowed_roles as $role ) {
add_action('wc_rbp_price_edit_tab_' . $role, array( $this, 'generate_price_field' ), 10, 4);
}
}
public function generate_price_field($product_id, $prodType, $prod, $tab_id) {
global $product;
$allowed_price = wc_rbp_allowed_price();
$price_exists = wc_rbp_price_types();
$output_html = '<div class="wc_rbp_price_container wc_rbp_popup_section wc_rbp_popup_section_' . $tab_id . '">';
foreach( $allowed_price as $price ) {
$field_id = 'role_based_price[' . $tab_id . '][' . $price . ']';
$defaults = array(
'type' => 'text',
'label' => $price_exists[$price],
'description' => __('Enter Product\'s ') . $price_exists[$price],
'class' => array(),
'label_class' => array(),
'input_class' => array( 'wc_input_price', $price, 'wc_rbp_' . $price ),
'return' => TRUE,
'custom_attributes' => array(),
);
$output_html .= '<div class="wc_rbp_pop_field_50 wc_rbp_pop_field_' . $price . '">';
$price = wc_rbp_price($product_id, $tab_id, $price);
$output_html .= woocommerce_form_field($field_id, $defaults, $price);
$output_html .= '</div>';
}
$output_html .= '</div>';
echo $output_html;
}
}
return new WooCommerce_Role_Based_Price_Admin_Price_Editor_Fields;
\ No newline at end of file
<?php
/**
* WooCommerce Product Role Based Price Edit Functions
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
* @package Role Based Price For WooCommerce
* @subpackage Role Based Price For WooCommerce/Admin
* @since 3.0
*/
if( ! defined('WPINC') ) {
die;
}
class WooCommerce_Role_Based_Price_Admin_Product_Functions {
public function __construct() {
add_action('wc_rbp_product_save_default', array( $this, 'simple_save_product_price' ), 1, 3);
}
public function simple_save_product_price(&$posted_values, &$success, &$error) {
$post_id = $posted_values['product_id'];
do_action_ref_array('wc_rbp_product_save_before', array( &$posted_values ));
if( isset($posted_values['role_based_price']) ) {
$status = isset($posted_values['enable_role_based_price']) ? TRUE : FALSE;
wc_rbp_update_role_based_price_status($post_id, $status);
wc_rbp_update_role_based_price($post_id, $posted_values['role_based_price']);
clean_post_cache($post_id);
$success['html'] = '<h3>' . __("Product Price Updated.", WC_RBP_TXT) . '</h3>';
} else {
$error['html'] = '<h3>' . __("Price Not Defined. Please Try Again", WC_RBP_TXT) . '</h3>';
}
do_action_ref_array('wc_rbp_product_save_after', array( &$posted_values ));
}
}
return new WooCommerce_Role_Based_Price_Admin_Product_Functions;
\ No newline at end of file
<?php
/**
* The admin-specific functionality of the plugin.
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
* @package Role Based Price For WooCommerce
* @subpackage Role Based Price For WooCommerce/Admin
* @since 3.0
*/
if( ! defined('WPINC') ) {
die;
}
class WooCommerce_Role_Based_Price_Admin_Settings_Options {
public function __construct() {
add_filter('wc_rbp_settings_pages', array( $this, 'settings_pages' ));
add_filter('wc_rbp_settings_section', array( $this, 'settings_section' ));
add_filter('wc_rbp_settings_fields', array( $this, 'settings_fields' ));
}
public function settings_pages($page) {
$page[] = array( 'id' => 'general', 'slug' => 'general', 'title' => __('General', WC_RBP_TXT) );
$page[] = array(
'id' => 'addonssettings',
'slug' => 'addonssettings',
'title' => __('Extensions Options', WC_RBP_TXT),
);
$page[] = array( 'id' => 'addons', 'slug' => 'wcrbpaddons', 'title' => __('Extensions', WC_RBP_TXT) );
return $page;
}
public function settings_section($section) {
$section['general'][] = array( 'id' => 'general', 'title' => __('General', WC_RBP_TXT) );
$section['addons'][] = array( 'id' => 'addons', 'title' => '' );
$addonSettings = array(
'addon_sample' => array(
'id' => 'addonssettings',
'title' => __('No Addons Activated / Installed.', WC_RBP_TXT),
),
);
$addonSettings = apply_filters('wc_rbp_addon_sections', $addonSettings);
if( count($addonSettings) > 1 )
unset($addonSettings['addon_sample']);
$section['addonssettings'] = $addonSettings;
return $section;
}
public function settings_fields($fields) {
$fields['general']['general'][] = array(
'id' => WC_RBP_DB . 'allowed_roles',
'multiple' => 'true',
'type' => 'select',
'label' => __('Allowed User Roles', WC_RBP_TXT),
'desc' => __('User Roles To List In Product Edit Page', WC_RBP_TXT),
'options' => wc_rbp_sort_array_by_array(wc_rbp_get_user_roles_selectbox(), wc_rbp_allowed_roles()),
'attr' => array(
'class' => 'wc-rbp-enhanced-select',
'multiple' => 'multiple',
),
);
$fields['general']['general'][] = array(
'id' => WC_RBP_DB . 'allowed_price',
'type' => 'select',
'multiple' => TRUE,
'label' => __('Allowed Product Pricing', WC_RBP_TXT),
'desc' => __('Price Fields To List In Product Edit Page', WC_RBP_TXT),
'options' => wc_rbp_sort_array_by_array(wc_rbp_avaiable_price_type(), wc_rbp_allowed_price()),
'attr' => array(
'class' => 'wc-rbp-enhanced-select',
'style' => 'width:auto;max-width:35%;',
'multiple' => 'multiple',
),
);
$price_type = wc_rbp_avaiable_price_type();
foreach( $price_type as $pK => $pV ) {
$fields['general']['general'][] = array(
'id' => WC_RBP_DB . $pK . '_label',
'type' => 'text',
'label' => $pV . __(' Label ', WC_RBP_TXT),
'default' => $pV,
'attr' => array(
'style' => 'width:auto;max-width:35%;',
),
);
}
if( class_exists('woocommerce_wpml') ) {
$fields['general']['general'][] = array(
'id' => WC_RBP_DB . 'enable_wpml_integration',
'type' => 'checkbox',
'label' => __('WPML Integration', WC_RBP_TXT),
'desc' => __('check if you have installed wpml and the price are showing wrong. ', WC_RBP_TXT),
'attr' => array( 'class' => 'wc_rbp_checkbox', ),
);
}
$addonSettings = array( 'addon_sample' => array() );
$addonSettings = apply_filters('wc_rbp_addon_fields', $addonSettings);
unset($addonSettings['addon_sample']);
$fields['addonssettings'] = $addonSettings;
return $fields;
}
}
return new WooCommerce_Role_Based_Price_Admin_Settings_Options;
\ No newline at end of file
<?php
/**
* Class for registering settings and sections and for display of the settings form(s).
* For detailed instructions see: https://github.com/keesiemeijer/WP-Settings
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
* @package Role Based Price For WooCommerce
* @subpackage Role Based Price For WooCommerce/WordPress/Settings
* @since 3.0
* @version 2.0
* @author keesiemeijer
*/
if( ! defined('WPINC') ) {
die;
}
class WooCommerce_Role_Based_Price_Settings_Framework {
public $settings;
private $page_hook = '';
private $settings_page;
private $settings_section;
private $settings_fields;
private $create_function;
private $settings_key;
private $settings_values;
function __construct($page_hook = '') {
$this->settings_section = array();
$this->settings_fields = array();
$this->create_function = array();
$this->add_settings_pages();
//$this->get_settings();
$this->add_settings_section();
$this->create_callback_function();
$this->page_hook = $page_hook;
if( empty($page_hook) ) {
add_action('admin_menu', array( $this, 'admin_menu' ));
}
add_action('admin_init', array( $this, 'admin_init' ));
}
private function add_settings_pages() {
$pages = array();
$pages = apply_filters('wc_rbp_settings_pages', $pages);
$this->settings_page = $pages;
}
private function add_settings_section() {
$section = array();
$section = apply_filters('wc_rbp_settings_section', $section);
$this->settings_section = $section;
}
private function create_callback_function() {
$sec = $this->settings_section;
foreach( $sec as $sk => $s ) {
if( is_array($s) ) {
$c = count($s);
$a = 0;
while( $a < $c ) {
if( isset($s[$a]['validate_callback']) ) {
$this->create_function[] = $s[$a]['id'];
$s[$a]['validate_callback'] = '';
$file = addslashes(WC_RBP_SETTINGS . 'validate-' . $s[$a]['id'] . '.php');
$s[$a]['validate_callback'] = create_function('$fields', 'do_action("wc_rbp_settings_validate",$fields); do_action("wc_rbp_settings_validate_' . $s[$a]['id'] . '",$fields);');
}
$a++;
}
}
$this->settings_section[$sk] = $s;
}
}
function admin_menu() {
$this->page_hook = add_submenu_page('woocommerce', __('Role Based Price Settings', WC_RBP_TXT), __('Role Based Price Settings', WC_RBP_TXT), 'manage_woocommerce', WC_RBP_SLUG . '-settings', array(
$this,
'admin_page',
));
}
function admin_init() {
$this->settings = new WooCommerce_Role_Based_Price_WP_Settings();
$this->add_settings_fields();
$this->settings->add_pages($this->settings_page);
$sections = $this->settings_section;
foreach( $sections as $page_id => $section_value ) {
$pages = $this->settings->add_sections($page_id, $section_value);
}
$fields = $this->settings_field;
foreach( $fields as $page_id => $section_fields ) {
foreach( $section_fields as $section_id => $sfields ) {
if( is_array($sfields) ) {
foreach( $sfields as $f ) {
$pages = $this->settings->add_field($page_id, $section_id, $f);
}
} else {
$pages = $this->settings->add_field($page_id, $section_id, $sfields);
}
}
}
$this->settings->init($pages, WC_RBP_DB);
}
private function add_settings_fields() {
global $fields;
$fields = array();
$fields = apply_filters('wc_rbp_settings_fields', $fields);
$this->settings_field = $fields;
}
public function admin_page() {
echo '<div class="wrap wc_rbp_settings">';
settings_errors();
$this->settings->render_header();
//echo $this->settings->debug;
$this->settings->render_form();
echo '</div>';
}
function get_option($id = '') {
if( ! empty($this->settings_values) && ! empty($id) ) {
if( isset($this->settings_values[$id]) ) {
return $this->settings_values[$id];
}
}
return FALSE;
}
function get_settings($key = '') {
$values = array();
foreach( $this->settings_page as $settings ) {
$this->settings_key[] = WC_RBP_DB . $settings['slug'];
$db_val = get_option(WC_RBP_DB . $settings['slug']);
if( is_array($db_val) ) {
unset($db_val['section_id']);
$values = array_merge($db_val, $values);
}
}
$this->settings_values = $values;
return $values;
}
}
\ No newline at end of file
<?php echo $category; ?>
<div class="wp-list-table widefat plugin-install">
<div class="the-list wc_rbp_addon_listing">
\ No newline at end of file
<?php
$slug = $wc_rbp_plugin_data['addon_slug'];
$cat_slug = implode(' wc-rbp-addon-', array_keys($wc_rbp_plugin_data['Category']));
$wrapperClass = 'plugin-card plugin-card-' . $slug . ' wc-rbp-addon-all wc-rbp-addon-' . $cat_slug;
if( $wc_rbp_plugin_data['is_active'] ) {
$wrapperClass .= ' wc-rbp-addon-active';
} else {
$wrapperClass .= ' wc-rbp-addon-inactive';
}
?>
<div class="<?php echo $wrapperClass; ?>" id="<?php echo $slug; ?>">
<?php wc_rbp_get_ajax_overlay(); ?>
<div class="plugin-card-top">
<div class="name column-name">
<h3>
<?php echo $wc_rbp_plugin_data['Name']; ?>
[
<small><?php _e('V', WC_RBP_TXT); ?><?php echo $wc_rbp_plugin_data['Version']; ?></small>
]
<?php $this->get_addon_icon($wc_rbp_plugin_data); ?>
</h3>
</div>
<div class="desc column-description">
<p><?php echo $wc_rbp_plugin_data['Description']; ?></p>
<p class="authors">
<cite>
<?php _e('By', WC_RBP_TXT); ?>
<a href="<?php echo $wc_rbp_plugin_data['AuthorURI']; ?>"> <?php echo $wc_rbp_plugin_data['Author']; ?></a>
</cite>
</p>
</div>
</div>
<div class="plugin-card-top wc-rbp-addons-required-plugins">
<?php if( ! empty($required_plugins) ): ?>
<div>
<h3><?php _e('Required Plugins :', WC_RBP_TXT); ?></h3>
<ul>
<?php
$echo = '';
foreach( $required_plugins as $plugin ) {
$plugin_status = $this->check_plugin_status($plugin['Slug']);
$status_val = __('InActive', WC_RBP_TXT);
$class = 'deactivated';
if( $plugin_status === 'notexist' ) {
$status_val = __('Plugin Does Not Exist', WC_RBP_TXT);
$class = 'notexist';
} else if( $plugin_status === TRUE ) {
$status_val = __('Active', WC_RBP_TXT);
$class = 'active';
}
if( ! isset($plugin['Version']) ) {
$plugin['version'] = '';
}
echo '<li class="' . $class . '">';
echo '<span class="wc_rbp_required_addon_plugin_name"> <a href="' . $plugin['URL'] . '" > ' . $plugin['Name'] . ' [' . $plugin['Version'] . '] </a> </span> : ';
echo '<span class="wc_rbp_required_addon_plugin_status ' . $class . '">' . $status_val . '</span>';
echo '</li>';
unset($plugin_status);
}
?>
</ul>
<?php /*<p> <span><?php _e('Above Mentioned Plugin name with version are Tested Up to',WC_RBP_TXT);?></span> </p> */ ?>
</div>
<?php endif; ?>
<?php if( ! empty($wc_rbp_plugin_data['screenshots']) ) : ?>
<div class="addon-screenshots">
<h3><?php _e("Screenshots", WC_RBP_TXT); ?></h3>
<ul>
<?php
$i = 1;
$url = $wc_rbp_plugin_data['addon_url'];
foreach( $wc_rbp_plugin_data['screenshots'] as $screen ) {
echo '<li><a class="thickbox" href="' . $url . basename($screen) . '?TB_iframe=true">' . $i . '</a></li>';
$i++;
}
?>
</ul>
</div>
<?php endif; ?>
<small><strong><?php _e('Addon Slug : ', WC_RBP_TXT); ?></strong><?php echo $wc_rbp_plugin_slug; ?></small>
</div>
<div class="plugin-card-bottom">
<div class="column-updated" data-pluginslug="<?php echo $slug; ?>">
<?php echo $this->get_addon_action_button($wc_rbp_plugin_slug, $required_plugins); ?>
</div>
<div class="column-downloaded"><strong><?php _e('Last Updated:', WC_RBP_TXT); ?></strong>
<span title="<?php echo $wc_rbp_plugin_data['last_update']; ?>"><?php echo $wc_rbp_plugin_data['last_update']; ?></span>
</div>
<div class="column-downloaded wc_rbp_ajax_response"></div>
</div>
</div>
\ No newline at end of file
<div class="wc_rbp_price_editor_footer">
<p>
<button name="close" onclick="Custombox.close();" id="close_modal"
class="button button-secondary"> <?php _e('Close', WC_RBP_TXT); ?> </button>
<button name="update_price" id="update_price"
class="button button-primary"> <?php _e('Update Price', WC_RBP_TXT); ?> </button>
</p>
</div>
</div>
</div>
\ No newline at end of file
<div class="wc-rbp-modal wc-rbp-modal-ajax" style="display: block;">
<button type="button" class="close" onclick="Custombox.close();"><span>&times;</span></button>
<h4 class="title"><?php _e('Role Based Price Editor'); ?> </h4>
<div class="wc-rbp-modal-content text">
\ No newline at end of file
<?php global $type, $product_id; ?>
<div class="wc_rbp_price_editor_fields" style="display:none;">
<form method="post" action="<?php echo admin_url('admin-ajax.php'); ?>" id="wc_rbp_price_editor_form">
<div class="wc_rbp_hidden_fields">
<?php echo wc_rbp_get_editor_fields($type); ?>
</div>
<div class="hide hidden wc_rbp_price_editor_ajax_response"></div>
<?php
$tabs = array();
$allowed_roles = wc_rbp_allowed_roles();
$registered_roles = wc_rbp_get_wp_roles();
foreach( $allowed_roles as $role ) {
if( isset($registered_roles[$role]) ) {
$tabs[$role] = $registered_roles[$role]['name'];
}
}
$tabs = apply_filters('wc_rbp_price_editor_tabs', $tabs, $product_id, $type);
$tab_pos = wc_rbp_option('price_editor_tab_pos');
extract(wc_rbp_get_tab_pos($tab_pos));
if( $type == 'simple' ) {
echo '<input type="hidden" name="product_id" value="' . $product_id . '" /> ';
}
do_action('wc_rbp_price_edit_top', $product_id, $type);
echo '<div class="tab_container">';
echo '<div class="wc_rbp_tabs" data-tabsPosition="' . $tab_pos . '"
data-horizontalPosition="' . $horizontalPosition . '"
data-verticalPosition="' . $verticalPosition . '">';
foreach( $tabs as $tabID => $name ) {
echo '<div data-pws-tab-name="' . $name . '" data-pws-tab="' . $tabID . '" class="pws_hide pws_tab_single" data-pws-tab-id="' . $tabID . '">';
do_action('wc_rbp_price_edit_tab_before', $product_id, $type, $tabID);
do_action('wc_rbp_price_edit_tab_' . $tabID . '_before', $product_id, $type, $tabID);
do_action('wc_rbp_price_edit_tab_' . $tabID, $product_id, $type, $tabID);
do_action('wc_rbp_price_edit_tab_' . $tabID . '_after', $product_id, $type, $tabID);
do_action('wc_rbp_price_edit_tab_after', $product_id, $type, $tabID);
echo '</div>';
}
echo '</div>';
echo '</div>';
do_action('wc_rbp_price_edit_bottom', $product_id, $type);
?>
</form>
</div>
\ No newline at end of file
<div class="wrap about-wrap">
<h1><?php _e("Welcome To", WC_RBP_TXT);
echo ' ' . __("Role Based Price For WooCommerce", WC_RBP_TXT) . ' ' . WC_RBP_V; ?></h1>
<p class="about-text">
<?php echo WC_RBP_NAME;
_e(" now with improved speed and stability"); ?>
</p>
<div class="wp-badge"><?php echo WC_RBP_V; ?></div>
</div>
<style>
.wp-badge {
background-image : url("https://plugins.svn.wordpress.org/woocommerce-role-based-price/assets/icon-256x256.jpg") !important;
background-position : center top !important;
background-size : 100% auto !important;
padding-top : 140px !important;
padding-bottom : 3px !important;
height : auto !important;
}
</style>
\ No newline at end of file
<?php
/**
* Dependency Checker
*
* Checks if required Dependency plugin is enabled
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
* @package Role Based Price For WooCommerce
* @subpackage Role Based Price For WooCommerce/FrontEnd
* @since 3.0
*/
if( ! defined('WPINC') ) {
die;
}
class WooCommerce_Role_Based_Price_Functions {
/**
* Define the core functionality of the plugin.
*
* Set the plugin name and the plugin version that can be used throughout the plugin.
* Load the dependencies, define the locale, and set the hooks for the admin area and
* the public-facing side of the site.
*
* @since 1.0.0
*/
public function __construct() {
add_filter('woocommerce_product_object', array( $this, 'setup_product_prices' ));
}
public function setup_product_prices($product) {
if( $product == NULL ) {
return $product;
}
$product->wc_rbp = wc_rbp_get_product_price($product->ID);
$product->wc_rbp_status = wc_rbp_product_status($product->ID);
do_action_ref_array('wc_rbp_product_class_attribute', array( &$product ));
return $product;
}
}
\ No newline at end of file
<?php
/**
* Simple Product Role Based Price Settings
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
* @since 1.0
* @package WooCommerce_Role_Based_Price
* @subpackage WooCommerce_Role_Based_Price/admin
* @author Varun Sridharan <varunsridharan23@gmail.com>
*/
if( ! defined('WPINC') ) {
exit;
}
class WooCommerce_Role_Based_Price_Shortcode_Handler {
private static $_instance = NULL;
private static $db_prices = NULL;
public function __construct() {
add_shortcode('wc_rbp', array( $this, 'shortcodehandler' ));
}
function is_aeliacs_active() {
return isset($GLOBALS['woocommerce-aelia-currencyswitcher']) && is_object($GLOBALS['woocommerce-aelia-currencyswitcher']);
}
public function shortcodehandler($attrs) {
$vars = shortcode_atts(array(
'id' => NULL,
'price' => 'regular_price',
'role' => 'current',
), $attrs, 'wc_rbp');
if( $vars['id'] == NULL ) {
global $product;
$id = '';
if( wc_rbp_is_wc_v('>=', '3.0.1') ) {
$id = $product->get_id();
} else {
$product->id;
}
if( ! isset($id) ) {
return __('Invalid Product ID Given', WC_RBP_TXT);
}
$vars['id'] = $id;
}
if( $vars['role'] == NULL ) {
return __('Invalid User Role Given', WC_RBP_TXT);
}
if( $vars['price'] == 'product_regular_price' || $vars['price'] == 'product_selling_price' ) {
return self::get_base_product_price($vars['id'], $vars['price']);
}
if( $vars['price'] != 'regular_price' && $vars['price'] != 'selling_price' ) {
return __('Invalid Price Type Given', WC_RBP_TXT);
}
$product_status = product_rbp_status($vars['id']);
$this->rbpPP = '';
if( $product_status ) {
$this->rbpPP = new WooCommerce_Role_Based_Price_Product_Pricing;
if( $vars['role'] == 'current' ) {
$vars['role'] = wc_rbp_get_current_user();
}
return self::get_selprice($vars['role'], $vars['price'], $vars['id']);
}
return '';
}
public function get_base_product_price($id, $price) {
if( ! defined('WC_RBP_SHORTCODE_PRODUCT_BASE_PRICING') ) {
define('WC_RBP_SHORTCODE_PRODUCT_BASE_PRICING', TRUE);
}
$product = new WC_Product($id);
if( $price == 'product_regular_price' ) {
return $product->get_regular_price();
}
if( $price == 'product_selling_price' ) {
return $product->get_sale_price();
}
}
public function get_selprice($role, $price = 'all', $product_id) {
$product = wc_get_product($product_id);
$p = $this->rbpPP->get_product_price('', $product, $price, $role);
return wc_price($p);
}
}
\ No newline at end of file
<?php
/**
* Fired during plugin activation.
*
* This class defines all code necessary to run during the plugin's activation.
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
* @package Role Based Price For WooCommerce
* @subpackage Role Based Price For WooCommerce/core
* @since 3.0
*/
class WooCommerce_Role_Based_Price_Activator {
public function __construct() {
}
/**
* Short Description. (use period)
*
* Long Description.
*
* @since 1.0.0
*/
public static function activate() {
require_once( WC_RBP_INC . 'helpers/class-version-check.php' );
require_once( WC_RBP_INC . 'helpers/class-dependencies.php' );
if( WooCommerce_Role_Based_Price_Dependencies(WC_RBP_DEPEN) ) {
WooCommerce_Role_Based_Price_Version_Check::activation_check('3.7');
$message = '<h3> <center> ' . __("Thank you for installing <strong>Role Based Price For WooCommerce</strong> : <strong>Version 3.0 </strong>", WC_RBP_TXT) . '</center> </h3>';
$message .= '<p>' . __("We have worked entire 1 year to improve our plugin to best of our ability and we hope you will enjoy working with it. We are always open for your sugestions and feature requests", WC_RBP_TXT) . '</p>';
$message .= '</hr>';
$message .= '<p>' . __("If you have installed <strong>WPRB</strong> for the 1st time or upgrading from <strong> Version 2.8.7</strong> then you will need to update its' settings once again or this plugin will not function properly. ", WC_RBP_TXT);
$url = admin_url('admin.php?page=woocommerce-role-based-price-settings');
$message .= '<a href="' . $url . '" class="button button-primary">' . __("Click Here to update the settings", WC_RBP_TXT) . '</a> </p>';
wc_rbp_admin_update($message, 1, 'activate_message', array(), array( 'wraper' => FALSE, 'times' => 1 ));
set_transient('_welcome_redirect_wcrbp', TRUE, 60);
} else {
if( is_plugin_active(WC_RBP_FILE) ) {
deactivate_plugins(WC_RBP_FILE);
}
wp_die(wc_rbp_dependency_message());
}
}
}
\ No newline at end of file
<?php
/**
* Fired during plugin deactivation.
*
* This class defines all code necessary to run during the plugin's deactivation.
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
* @package Role Based Price For WooCommerce
* @subpackage Role Based Price For WooCommerce/core
* @since 3.0
*/
class WooCommerce_Role_Based_Price_Deactivator {
/**
* Short Description. (use period)
*
* Long Description.
*
* @since 1.0.0
*/
public static function deactivate() {
}
public static function dependency_deactivate() {
if( is_plugin_active(WC_RBP_FILE) ) {
add_action('update_option_active_plugins', array( __CLASS__, 'deactivate_dependent' ));
}
}
public static function deactivate_dependent() {
delete_transient('_welcome_redirect_wcrbp');
deactivate_plugins(WC_RBP_FILE);
}
}
\ No newline at end of file
<?php
/**
* Dependency Checker
*
* Checks if required Dependency plugin is enabled
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
* @package Role Based Price For WooCommerce
* @subpackage Role Based Price For WooCommerce/core
* @since 3.0
*/
if( ! class_exists('WooCommerce_Role_Based_Price_Dependencies') ) {
class WooCommerce_Role_Based_Price_Dependencies {
private static $active_plugins;
public static function init() {
self::$active_plugins = (array) get_option('active_plugins', array());
if( is_multisite() )
self::$active_plugins = array_merge(self::$active_plugins, get_site_option('active_sitewide_plugins', array()));
}
public static function active_check($pluginToCheck = '') {
if( ! self::$active_plugins )
self::init();
return in_array($pluginToCheck, self::$active_plugins) || array_key_exists($pluginToCheck, self::$active_plugins);
}
}
}
/**
* WC Detection
*/
if( ! function_exists('WooCommerce_Role_Based_Price_Dependencies') ) {
function WooCommerce_Role_Based_Price_Dependencies($pluginToCheck = 'woocommerce/woocommerce.php') {
return WooCommerce_Role_Based_Price_Dependencies::active_check($pluginToCheck);
}
}
?>
\ No newline at end of file
<?php
/**
* Check the version of WordPress
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
* @package Role Based Price For WooCommerce
* @subpackage Role Based Price For WooCommerce/core
* @since 3.0
*/
class WooCommerce_Role_Based_Price_Version_Check {
static $version;
/**
* The primary sanity check, automatically disable the plugin on activation if it doesn't meet minimum requirements
*
* @since 1.0.0
*/
public static function activation_check($version) {
self::$version = $version;
if( ! self::compatible_version() ) {
deactivate_plugins(WC_RBP_FILE);
wp_die(__(WC_RBP_NAME . ' requires WordPress ' . self::$version . ' or higher!', WC_RBP_TXT));
}
}
/**
* Check current version against $prefix_version_check
*
* @since 1.0.0
*/
public static function compatible_version() {
if( version_compare($GLOBALS['wp_version'], self::$version, '<') ) {
return FALSE;
}
return TRUE;
}
/**
* The backup sanity check, in case the plugin is activated in a weird way, or the versions change after activation
*
* @since 1.0.0
*/
public function check_version() {
if( ! self::compatible_version() ) {
if( is_plugin_active(WC_RBP_FILE) ) {
deactivate_plugins(WC_RBP_FILE);
add_action('admin_notices', array( $this, 'disabled_notice' ));
if( isset($_GET['activate']) ) {
unset($_GET['activate']);
}
}
}
}
/**
* Text to display in the notice
*
* @since 1.0.0
*/
public function disabled_notice() {
echo '<strong>' . esc_html__(WC_RBP_NAME . ' requires WordPress ' . self::$version . ' or higher!', WC_RBP_TXT) . '</strong>';
}
}
\ No newline at end of file
;
( function( $, window, document ) {
'use strict';
$.WCRBP = $.WCRBP || {};
/**
* Global Functions
*/
/* $.WCRBP.validate_selling_price = function (e) {
var sale_price_field = $(this),
regular_price_field;
regular_price_field = sale_price_field.parents('.wc_rbp_price_container').find('.wc_rbp_regular_price');
var sale_price = parseFloat(window.accounting.unformat(sale_price_field.val(), woocommerce_admin.mon_decimal_point));
var regular_price = parseFloat(window.accounting.unformat(regular_price_field.val(), woocommerce_admin.mon_decimal_point));
if ( sale_price >= regular_price ) {
$(document.body).triggerHandler('wc_add_error_tip', [$(this), 'i18_sale_less_than_regular_error']);
if ( 'change' === e.type ) {
if ( sale_price >= regular_price ) {
$(this).val('');
$('div#wc-rbp-product-editor #wc_rbp_update_price').removeAttr('disabled');
}
} else {
$('div#wc-rbp-product-editor #wc_rbp_update_price').attr('disabled', 'disabled');
}
} else {
$(document.body).triggerHandler('wc_remove_error_tip', [$(this), 'i18_sale_less_than_regular_error']);
$('div#wc-rbp-product-editor #wc_rbp_update_price').removeAttr('disabled');
}
};*/
$.WCRBP.tab_navigation = function( e ) {
e.preventDefault();
var $li = jQuery( this ).parent(),
panel = $li.data( 'panel' ),
$wrapper = $li.closest( '.wcrbp-tabs' ),
$panel = $wrapper.find( '.wcrbp-tab-panel-' + panel );
$li.addClass( 'wcrbp-tab-active' ).siblings().removeClass( 'wcrbp-tab-active' );
$panel.show().siblings().hide();
};
$.WCRBP.render_wootabs = function() {
$( ".wcrbp-tab-nav" ).on( "click", 'a', $.WCRBP.tab_navigation );
if( !$( '.wcrbp-tab-active' ).is( 'visible' ) ) {
var activePane = $( '.wcrbp-tab-panel[style*="block"]' ).index();
if( activePane >= 0 ) {
$( '.wcrbp-tab-nav li' ).removeClass( 'wcrbp-tab-active' );
$( '.wcrbp-tab-nav li' ).eq( activePane ).addClass( 'wcrbp-tab-active' );
}
}
$( '.wcrbp-tab-active a' ).trigger( 'click' );
$( '.wcrbp-tabs-no-wrapper' ).closest( '.postbox' ).addClass( 'wcrbp-tabs-no-controls' );
};
$.WCRBP.block = function( $elem ) {
$elem.block( {
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6
}
} );
};
$.WCRBP.unblock = function( $elem ) {
$elem.unblock();
};
$.WCRBP.render_price_status = function() {
$( '.wcrbp-tab-nav > li' ).each( function() {
if( $( this ).attr( 'data-status' ) == 'yes' ) {
var $this = $( this ),
divClass = 'div.wcrbp-tab-panel-' + $this.attr( 'data-panel' ),
filled = 0,
unfilled = 0,
totalf = 0;
$( divClass ).find( 'input[type=text]' ).each( function() {
if( $( this ).hasClass( "include_count" ) || !$( this ).hasClass( "exclude_count" ) ) {
if( $( this ).val() == '' ) {
unfilled = unfilled + 1;
} else {
filled = filled + 1;
}
}
} );
totalf = filled + unfilled;
$this.find( '.wc-rbp-tab-status' ).removeClass( 'bgred' );
$this.find( '.wc-rbp-tab-status' ).removeClass( 'bggreen' );
$this.find( '.wc-rbp-tab-status' ).removeClass( 'bgblue' );
if( filled == 0 && unfilled > 0 ) {
$this.find( '.wc-rbp-tab-status' ).addClass( 'bgred' );
} else if( filled > 0 && unfilled > 0 ) {
$this.find( '.wc-rbp-tab-status' ).addClass( 'bgblue' );
} else if( filled > 0 && unfilled == 0 ) {
$this.find( '.wc-rbp-tab-status' ).addClass( 'bggreen' );
}
}
} );
};
$.WCRBP.add_variation_selectbox = function() {
if( $( ".wcrbpvariationbx" ).size() > 0 ) {
$( ".wcrbpvariationbx" ).appendTo( "#wc-rbp-product-editor .hndle span" );
}
if( jQuery( '.wcrbpvariationbx' ).size() > 0 ) {
jQuery( '.wcrbpvariationbx' ).selectize( {
plugins: [ 'remove_button', 'restore_on_backspace' ],
persist: false,
create: false,
onChange: function( value ) {
$.WCRBP.block( $( 'div#wc-rbp-product-editor div.inside' ) );
var $select = this;
var $parentID = $( 'input#post_ID' ).val();
$.ajax( {
url: ajaxurl + '?action=wc_rbp_metabox_refersh&pid=' + value + '&parentID=' + $parentID,
method: "GET",
data: '',
} ).done( function( response ) {
if( response.success === true ) {
$select.destroy();
$( '.wcrbpvariationbx' ).remove();
$( '#wc-rbp-product-editor .inside' ).html( response.data );
$.WCRBP.render_wootabs();
$.WCRBP.add_variation_selectbox();
$( "#wc-rbp-product-editor .inside input.wc_rbp_checkbox" ).wcrbp_checkbox();
$.WCRBP.unblock( $( 'div#wc-rbp-product-editor div.inside' ) );
$.WCRBP.render_price_status();
}
} )
}
} );
}
};
$.WCRBP.move_selectbox_metabox = function() {
$( '#wc-rbp-product-editor' ).find( '.hndle' ).unbind( 'click' );
$( '#wc-rbp-product-editor' ).on( 'click', '.hndle', function( event ) {
event.preventDefault();
if( $( event.target ).filter( 'input, option, label, select, div, span' ).size() ) {
jQuery( '#wc-rbp-product-editor' ).toggleClass( 'closed' );
}
return;
} );
};
$.WCRBP.action_save_product_prices = function() {
var $clickedBtn = $( this ),
$data = $( 'div#wc-rbp-product-editor :input' ).serialize(),
$form = $( '.wc-rbp-metabox-container' ),
$action = $form.attr( 'action' ),
$method = $form.attr( 'method' );
$clickedBtn.attr( 'disabled', 'disable' );
$.WCRBP.block( $( 'div#wc-rbp-product-editor div.inside' ) );
$.ajax( {
url: $action,
method: $method,
data: $data,
} ).done( function( data ) {
$clickedBtn.removeAttr( 'disabled' );
$.WCRBP.unblock( $( 'div#wc-rbp-product-editor div.inside' ) );
$( 'div.wc_rbp_hidden_fields' ).html( data.data.hidden_fields );
$( 'div.wc_rbp_price_editor_ajax_response' ).html( data.data.html ).fadeIn( 'slow' );
setTimeout( 2000, function() {
jQuery( 'div.wc_rbp_price_editor_ajax_response' ).fadeOut( 'slow' );
} );
} )
};
$.WCRBP.action_clear_product_prices = function() {
var $clickedBtn = $( this );
$clickedBtn.attr( 'disabled', 'disable' );
$.WCRBP.block( $( 'div#wc-rbp-product-editor div.inside' ) );
$.ajax( {
url: ajaxurl,
method: 'post',
data: { post_id: $( "#post_ID" ).val(), action: "wc_rbp_clear_variation_cache" }
} ).done( function( data ) {
$clickedBtn.removeAttr( 'disabled' );
$.WCRBP.unblock( $( 'div#wc-rbp-product-editor div.inside' ) );
$( 'div.wc_rbp_price_editor_ajax_response' ).html( data.data.html ).fadeIn( 'slow' );
setTimeout( 2000, function() {
jQuery( 'div.wc_rbp_price_editor_ajax_response' ).fadeOut( 'slow' );
} );
} )
};
$.WCRBP.basic_init_metabox = function() {
//$(document.body).on('keyup change', '.wc_rbp_selling_price', $.WCRBP.validate_selling_price);
if( $( "input.wc_rbp_checkbox" ).size() > 0 ) {
$( "input.wc_rbp_checkbox" ).wcrbp_checkbox();
}
if( $( ".wcrbpvariationbx" ).size() > 0 ) {
$.WCRBP.add_variation_selectbox();
}
if( $( ".wcrbp-tabs" ).size() > 0 ) {
$.WCRBP.block( $( 'div#wc-rbp-product-editor div.inside' ) );
$.WCRBP.render_wootabs();
$.WCRBP.move_selectbox_metabox();
$.WCRBP.render_price_status();
}
$( 'body' ).on( 'blur', '#wc-rbp-product-editor :input', function() {
$.WCRBP.render_price_status();
} );
$( "body" ).on( "click", 'div#wc-rbp-product-editor #wc_rbp_update_price', $.WCRBP.action_save_product_prices );
$( "body" )
.on( "click", 'div#wc-rbp-product-editor #wc_rbp_clear_trasient', $.WCRBP.action_clear_product_prices );
};
/**
* Internal Functions
*/
$.fn.wcrbp_checkbox = function() {
return this.each( function() {
var $this = $( this ),
size = $this.attr( 'data-size' ),
color = $this.attr( 'data-color' ),
secondaryColor = $this.attr( 'data-secondaryColor' ),
jackColor = $this.attr( "data-jackColor" ),
jackSecondaryColor = $this.attr( "data-jackSecondaryColor" ),
className = $this.attr( "data-className" ),
disabled = $this.attr( 'data-disabled' ),
disabledOpacity = $this.attr( "data-disabledOpacity" ),
speed = $this.attr( "data-speed" );
new Switchery( this, {
size: size,
color: color,
secondaryColor: secondaryColor,
jackColor: jackColor,
jackSecondaryColor: jackSecondaryColor,
className: className,
disabled: disabled,
disabledOpacity: disabledOpacity,
speed: speed
} );
} );
};
$( document ).ready( function() {
$.WCRBP.basic_init_metabox();
} );
$( window ).load( function() {
if( $( '#wc-rbp-product-editor' ).size() > 0 ) {
$.WCRBP.move_selectbox_metabox();
$.WCRBP.unblock( $( 'div#wc-rbp-product-editor div.inside' ) );
}
} )
} )( jQuery, window, document );
;
( function ($, window, document, undefined) {
'use strict';
$.WCRBP_SETTINGS = $.WCRBP_SETTINGS || {};
$.WCRBP_SETTINGS.addons_html = '';
$.WCRBP_SETTINGS.http_reffer = '';
$.WCRBP_SETTINGS.handle_settings_page_url = function () {
var id = window.location.hash;
jQuery('.wc_rbp_settings_submenu a').removeClass('current');
jQuery('.wc_rbp_settings_submenu a[href="' + id + '" ]').addClass('current');
if ( id == '' ) {
jQuery('.wc_rbp_settings_submenu a:first').addClass('current');
id = jQuery('.wc_rbp_settings_submenu a:first').attr('href');
}
$.WCRBP_SETTINGS.http_reffer = jQuery('input[name=_wp_http_referer').val();
$.WCRBP_SETTINGS.show_settings(id);
}
$.WCRBP_SETTINGS.show_settings = function (elem) {
jQuery('div.wc_rbp_settings_content').hide();
elem = elem.replace('#', '#settings_');
jQuery(elem).show();
}
$.WCRBP_SETTINGS.settings_click_handler = function () {
var id = jQuery(this).attr('href');
jQuery('.wc_rbp_settings_submenu a').removeClass('current');
jQuery(this).addClass('current');
$.WCRBP_SETTINGS.show_settings(id);
jQuery('input[name=_wp_http_referer').val($.WCRBP_SETTINGS.http_reffer + id);
}
$.WCRBP_SETTINGS.handle_activate_deactivate_addons = function (elem, $class) {
if ( typeof ( $class ) === 'undefined' ) $class = '.wc-rbp-deactivate-now';
var clicked = elem;
var slug = elem.parent().attr('data-pluginslug');
var parent_div = '.plugin-card-' + slug;
var height = jQuery(parent_div).innerHeight();
var width = jQuery(parent_div).innerWidth();
jQuery(parent_div + ' .wc_rbp_ajax_overlay').css('height', height + 'px').css('width', width + 'px').fadeIn();
clicked.attr('disabled', 'disable');
var link = clicked.attr('href');
jQuery.ajax({
method: 'GET',
url: link,
}).done(function (response) {
var status = response.success;
jQuery(parent_div + ' .wc_rbp_ajax_overlay').fadeOut();
clicked.removeAttr('disabled');
if ( status ) {
clicked.hide();
jQuery(parent_div).find($class).fadeIn();
}
jQuery(parent_div).find('.wc_rbp_ajax_response').hide().html(response.data.msg).fadeIn(function () {
setTimeout(function () {
jQuery(parent_div).find('.wc_rbp_ajax_response').fadeOut();
}, 5000);
});
jQuery.ajax({
method: 'GET',
url: ajaxurl + '?action=wc_rbp_get_addons_html',
}).done(function (response) {
addons_html = jQuery(response);
});
});
}
$(document).ready(function () {
if ( jQuery('div.wc_rbp_addon_listing').size() > 0 ) {
jQuery('p.submit').remove();
}
jQuery('select.wc-rbp-enhanced-select').selectize({
plugins: ['remove_button', 'restore_on_backspace', 'drag_drop'],
persist: false,
create: true,
});
jQuery('.wc_rbp_settings_submenu a').click($.WCRBP_SETTINGS.settings_click_handler);
if ( jQuery('.wc_rbp_settings_submenu').size() > 0 ) {
$.WCRBP_SETTINGS.handle_settings_page_url();
}
jQuery('.wc_rbp_addon_listing').on('click', '.wc-rbp-activate-now', function () {
$.WCRBP_SETTINGS.handle_activate_deactivate_addons(jQuery(this), '.wc-rbp-deactivate-now')
});
jQuery('.wc_rbp_addon_listing').on('click', '.wc-rbp-deactivate-now', function () {
$.WCRBP_SETTINGS.handle_activate_deactivate_addons(jQuery(this), '.wc-rbp-activate-now')
});
$.WCRBP_SETTINGS.addons_html = jQuery('.wc_rbp_addon_listing').clone();
jQuery('ul.wc_rbp_addons_category li a:first').addClass('current');
jQuery('ul.wc_rbp_addons_category li a').click(function () {
var cat = jQuery(this).attr('data-category');
var NewDis = 'div.wc-rbp-addon-' + cat;
jQuery('ul.wc_rbp_addons_category li a').removeClass('current');
jQuery(this).addClass('current');
jQuery('.wc_rbp_addon_listing').html($.WCRBP_SETTINGS.addons_html.find(NewDis).clone());
});
jQuery('ul.wc_rbp_addons_category li a').each(function () {
var category = jQuery(this).attr('data-category');
var catCount = jQuery('.wc-rbp-addon-' + category).size();
jQuery(this).append(' <span class="catCount"> (' + catCount + ') </span>');
});
jQuery('div.addons-search-form input.wp-filter-search').keyup(function () {
var val = jQuery(this).val();
var html_source = $.WCRBP_SETTINGS.addons_html.clone();
if ( val == '' ) {
jQuery('.wc_rbp_addon_listing').html(html_source);
jQuery('.wc-rbp-addon-all').show();
} else {
html_source = jQuery(html_source).find(".plugin-card:contains('" + val + "')").not().remove();
jQuery('.wc_rbp_addon_listing').html(html_source);
}
})
});
} )(jQuery, window, document);
!function(t,s,i,a){function e(s,i){this.element=t(s),this.$elem=t(this.element),this.settings=t.extend({},l,i),this._defaults=l,this._name=n,this.init()}var n="pwstabs",l={effect:"scale",defaultTab:1,containerWidth:"100%",tabsPosition:"horizontal",horizontalPosition:"top",verticalPosition:"left",responsive:!1,theme:"",rtl:!1};e.prototype={init:function(){var i=["scale","slideleft","slideright","slidetop","slidedown","none"],a=this.$elem,e=a.children("[data-pws-tab]");a.addClass("pws_tabs_list"),a.wrap('<div class="pws_tabs_container"></div>');var n=a.closest(".pws_tabs_container");if("100%"!==this.settings.containerWidth&&n.css("width",this.settings.containerWidth),"vertical"==this.settings.tabsPosition){if(n.closest(".pws_tab_single").length){var l=n.closest(".pws_tab_single").innerWidth();n.css("width",l)}"left"==this.settings.verticalPosition?n.addClass("pws_tabs_vertical pws_tabs_vertical_left"):n.addClass("pws_tabs_vertical pws_tabs_vertical_right")}else"top"==this.settings.horizontalPosition?n.addClass("pws_tabs_horizontal pws_tabs_horizontal_top"):n.addClass("pws_tabs_horizontal pws_tabs_horizontal_bottom");this.settings.rtl&&n.addClass("pws_tabs_rtl"),"none"==this.settings.effect&&n.addClass("pws_tabs_noeffect"),this.settings.theme&&n.addClass(this.settings.theme),t.inArray(this.settings.effect,i)>=0?n.addClass("pws_"+this.settings.effect):n.addClass("pws_scale"),e.addClass("pws_hide").hide(),"vertical"==this.settings.tabsPosition?"left"==this.settings.verticalPosition?n.prepend('<ul class="pws_tabs_controll"></ul>'):n.append('<ul class="pws_tabs_controll"></ul>'):"top"==this.settings.horizontalPosition?n.prepend('<ul class="pws_tabs_controll"></ul>'):n.append('<ul class="pws_tabs_controll"></ul>');var d=n.children(".pws_tabs_controll"),o=1;e.each(function(){t(this).attr("data-pws-tab-id",o);var s=t(this).data("pws-tab"),i=t(this).data("pws-tab-name");d.append('<li><a data-tab-id="'+s+'">'+i+"</a></li>"),t(this).addClass("pws_tab_single"),o++});var h=d.find("a"),p=d.find("li"),r=a.children('[data-pws-tab-id="'+this.settings.defaultTab+'"]');if(a.children("[data-pws-tab-icon]").each(function(){var s=t(this).attr("data-pws-tab"),i=t(this).attr("data-pws-tab-name"),a=t(this).attr("data-pws-tab-icon");""==i&&d.find('[data-tab-id="'+s+'"]').addClass("pws_tab_noname"),d.find('[data-tab-id="'+s+'"]').prepend('<i class="fa '+a+'"></i>')}),"vertical"==this.settings.tabsPosition){var _=n.innerWidth()/450,c=parseInt(h.css("font-size"))/_,w=parseInt(h.css("padding-left"))+parseInt(h.css("padding-right")),u=h.html().length*c+w,b=d.outerHeight(),f=n.outerWidth()-u,v=a.outerHeight();d.width(u),a.outerWidth(f),b>v&&a.css("min-height",b)}if(r.addClass("pws_show").show(),d.find('[data-tab-id="'+r.data("pws-tab")+'"]').addClass("pws_tab_active"),h.on("click",function(s){s.preventDefault(),h.removeClass("pws_tab_active"),t(this).addClass("pws_tab_active");var i=t(this).data("tab-id"),n=a.children('[data-pws-tab="'+i+'"]');e.removeClass("pws_show"),setTimeout(function(){e.hide(),n.show()},400),setTimeout(function(){n.addClass("pws_show")},450)}),this.settings.responsive){n.addClass("pws_tabs_responsive");var g=parseInt(d.children("li").length),m=100/g,C=Math.max.apply(null,p.map(function(){return t(this).height()}).get());t(s).on("resize load",{pluginSettings:this.settings},function(i){var e=i.data.pluginSettings,l=e.tabsPosition,o=e.containerWidth;t(s).width()<=960&&(n.width(""),p.css("width",m+"%"),h.each(function(){t(this).height(C)}),"vertical"==l&&(d.width(""),a.width(""),a.css("min-height",""),a.height(r.height()))),t(s).width()<=600?(n.find(".pws_responsive_small_menu").length<1&&t('<div class="pws_responsive_small_menu"><a data-visible="0"><i class="fa fa-bars"></i></a></div>').insertBefore(d),d.addClass("pws_tabs_menu_popup"),h.height(""),p.width(""),n.find("ul.pws_tabs_menu_popup").hide(),n.find(".pws_responsive_small_menu a").click(function(s){s.preventDefault(),"0"==t(this).attr("data-visible")?(n.find("ul.pws_tabs_menu_popup").show(),t(this).attr("data-visible","1")):(n.find("ul.pws_tabs_menu_popup").hide(),t(this).attr("data-visible","0"))}),n.find("ul.pws_tabs_menu_popup li a").on("click",function(s){s.preventDefault(),t(this).closest(".pws_tabs_menu_popup").hide(),n.find(".pws_responsive_small_menu a").attr("data-visible","0")})):t(s).width()>960?(n.css("width",o),p.width(""),h.height(""),n.find(".pws_responsive_small_menu").remove(),d.removeClass("pws_tabs_menu_popup"),d.show()):t(s).width()>600&&(n.find(".pws_responsive_small_menu").remove(),d.removeClass("pws_tabs_menu_popup"),d.show(),h.on("click",function(s){s.preventDefault(),t(this).parent().parent().show()}))})}}},t.fn[n]=function(t){return this.each(function(){new e(this,t)})}}(jQuery,window,document);
\ No newline at end of file
<?php
if( ! function_exists('wc_rbp_update_acs_role_based_price') ) {
/**
* Updates Products Role Based Price Array In DB
*
* @param int $post_id Post ID To Update
* @param array $price_array Price List
*
* @return boolean [[Description]]
*/
function wc_rbp_update_acs_role_based_price($post_id, $price_array) {
update_post_meta($post_id, '_acs_role_based_price', $price_array);
return TRUE;
}
}
if( ! function_exists('wc_rbp_get_acs_product_price') ) {
/**
* Gets Product price from DB
* #TODO Integrate Wth product_rbp_price function to make it faster
*/
function wc_rbp_get_acs_product_price($post_id, $supress_filter = FALSE) {
$price = get_post_meta($post_id, '_acs_role_based_price');
if( ! empty($price) ) {
$price = $price[0];
} else if( empty($price) ) {
$price = array();
}
if( ! $supress_filter )
$price = apply_filters('wc_rbp_product_acs_prices', $price);
return $price;
}
}
if( ! function_exists('product_acs_rbp_price') ) {
/**
* Gets product price from DB
*/
function product_acs_rbp_price($post_id) {
$price = wc_rbp_product_variable($post_id, 'wc_rbp_acs', 'wc_rbp_get_acs_product_price');
return $price;
}
}
if( ! function_exists('wc_rbp_acs_price') ) {
/**
* Returns Price Based On Give Value
*
* @role : enter role slug / use all to get all roles values
* @price : use selling_price / regular_price or use all to get all values for the given role
*/
function wc_rbp_acs_price($post_id, $role, $currency, $price = 'regular_price', $args = array()) {
$dbprice = product_acs_rbp_price($post_id);
$return = FALSE;
if( $price == 'all' && $role == 'all' ) {
$return = $dbprice;
} else if( $price == 'all' && $role !== 'all' ) {
if( isset($dbprice[$role]) ) {
$return = $dbprice[$role];
}
} else if( $price == 'currency' && $role !== 'all' ) {
if( isset($dbprice[$role]) ) {
$return = $dbprice[$role][$currency];
}
} else if( isset($dbprice[$role][$currency][$price]) ) {
$return = $dbprice[$role][$currency][$price];
}
$return = apply_filters('wc_rbp_product_acs_price', $return, $role, $price, $post_id, $args);
return $return;
}
}
\ No newline at end of file
<div class="wc_rbp_popup_section acs_popup_section">
<div class="wc_rbp_pop_field"><h3><?php _e('Aelia Currency Switcher', WC_RBP_TXT); ?></h3></div>
<div class="wc_rbp_pop_field">
<?php
$tabs = array();
$content = array();
$output_html = '';
foreach( $allowed_currency as $currency ) {
if( $this->base_currency == $currency ) {
continue;
}
$symbol = get_woocommerce_currency_symbol($currency);
$symbol = ! empty($symbol) ? ' (' . $symbol . ') ' : ' (' . $currency . ') ';
$tabs[$tab_id . '-' . $currency] = array( 'title' => $currency . ' ' . $symbol );
$output_html = '<div class="wc_rbp_price_container wc_rbp_popup_section wc_rbp_popup_section_' . $tab_id . '_' . $currency . '">';
foreach( $allowed_price as $price ) {
$value = wc_rbp_acs_price($product_id, $tab_id, $currency, $price);
$text = __('Enter Product\'s %s For %s Currency', WC_RBP_TXT);
$field_id = 'wc_rbp_acs[' . $tab_id . '][' . $currency . '][' . $price . ']';
$defaults = array(
'type' => 'text',
'label' => $ex_price[$price] . $symbol,
'description' => sprintf($text, $ex_price[$price], $currency),
'class' => array(),
'label_class' => array(),
'input_class' => array( 'wc_input_price', $price, 'wc_rbp_' . $price ),
'return' => TRUE,
'custom_attributes' => array(),
);
$output_html .= '<div class="wc_rbp_pop_field_50 wc_rbp_pop_field_' . $price . '">';
$output_html .= woocommerce_form_field($field_id, $defaults, $value);
$output_html .= '</div>';
}
$output_html .= '</div>';
$content[$tab_id . '-' . $currency] = $output_html;
}
echo wc_rbp_generate_tabs($tabs, $content, array( 'tab_style' => 'default' ));
?>
</div>
</div>
\ No newline at end of file
<?php
/**
* Plugin Name: Price & Add To Cart Visibility
* Plugin URI:
* Version: 1.0
* Description: Allows to hide products price & add to cart button based on the user roles.
* Author: Varun Sridharan
* Author URI: http://varunsridharan.in
* Last Update: 2016-03-04
* Category: Tools
*/
if( ! defined('WC_RBP_PLUGIN') ) {
die;
}
class Price_add_to_cart_visibility_WC_RBP {
public function __construct() {
add_filter('wc_rbp_addon_sections', array( $this, 'add_settings_section' ));
add_filter('wc_rbp_addon_fields', array( $this, 'add_settings_fields' ));
add_filter('init', array( $this, 'check_remove_add_to_cart' ), 999);
add_filter('woocommerce_get_price_html', array( $this, 'remove_price' ), 999, 2);
}
public function check_remove_add_to_cart() {
$current_role = wc_rbp_get_current_user();
$resticted_role = wc_rbp_option('hide_product_addtocart');
$variable_status = wc_rbp_option('hide_variable_product');
if( empty($resticted_role) ) {
return;
}
if( in_array($current_role, $resticted_role) ) {
add_filter('woocommerce_loop_add_to_cart_link', array( &$this, 'remove_add_to_cart_link' ), 99);
remove_action('woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30);
if( $variable_status ) {
remove_action('woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30);
} else {
remove_action('woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20);
}
}
}
public function remove_add_to_cart_link($link) {
return '';
}
public function remove_price($price) {
$current_role = wc_rbp_get_current_user();
$resticted_role = wc_rbp_option('hide_product_price');
if( ! empty($resticted_role) ) {
if( in_array($current_role, $resticted_role) ) {
$price_notice = wc_rbp_option('pv_custom_message');
$price_notice = apply_filters('wc_rbp_price_visibility_custom_price_message', $price_notice, $current_role);
if( ! empty($price_notice) ) {
$symbol = get_woocommerce_currency_symbol();
$price_notice = str_replace('[currency]', $symbol, $price_notice);
return $price_notice;
}
return '';
}
}
return $price;
}
public function add_settings_fields($fields) {
$fields['price_visibility'][] = array(
'id' => WC_RBP_DB . 'hide_product_price',
'multiple' => 'true',
'type' => 'select',
'label' => __('Hide Price For', WC_RBP_TXT),
'desc' => __('Product Price will be hidden for the selected user roles', WC_RBP_TXT),
'options' => wc_rbp_get_user_roles_selectbox(),
'attr' => array(
'class' => 'wc-rbp-enhanced-select',
'multiple' => 'multiple',
),
);
$fields['price_visibility'][] = array(
'id' => WC_RBP_DB . 'hide_product_addtocart',
'multiple' => 'true',
'type' => 'select',
'label' => __('Hide Add To Cart Button', WC_RBP_TXT),
'desc' => __('Product Add To Cart Button will be hidden for the selected user roles', WC_RBP_TXT),
'options' => wc_rbp_get_user_roles_selectbox(),
'attr' => array(
'class' => 'wc-rbp-enhanced-select',
'multiple' => 'multiple',
),
);
$fields['price_visibility'][] = array(
'id' => WC_RBP_DB . 'hide_variable_product',
'type' => 'checkbox',
'label' => __('Hide Product Variations', WC_RBP_TXT),
'desc' => __('if checked Variable product variation will be hidden from product page ', WC_RBP_TXT),
'attr' => array( 'class' => 'wc_rbp_checkbox', ),
);
$fields['price_visibility'][] = array(
'id' => WC_RBP_DB . 'pv_custom_message',
'value' => html_entity_decode(wc_rbp_option('pv_custom_message')),
'type' => 'richtext',
'richtext_settings' => array( 'textarea_rows' => 5 ),
'label' => __('Custom Message', WC_RBP_TXT),
'desc' => __('Used when product price is hidden.. use <code>[currency]</code> to get current store currency', WC_RBP_TXT),
'attr' => array( 'class' => 'wc_rbp_checkbox', ),
);
return $fields;
}
public function add_settings_section($section) {
$c_section = array();
$c_section['id'] = 'price_visibility';
$c_section['title'] = __('Price & AddToCart Visibility', WC_RBP_TXT);
$c_section['desc'] = __('Hide Product Price & Add To Cart button based on users role and set custom messsage to show if price is hidden', WC_RBP_TXT);
$section[] = $c_section;
return $section;
}
}
return new Price_add_to_cart_visibility_WC_RBP;
\ No newline at end of file
<?php
/**
* Plugin Name: WooCommerce Product Export
* Plugin URI:
* Version: 1.0
* Description: This Addon Integration With Default Product Exporter In WooCommerce And Provides Options To Export Role Based Prices
* Author: Varun Sridharan
* Author URI: http://varunsridharan.in
* Last Update: 2017-07-07
* Category: Tools,Price Export
*/
if( ! defined('WC_RBP_PLUGIN') ) {
die;
}
class wc_product_price_exporter {
public function __construct() {
$this->is_wcrbp_export = FALSE;
$this->key_vals();
add_filter("woocommerce_product_export_product_default_columns", array( $this, 'add_option' ));
add_filter("woocommerce_product_export_row_data", array( $this, 'add_wcrbp_prices' ), 1, 2);
add_action("wp_ajax_woocommerce_do_ajax_product_export", array( $this, 'check_wcrbp_export' ), 1);
}
public function key_vals() {
$allowed_user_roles = wc_rbp_allowed_roles();
$allowed_prices = wc_rbp_allowed_price();
$active_cols = array( 'wcrbp_status' => '' );
$user_roles = array();
foreach( $allowed_user_roles as $role_id ) {
if( ! isset($user_roles['wcrbp_' . $role_id]) ) {
$user_roles['wcrbp_' . $role_id] = array();
}
foreach( $allowed_prices as $price_id ) {
if( ! isset($active_cols['wcrbp_' . $role_id . '_' . $price_id]) ) {
$user_roles['wcrbp_' . $role_id]['wcrbp_' . $role_id . '_' . $price_id] = '';
$active_cols['wcrbp_' . $role_id . '_' . $price_id] = array( 'role' => $role_id,
'price' => $price_id,
);
}
}
}
$this->active_cols = $active_cols;
$this->user_roles = $user_roles;
return $this->active_cols;
}
public function check_wcrbp_export() {
if( isset($_POST['selected_columns']) ) {
if( is_array($_POST['selected_columns']) ) {
if( in_array('wcrbp_price', $_POST['selected_columns']) ) {
$this->remove_post_data('wcrbp_price');
$_POST['selected_columns'] = array_merge($_POST['selected_columns'], array_keys($this->key_vals()));
$this->is_wcrbp_export = TRUE;
} else {
foreach( array_keys($this->user_roles) as $role ) {
if( in_array($role, $_POST['selected_columns']) ) {
$this->remove_post_data($role);
$_POST['selected_columns'] = array_merge($_POST['selected_columns'], array_keys($this->user_roles[$role]));
$this->is_wcrbp_export = TRUE;
}
}
}
}
}
if( $this->is_wcrbp_export ) {
add_filter("woocommerce_product_export_column_names", array( $this, 'custom_col' ));
}
}
public function remove_post_data($key) {
foreach( $_POST['selected_columns'] as $id => $vl ) {
if( $vl == $key ) {
unset($_POST['selected_columns'][$id]);
}
}
}
public function add_wcrbp_prices($row, $product) {
if( $this->is_wcrbp_export ) {
$prices = wc_rbp_price($product->get_id(), 'all', 'all');
if( isset($row['wcrbp_status']) )
$row['wcrbp_status'] = wc_rbp_product_status($product->get_id(), TRUE);
if( ! empty($prices) ) {
foreach( $prices as $user => $price_types ) {
foreach( $price_types as $type => $price ) {
if( isset($row['wcrbp_' . $user . '_' . $type]) ) {
$row['wcrbp_' . $user . '_' . $type] = wc_format_localized_price($price);
}
}
}
}
}
return $row;
}
public function custom_col($cols) {
$new_cols = $this->active_cols;
$allowed_user_roles = wc_rbp_allowed_roles();
$allowed_prices = wc_rbp_allowed_price();
foreach( $allowed_user_roles as $user_role_id ) {
foreach( $allowed_prices as $price ) {
if( ! isset($cols['wcrbp_' . $user_role_id . '_' . $price]) ) {
$cols['wcrbp_' . $user_role_id . '_' . $price] = $user_role_id . '_' . $price;
}
}
}
$cols['wcrbp_status'] = 'wcrbp_status';
return $cols;
}
public function add_option($options) {
$options['wcrbp_price'] = __("Role Based Price For WooCommerce All", WC_RBP_TXT);
$allowed_user_roles = wc_rbp_allowed_roles();
$user_roles = wc_rbp_get_wp_roles();
$options['wcrbp_status'] = __("WC RBP Status", WC_RBP_TXT);
foreach( $user_roles as $user_role_id => $user_role_name ) {
if( in_array($user_role_id, $allowed_user_roles) ) {
if( ! isset($options['wcrbp_' . $user_role_id]) ) {
$options['wcrbp_' . $user_role_id] = __('WC Role Based ', WC_RBP_TXT) . $user_role_name['name'] . __(' Price ', WC_RBP_TXT);
}
}
}
return $options;
}
}
return new wc_product_price_exporter;
\ No newline at end of file
<?php
/**
* Plugin Name: WooCommerce Product Importer
* Plugin URI:
* Version: 1.0
* Description: This Addon Integration With Default Product Importer In WooCommerce And Provides Options To Import, Role Based Prices
* Author: Varun Sridharan
* Author URI: http://varunsridharan.in
* Last Update: 2017-07-07
* Category: Tools,Price Import
*/
if( ! defined('WC_RBP_PLUGIN') ) {
die;
}
class wc_product_price_importer {
public function __construct() {
add_filter("woocommerce_csv_product_import_mapping_options", array( $this, 'add_import_options' ));
add_action("woocommerce_product_import_inserted_product_object", array( $this, 'save_price' ), 10, 2);
}
public function save_price($product, $data) {
$this->generate_options_data();
$obj = $this->options_product_save;
$obk = array_keys($obj);
$final_price = array();
$status = FALSE;
foreach( $data as $id => $value ) {
if( $id == 'wcrbp_status' ) {
if( $value == 'no' ) {
$status = FALSE;
} else if( $value == 'yes' ) {
$status = TRUE;
} else if( floatval($value) == 0 ) {
$status = FALSE;
} else if( floatval($value) == 1 ) {
$status = TRUE;
}
} else if( in_array($id, $obk) ) {
$attribute = $obj[$id];
$role = $attribute['role'];
$price_type = $attribute['price'];
if( $value != '' ) {
$final_price[$role][$price_type] = wc_format_decimal($value);
}
}
}
if( ! empty($final_price) )
wc_rbp_update_role_based_price($product->get_id(), $final_price);
wc_rbp_update_role_based_price_status($product->get_id(), $status);
}
public function generate_options_data() {
if( isset($this->options_updated) ) {
return $this->options_updated;
}
$allowed_user_roles = wc_rbp_allowed_roles();
$allowed_prices = wc_rbp_allowed_price();
$options = array( "wcrbp_status" => __("Price Status") );
$options2 = array( "wcrbp_status" => __("Price Status") );
foreach( wc_rbp_get_wp_roles() as $role_id => $data ) {
if( in_array($role_id, $allowed_user_roles) ) {
foreach( $allowed_prices as $price_id ) {
$options[$role_id . '_' . $price_id] = ' WC Role Based ' . $data['name'] . ' - ' . wc_rbp_price_types($price_id);
$options2[$role_id . '_' . $price_id] = array( 'role' => $role_id, 'price' => $price_id );
}
}
}
$this->options_updated = $options;
$this->options_product_save = $options2;
return $options;
}
public function add_import_options($options) {
$options['wcrbp_options'] = array(
'name' => __("Role Based Price For WooCommerce"),
'options' => $this->generate_options_data(),
);
return $options;
}
}
return new wc_product_price_importer;
\ No newline at end of file
<?php
/**
* Summary (no period for file headers)
*
* Description. (use period)
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
* @package Role Based Price For WooCommerce
* @subpackage Role Based Price For WooCommerce/core
* @since 3.0
*/
if( ! defined('WP_UNINSTALL_PLUGIN') ) {
exit;
}
\ No newline at end of file
<?php
/**
* Plugin Name: Role Based Price For WooCommerce
* Plugin URI: https://wordpress.org/plugins/woocommerce-role-based-price/
* Description: Sell product in different price for different user role based on your settings.
* Version: 3.3.6
* Author: Varun Sridharan
* Author URI: http://varunsridharan.in
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: woocommerce-role-based-price
* Domain Path: /languages/
*/
if ( ! defined( 'WPINC' ) ) {
die;
}
define( 'WC_RBP_FILE', plugin_basename( __FILE__ ) );
define( 'WC_RBP_PATH', plugin_dir_path( __FILE__ ) ); # Plugin DIR
define( 'WC_RBP_INC', WC_RBP_PATH . 'includes/' ); # Plugin INC Folder
define( 'WC_RBP_DEPEN', 'woocommerce/woocommerce.php' );
define( 'WC_RBP_VARIABLE_VERSION', '3.3.6' );
register_activation_hook( __FILE__, 'wc_rbp_activate_plugin_name' );
register_deactivation_hook( __FILE__, 'wc_rbp_deactivate_plugin_name' );
register_deactivation_hook( WC_RBP_DEPEN, 'wc_rbp_dependency_plugin_deactivate' );
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-plugin-name-activator.php
*/
function wc_rbp_activate_plugin_name() {
require_once( WC_RBP_INC . 'helpers/class-activator.php' );
woocommerce_role_based_price_Activator::activate();
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-plugin-name-deactivator.php
*/
function wc_rbp_deactivate_plugin_name() {
require_once( WC_RBP_INC . 'helpers/class-deactivator.php' );
woocommerce_role_based_price_Deactivator::deactivate();
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-plugin-name-deactivator.php
*/
function wc_rbp_dependency_plugin_deactivate() {
require_once( WC_RBP_INC . 'helpers/class-deactivator.php' );
woocommerce_role_based_price_Deactivator::dependency_deactivate();
}
require_once( WC_RBP_INC . 'functions.php' );
require_once( plugin_dir_path( __FILE__ ) . 'bootstrap.php' );
if ( ! function_exists( 'woocommerce_role_based_price' ) ) {
function woocommerce_role_based_price() {
return woocommerce_role_based_price::get_instance();
}
}
woocommerce_role_based_price();
\ No newline at end of file
<wpml-config>
<custom-fields>
<custom-field action="copy">_enable_role_based_price</custom-field>
<custom-field action="copy">_role_based_price</custom-field>
</custom-fields>
</wpml-config>
\ No newline at end of file