Changeset 2107071
- Timestamp:
- 06/16/2019 09:56:43 PM (7 years ago)
- Location:
- woo-affiliate-sort/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (2 diffs)
-
woocommerce-affiliate-sort.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woo-affiliate-sort/trunk/readme.txt
r1843323 r2107071 2 2 Donate link: https://www.paypal.me/ash0ur 3 3 Tags: Woocommerce, development, affiliate, external, sort, order, popularity, clicks 4 Tested up to: 4.9.45 Version: 1.0.0 4 Tested up to: 5.2.1 5 Version: 1.0.0 6 6 Author: Abdelrahman Ashour 7 7 Author email: abdelrahman.ashour38@gmail.com … … 11 11 12 12 == Description == 13 This plugin is for sites that promote affiliate or external products, It allows sorting the affiliate products by popularity using the users clicks on the product link. 14 15 13 This plugin is for sites that promote affiliate/external products, It allows sorting the affiliate/external products ascending by popularity using the users clicks on the product link. -
woo-affiliate-sort/trunk/woocommerce-affiliate-sort.php
r1843323 r2107071 16 16 * License: GPL2 17 17 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 18 */18 */ 19 19 20 if (!defined('ABSPATH'))20 if ( ! defined( 'ABSPATH' ) ) { 21 21 exit; 22 } 22 23 23 24 24 if (!class_exists('WooCommerce_affiliate_sort')):25 if ( ! class_exists( 'WooCommerce_affiliate_sort' ) ) : 25 26 26 class WooCommerce_affiliate_sort{27 class WooCommerce_affiliate_sort { 27 28 28 29 29 public static function init(){30 $theCalc = new self();31 }30 public static function init() { 31 $theCalc = new self(); 32 } 32 33 33 public function __construct(){34 public function __construct() { 34 35 35 $this->define_constants();36 $this->setup_actions();37 }36 $this->define_constants(); 37 $this->setup_actions(); 38 } 38 39 39 40 40 41 41 public function define_constants(){42 public function define_constants() { 42 43 43 define('WOOAFFPRO_BASE_URL', trailingslashit( plugins_url('woocommerce-affiliate-sort') ));44 define('WOOAFFPRO_ASSETS_URL', trailingslashit( WOOAFFPRO_BASE_URL . 'assets') );45 define('WOOAFFPRO_PATH', plugin_dir_path(__FILE__ ));46 }44 define( 'WOOAFFPRO_BASE_URL', trailingslashit( plugins_url( 'woocommerce-affiliate-sort' ) ) ); 45 define( 'WOOAFFPRO_ASSETS_URL', trailingslashit( WOOAFFPRO_BASE_URL . 'assets' ) ); 46 define( 'WOOAFFPRO_PATH', plugin_dir_path( __FILE__ ) ); 47 } 47 48 48 public static function plugin_activated(){ 49 50 if( !in_array('woocommerce/woocommerce.php',apply_filters('active_plugins',get_option('active_plugins'))) ){ 51 die('WooCommerce plugin must be active'); 49 public static function plugin_activated() { 50 51 if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { 52 die( 'WooCommerce plugin must be active' ); 53 54 } 52 55 53 56 } 57 58 59 60 public function frontend_enqueue_global() { 61 62 if ( ! wp_script_is( 'jquery', 'registered' ) ) { 63 wp_enqueue_script( 'jquery' ); 64 } 65 66 wp_enqueue_script( 'WOOAFFPRO_actions', WOOAFFPRO_ASSETS_URL . 'js/actions.js', array( 'jquery' ), WC_VERSION, true ); 67 68 wp_localize_script( 69 'WOOAFFPRO_actions', 70 'WOOAFFPRO_ajax_data', 71 array( 72 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 73 'nonce' => wp_create_nonce( 'WOOAFFPRO_ajax_nonce' ), 74 ) 75 ); 76 } 77 78 79 public function setup_actions() { 80 81 add_action( 'wp_enqueue_scripts', array( $this, 'frontend_enqueue_global' ) ); 82 83 add_action( 'wp_ajax_nopriv_increase_external_populatiry', array( $this, 'increase_external_populatiry_func' ) ); 84 85 add_action( 'wp_ajax_increase_external_populatiry', array( $this, 'increase_external_populatiry_func' ) ); 86 } 87 88 89 public function increase_external_populatiry_func() { 90 91 check_ajax_referer( 'WOOAFFPRO_ajax_nonce', 'nonce' ); 92 93 $product_id = absint( $_POST['product_id'] ); 94 95 if ( $product_id && wc_get_product( $product_id )->get_type() == 'external' ) { 96 97 $lastCount = get_post_meta( $product_id, 'total_sales', true ); 98 99 if ( ! empty( $lastCount ) ) { 100 101 $updated = update_post_meta( $product_id, 'total_sales', $lastCount + 1 ); 102 103 } else { 104 $updated = update_post_meta( $product_id, 'total_sales', 1 ); 105 } 106 } 107 108 wp_die(); 109 } 110 54 111 55 112 } … … 57 114 58 115 59 public function frontend_enqueue_global(){116 add_action( 'plugins_loaded', array( 'WooCommerce_affiliate_sort', 'init' ), 10 ); 60 117 61 if(!wp_script_is( 'jquery', 'registered' )) 62 wp_enqueue_script( 'jquery'); 63 64 wp_enqueue_script( 'WOOAFFPRO_actions',WOOAFFPRO_ASSETS_URL . 'js/actions.js',array('jquery'),WC_VERSION,true); 65 66 wp_localize_script('WOOAFFPRO_actions','WOOAFFPRO_ajax_data',array('ajaxUrl'=>admin_url('admin-ajax.php'),'nonce'=>wp_create_nonce('WOOAFFPRO_ajax_nonce')) ); 67 } 68 69 70 public function setup_actions(){ 71 72 add_action('wp_enqueue_scripts',array($this,'frontend_enqueue_global')); 73 74 add_action('wp_ajax_nopriv_increase_external_populatiry',array($this,'increase_external_populatiry_func')); 75 76 add_action('wp_ajax_increase_external_populatiry',array($this,'increase_external_populatiry_func')); 77 } 78 79 80 public function increase_external_populatiry_func(){ 81 82 check_ajax_referer( 'WOOAFFPRO_ajax_nonce','nonce' ); 83 84 $product_id = absint($_POST['product_id']); 85 86 if( $product_id && wc_get_product($product_id)->get_type() == 'external' ){ 87 88 $lastCount = get_post_meta($product_id,'total_sales',true); 89 90 if(!empty($lastCount)){ 91 92 $updated = update_post_meta($product_id,'total_sales',$lastCount+1); 93 94 }else{ 95 $updated = update_post_meta($product_id,'total_sales',1); 96 } 97 98 } 99 100 wp_die(); 101 } 102 103 104 } 105 106 107 108 add_action('plugins_loaded',array('WooCommerce_affiliate_sort','init'),10); 109 110 register_activation_hook( __FILE__,array('WooCommerce_affiliate_sort','plugin_activated') ); 118 register_activation_hook( __FILE__, array( 'WooCommerce_affiliate_sort', 'plugin_activated' ) ); 111 119 112 120 endif; 113 114 115 116 117
Note: See TracChangeset
for help on using the changeset viewer.