Changeset 2703109
- Timestamp:
- 04/01/2022 06:43:17 AM (4 years ago)
- Location:
- woo-product-as-gift/trunk
- Files:
-
- 14 edited
-
assets/admin/css/style.css (modified) (1 diff)
-
assets/admin/js/script.js (modified) (2 diffs)
-
assets/css/style.css (modified) (1 diff)
-
assets/js/script.js (modified) (2 diffs)
-
class/class-wc-gift-settings.php (modified) (1 diff)
-
lib/codupads/codupads.php (modified) (1 diff)
-
lib/codupads/scripts/adscript.js (modified) (1 diff)
-
lib/codupads/styles/style.css (modified) (1 diff)
-
partials/gifts-settings.php (modified) (1 diff)
-
partials/nav.php (modified) (1 diff)
-
partials/note.php (modified) (1 diff)
-
partials/wrapping.php (modified) (1 diff)
-
readme.txt (modified) (1 diff)
-
woocommerce-gift-wrap.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
woo-product-as-gift/trunk/assets/admin/css/style.css
r2388090 r2703109 1 1 .wcgw-gifts-wrapper{ 2 width: 100%;3 display: block;2 width: 100%; 3 display: block; 4 4 } 5 5 6 6 .wcgw-gifts-wrapper h1{ 7 margin: 0.2em 200px 0 0;8 padding: 0;9 color: #32373c;10 line-height: 1.2em;11 font-size: 2.8em;12 font-weight: 400;7 margin: 0.2em 200px 0 0; 8 padding: 0; 9 color: #32373c; 10 line-height: 1.2em; 11 font-size: 2.8em; 12 font-weight: 400; 13 13 } 14 14 15 15 .gift-control-enable{ 16 width: 100%;17 display: block;16 width: 100%; 17 display: block; 18 18 } 19 19 20 20 .gift-control-enable label{ 21 float: left;22 line-height: 17px;23 margin-right: 20px;21 float: left; 22 line-height: 17px; 23 margin-right: 20px; 24 24 } 25 25 26 26 .gift-control-enable input[type=checkbox]{ 27 width: 18px;28 height: 17px;29 padding: 1px 0 0 0 !important;27 width: 18px; 28 height: 17px; 29 padding: 1px 0 0 0 !important; 30 30 } 31 31 32 32 .wcgw-gifts-wrapper-section{ 33 display: block;34 padding: 30px 10px;33 display: block; 34 padding: 30px 10px; 35 35 } 36 36 37 37 .wcgw-gifts-wrapper-section input[type=text],.wcgw-gifts-wrapper-section textarea,.wcgw-gifts-wrapper-section select{ 38 width: 400px;38 width: 400px; 39 39 } 40 40 41 41 .wcgw-gifts-wrapper-section .help-notice{ 42 color: #666;43 display: inline-block;44 font-size: 1.1em;45 font-style: normal;46 height: 16px;47 line-height: 16px;48 position: relative;49 vertical-align: middle;50 width: 16px;42 color: #666; 43 display: inline-block; 44 font-size: 1.1em; 45 font-style: normal; 46 height: 16px; 47 line-height: 16px; 48 position: relative; 49 vertical-align: middle; 50 width: 16px; 51 51 } 52 52 53 53 .wcgw-gifts-wrapper-section .help-notice::after{ 54 font-family: Dashicons;55 speak: none;56 font-weight: 400;57 text-transform: none;58 line-height: 1;59 -webkit-font-smoothing: antialiased;60 text-indent: 0px;61 position: absolute;62 top: 0px;63 left: 0px;64 width: 100%;65 height: 100%;66 text-align: center;67 content: "";68 cursor: help;69 font-variant: normal normal;70 margin: 0px;54 font-family: Dashicons; 55 speak: none; 56 font-weight: 400; 57 text-transform: none; 58 line-height: 1; 59 -webkit-font-smoothing: antialiased; 60 text-indent: 0px; 61 position: absolute; 62 top: 0px; 63 left: 0px; 64 width: 100%; 65 height: 100%; 66 text-align: center; 67 content: ""; 68 cursor: help; 69 font-variant: normal normal; 70 margin: 0px; 71 71 } 72 72 73 73 .wcgw-wrapping-style { 74 display: flex;74 display: flex; 75 75 } 76 76 77 77 .wcgw-wrapping-style .dashicons{ 78 background: #FFF;79 border-radius: 50%;80 line-height: 23px;81 padding: 3px;78 background: #FFF; 79 border-radius: 50%; 80 line-height: 23px; 81 padding: 3px; 82 82 } 83 83 84 84 .wcgw-wrapping-style-wrapper { 85 float: left;86 width: 410px;85 float: left; 86 width: 410px; 87 87 } 88 88 89 89 .wcgw-wrapping-style-wrapper > * { 90 /* display: inline; */91 margin: 5px 0;90 /* display: inline; */ 91 margin: 5px 0; 92 92 } -
woo-product-as-gift/trunk/assets/admin/js/script.js
r2388090 r2703109 1 /* 1 /* 2 2 * To change this license header, choose License Headers in Project Properties. 3 3 * To change this template file, choose Tools | Templates … … 5 5 */ 6 6 7 jQuery(document).ready(function ($) { 8 jQuery("body").on("click", ".dashicons", function () { 9 var icon = jQuery(this); 10 if (jQuery(icon).hasClass("dashicons-plus") == true) { 11 // icon.prev().find("input").val(""); 12 var newDiv = icon.parent().clone(true); 13 newDiv.hide().appendTo(icon.parent().parent()).show(1000); 14 newDiv.find('.dashicons-plus').replaceWith(`<p class="dashicons dashicons-minus"></p>`); 15 // icon.prev().remove(); 16 newDiv.find("input").val(""); 17 var noImage = $('#defaultImg').attr("data-image"); 18 console.log(noImage); 7 jQuery( document ).ready( 8 function ($) { 9 jQuery( "body" ).on( 10 "click", 11 ".dashicons", 12 function () { 13 var icon = jQuery( this ); 14 if (jQuery( icon ).hasClass( "dashicons-plus" ) == true) { 15 // icon.prev().find("input").val(""); 16 var newDiv = icon.parent().clone( true ); 17 newDiv.hide().appendTo( icon.parent().parent() ).show( 1000 ); 18 newDiv.find( '.dashicons-plus' ).replaceWith( ` < p class = "dashicons dashicons-minus" > < / p > ` ); 19 // icon.prev().remove(); 20 newDiv.find( "input" ).val( "" ); 21 var noImage = $( '#defaultImg' ).attr( "data-image" ); 22 console.log( noImage ); 19 23 20 newDiv.find("img").attr("src", noImage); 21 // icon.removeClass("dashicons-plus"); 22 // icon.addClass("dashicons-minus"); 23 } else { 24 console.log('IN ELSE'); 25 if (jQuery(icon).hasClass("last") == true) { 26 // icon.parent().prev().append('<p class="dashicons dashicons-plus"></p>'); 27 icon.parent().prev().find(".dashicons-minus").addClass("last"); 28 } 29 icon.parent().hide(1000, function(){ 30 jQuery(this).remove(); 31 }); 32 } 33 }); 34 jQuery(".upload_image_button").click(function () { 35 var send_attachment_bkp = wp.media.editor.send.attachment; 36 var button = jQuery(this); 37 wp.media.editor.send.attachment = function (props, attachment) { 38 console.log(attachment.title); 39 jQuery(button).parent().prev().attr("src", attachment.sizes.thumbnail.url); 40 jQuery(button).prev().val(attachment.id); 41 wp.media.editor.send.attachment = send_attachment_bkp; 42 } 43 wp.media.editor.open(button); 44 return false; 45 }); 46 }); 47 48 24 newDiv.find( "img" ).attr( "src", noImage ); 25 // icon.removeClass("dashicons-plus"); 26 // icon.addClass("dashicons-minus"); 27 } else { 28 console.log( 'IN ELSE' ); 29 if (jQuery( icon ).hasClass( "last" ) == true) { 30 // icon.parent().prev().append('<p class="dashicons dashicons-plus"></p>'); 31 icon.parent().prev().find( ".dashicons-minus" ).addClass( "last" ); 32 } 33 icon.parent().hide( 34 1000, 35 function(){ 36 jQuery( this ).remove(); 37 } 38 ); 39 } 40 } 41 ); 42 jQuery( ".upload_image_button" ).click( 43 function () { 44 var send_attachment_bkp = wp.media.editor.send.attachment; 45 var button = jQuery( this ); 46 wp.media.editor.send.attachment = function (props, attachment) { 47 console.log( attachment.title ); 48 jQuery( button ).parent().prev().attr( "src", attachment.sizes.thumbnail.url ); 49 jQuery( button ).prev().val( attachment.id ); 50 wp.media.editor.send.attachment = send_attachment_bkp; 51 } 52 wp.media.editor.open( button ); 53 return false; 54 } 55 ); 56 } 57 ); -
woo-product-as-gift/trunk/assets/css/style.css
r2388090 r2703109 1 1 .wcgw_giftwrap_products ul{ 2 margin: 0;3 padding: 0;2 margin: 0; 3 padding: 0; 4 4 } 5 5 6 6 .wcgw_giftwrap_products ul li { 7 list-style: none;8 display: inline-block;9 width: 23%;10 margin: 0px 5px 10px;11 vertical-align: top;7 list-style: none; 8 display: inline-block; 9 width: 23%; 10 margin: 0px 5px 10px; 11 vertical-align: top; 12 12 } 13 13 14 14 .wcgw_giftwrap_products ul li .wcgw_image { 15 height: 180px;16 border: 1px solid #f1f1f1;15 height: 180px; 16 border: 1px solid #f1f1f1; 17 17 } 18 18 19 19 .wcgw_message_charges_message{ 20 font-size: 12px;20 font-size: 12px; 21 21 } 22 22 23 23 .wcgw-success-notice { 24 background: #0f834d;25 padding: 10px 20px;26 color: #FFF;24 background: #0f834d; 25 padding: 10px 20px; 26 color: #FFF; 27 27 } 28 28 .showImg{ 29 height: 100% !important;29 height: 100% !important; 30 30 } -
woo-product-as-gift/trunk/assets/js/script.js
r1857014 r2703109 1 /* 1 /* 2 2 * To change this license header, choose License Headers in Project Properties. 3 3 * To change this template file, choose Tools | Templates … … 5 5 */ 6 6 7 jQuery(document).ready(function () { 8 jQuery("input[name='wcgw-apply-gift-options']").on('click', function () { 9 action = "is_order_is_gift"; 10 var data = { 11 'action': action, 12 }; 13 jQuery.post(admin_url, data, function (response) { 14 location.reload(); 15 }); 16 }); 17 }); 18 19 7 jQuery( document ).ready( 8 function () { 9 jQuery( "input[name='wcgw-apply-gift-options']" ).on( 10 'click', 11 function () { 12 action = "is_order_is_gift"; 13 var data = { 14 'action': action, 15 }; 16 jQuery.post( 17 admin_url, 18 data, 19 function (response) { 20 location.reload(); 21 } 22 ); 23 } 24 ); 25 } 26 ); -
woo-product-as-gift/trunk/class/class-wc-gift-settings.php
r2388090 r2703109 1 1 <?php 2 if ( ! defined('ABSPATH') ) {3 exit; // Exit if accessed directly.2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; // Exit if accessed directly. 4 4 } 5 5 6 6 class WCGR_Gift_Wrapping_Base_Settings { 7 7 8 protected static $_instance = null;8 protected static $_instance = null; 9 9 10 /**11 * main init callback loads functions which are required on wordpress init12 */13 public static function instance() {14 if ( is_null(self::$_instance) ) {15 self::$_instance = new self();16 }17 return self::$_instance;18 }10 /** 11 * main init callback loads functions which are required on WordPress init 12 */ 13 public static function instance() { 14 if ( is_null( self::$_instance ) ) { 15 self::$_instance = new self(); 16 } 17 return self::$_instance; 18 } 19 19 20 /**21 * Constructor.22 */23 public function __construct() {24 add_action('admin_menu', array($this, 'add_settings_menu'));25 add_action('admin_init', array($this, 'register_admin_scripts'));26 add_action('admin_enqueue_scripts', array($this, 'register_media_related_scripts'));27 }20 /** 21 * Constructor. 22 */ 23 public function __construct() { 24 add_action( 'admin_menu', array( $this, 'add_settings_menu' ) ); 25 add_action( 'admin_init', array( $this, 'register_admin_scripts' ) ); 26 add_action( 'admin_enqueue_scripts', array( $this, 'register_media_related_scripts' ) ); 27 } 28 28 29 public function add_settings_menu() {30 add_submenu_page("woocommerce", "Settings", "Gifts Settings", "administrator", "wc-gift-settings", array($this, 'settings_page'));31 }29 public function add_settings_menu() { 30 add_submenu_page( 'woocommerce', 'Settings', 'Gifts Settings', 'administrator', 'wc-gift-settings', array( $this, 'settings_page' ) ); 31 } 32 32 33 public function save_styles($array) { 34 35 $styles_array = []; 36 if ( $array["name"][0] != "" ) { 37 foreach ( $array["name"] as $kname => $name ) { 38 $styles_array[$kname]["name"] = $name; 39 } 40 foreach ( $array["price"] as $kprice => $price ) { 41 $styles_array[$kprice]["price"] = $price; 42 } 43 44 45 foreach ( $array["image"] as $kimage => $image ) { 46 $styles_array[$kimage]["image"] = $image; 47 } 48 update_option("wcgw-wrapping-style", json_encode($styles_array)); 49 } 50 } 33 public function save_styles( $array ) { 51 34 52 /** 53 * loads setting page html 54 */ 55 public function settings_page() { 56 57 if ( filter_input(INPUT_POST, "wcgw_submit") ) { 58 update_option("wcgw-enable-gift-options", filter_input(INPUT_POST, "wcgw-enable-gift-options")); 59 if ( filter_input(INPUT_POST, "wcgw-is-this-gift") ) { 60 update_option("wcgw-is-this-gift", filter_input(INPUT_POST, "wcgw-is-this-gift")); 61 } 62 else { 63 update_option("wcgw-is-this-gift", "Is this gift"); 64 } 65 if ( !empty(filter_input(INPUT_POST, "wcgw-gift-detail")) ) { 66 update_option("wcgw-gift-detail", filter_input(INPUT_POST, "wcgw-gift-detail")); 67 } 68 else { 69 delete_option("wcgw-gift-detail"); 70 } 71 $wcgw_wrapping_style = (isset($_POST["wcgw-wrapping-style"])) ? $_POST["wcgw-wrapping-style"] : false; 72 $first_set = (isset($_POST["wcgw-wrapping-style"]["name"][0])) ? $_POST["wcgw-wrapping-style"]["name"][0] : false; 73 74 if ( !empty($first_set) ) { 75 $this->save_styles($wcgw_wrapping_style); 76 } 77 else { 78 delete_option("wcgw-wrapping-style"); 79 } 80 } 81 if ( filter_input(INPUT_POST, "wcgw_note_submit") ) { 82 update_option("wcgw-charge-fee-message", filter_input(INPUT_POST, "wcgw-charge-fee-message")); 83 if ( filter_input(INPUT_POST, "wcgw-message-charges") ) { 84 update_option("wcgw-message-charges", filter_input(INPUT_POST, "wcgw-message-charges")); 85 } 86 else { 87 delete_option("wcgw-message-charges"); 88 } 89 if ( filter_input(INPUT_POST, "wcgw-add-message") ) { 90 update_option("wcgw-add-message", filter_input(INPUT_POST, "wcgw-add-message")); 91 } 92 else { 93 delete_option("wcgw-add-message"); 94 } 95 } 96 require_once WC_GIFTS_DIR . '/partials/gifts-settings.php'; 97 } 35 $styles_array = array(); 36 if ( $array['name'][0] != '' ) { 37 foreach ( $array['name'] as $kname => $name ) { 38 $styles_array[ $kname ]['name'] = $name; 39 } 40 foreach ( $array['price'] as $kprice => $price ) { 41 $styles_array[ $kprice ]['price'] = $price; 42 } 98 43 99 /** 100 * Register all media library related scripts 101 */ 102 public function register_media_related_scripts() { 103 wp_enqueue_media(); 104 }44 foreach ( $array['image'] as $kimage => $image ) { 45 $styles_array[ $kimage ]['image'] = $image; 46 } 47 update_option( 'wcgw-wrapping-style', json_encode( $styles_array ) ); 48 } 49 } 105 50 106 /** 107 * register all admin scripts related to this plugin 108 */ 109 public function register_admin_scripts() { 110 wp_enqueue_style("wc-gift-admin-style", WC_GIFTS_URL . 'assets/admin/css/style.css', array(), WC_GIFTS_VERSION); 111 wp_enqueue_script("wc-gift-admin-script", WC_GIFTS_URL . 'assets/admin/js/script.js', array('jquery'), WC_GIFTS_VERSION); 112 } 51 /** 52 * loads setting page html 53 */ 54 public function settings_page() { 55 56 if ( filter_input( INPUT_POST, 'wcgw_submit' ) ) { 57 update_option( 'wcgw-enable-gift-options', filter_input( INPUT_POST, 'wcgw-enable-gift-options' ) ); 58 if ( filter_input( INPUT_POST, 'wcgw-is-this-gift' ) ) { 59 update_option( 'wcgw-is-this-gift', filter_input( INPUT_POST, 'wcgw-is-this-gift' ) ); 60 } else { 61 update_option( 'wcgw-is-this-gift', 'Is this gift' ); 62 } 63 if ( ! empty( filter_input( INPUT_POST, 'wcgw-gift-detail' ) ) ) { 64 update_option( 'wcgw-gift-detail', filter_input( INPUT_POST, 'wcgw-gift-detail' ) ); 65 } else { 66 delete_option( 'wcgw-gift-detail' ); 67 } 68 $wcgw_wrapping_style = ( isset( $_POST['wcgw-wrapping-style'] ) ) ? $_POST['wcgw-wrapping-style'] : false; 69 $first_set = ( isset( $_POST['wcgw-wrapping-style']['name'][0] ) ) ? $_POST['wcgw-wrapping-style']['name'][0] : false; 70 71 if ( ! empty( $first_set ) ) { 72 $this->save_styles( $wcgw_wrapping_style ); 73 } else { 74 delete_option( 'wcgw-wrapping-style' ); 75 } 76 } 77 if ( filter_input( INPUT_POST, 'wcgw_note_submit' ) ) { 78 update_option( 'wcgw-charge-fee-message', filter_input( INPUT_POST, 'wcgw-charge-fee-message' ) ); 79 if ( filter_input( INPUT_POST, 'wcgw-message-charges' ) ) { 80 update_option( 'wcgw-message-charges', filter_input( INPUT_POST, 'wcgw-message-charges' ) ); 81 } else { 82 delete_option( 'wcgw-message-charges' ); 83 } 84 if ( filter_input( INPUT_POST, 'wcgw-add-message' ) ) { 85 update_option( 'wcgw-add-message', filter_input( INPUT_POST, 'wcgw-add-message' ) ); 86 } else { 87 delete_option( 'wcgw-add-message' ); 88 } 89 } 90 require_once WC_GIFTS_DIR . '/partials/gifts-settings.php'; 91 } 92 93 /** 94 * Register all media library related scripts 95 */ 96 public function register_media_related_scripts() { 97 wp_enqueue_media(); 98 } 99 100 /** 101 * register all admin scripts related to this plugin 102 */ 103 public function register_admin_scripts() { 104 wp_enqueue_style( 'wc-gift-admin-style', WC_GIFTS_URL . 'assets/admin/css/style.css', array(), WC_GIFTS_VERSION ); 105 wp_enqueue_script( 'wc-gift-admin-script', WC_GIFTS_URL . 'assets/admin/js/script.js', array( 'jquery' ), WC_GIFTS_VERSION ); 106 } 113 107 114 108 } 115 109 116 110 WCGR_Gift_Wrapping_Base_Settings::instance(); 117 if ( !class_exists('CodupAds')){118 require_once WC_GIFTS_DIR . '/lib/codupads/codupads.php';111 if ( ! class_exists( 'CodupAds' ) ) { 112 require_once WC_GIFTS_DIR . '/lib/codupads/codupads.php'; 119 113 } 120 new CodupAds(); 114 new CodupAds(); 121 115 -
woo-product-as-gift/trunk/lib/codupads/codupads.php
r2022730 r2703109 1 1 <?php 2 if ( ! class_exists('CodupAds') ) :2 if ( ! class_exists( 'CodupAds' ) ) : 3 3 4 class CodupAds {4 class CodupAds { 5 5 6 public function __construct() {7 add_shortcode('codup_ads_top', array($this, 'codup_render_top_ads'));8 add_shortcode('codup_ads_right', array($this, 'codup_render_right_ads'));9 add_action('admin_init', array($this, 'add_style_scripts'));10 add_action('init', array($this, 'add_style_scripts'));11 }6 public function __construct() { 7 add_shortcode( 'codup_ads_top', array( $this, 'codup_render_top_ads' ) ); 8 add_shortcode( 'codup_ads_right', array( $this, 'codup_render_right_ads' ) ); 9 add_action( 'admin_init', array( $this, 'add_style_scripts' ) ); 10 add_action( 'init', array( $this, 'add_style_scripts' ) ); 11 } 12 12 13 function cwrf_get_woo_version_number() { 14 if ( !function_exists('get_plugins') ) 15 require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 13 function cwrf_get_woo_version_number() { 14 if ( ! function_exists( 'get_plugins' ) ) { 15 require_once ABSPATH . 'wp-admin/includes/plugin.php'; 16 } 16 17 17 $plugin_folder = get_plugins('/' . 'woocommerce');18 $plugin_file= 'woocommerce.php';18 $plugin_folder = get_plugins( '/' . 'woocommerce' ); 19 $plugin_file = 'woocommerce.php'; 19 20 20 if ( isset($plugin_folder[$plugin_file]['Version']) ) { 21 return $plugin_folder[$plugin_file]['Version']; 22 } 23 else { 21 if ( isset( $plugin_folder[ $plugin_file ]['Version'] ) ) { 22 return $plugin_folder[ $plugin_file ]['Version']; 23 } else { 24 24 25 return NULL;26 }27 }25 return null; 26 } 27 } 28 28 29 function add_style_scripts() {30 $pluginConfig = array(31 "pluginName"=> WC_GIFTS_NAME,32 "pluginVersion"=> WC_GIFTS_VERSION,33 "pageSlug"=> WC_GIFTS_SLUG,34 "wpVersion" => get_bloginfo('version'),35 "wcVersion" => $this->cwrf_get_woo_version_number() 36 );37 wp_enqueue_script(WC_GIFTS_NAME, plugin_dir_url(__FILE__) . 'scripts/adscript.js', array('jquery'), WC_GIFTS_VERSION, false);38 wp_enqueue_style(WC_GIFTS_NAME . '- codupads-styles', plugin_dir_url(__FILE__) . 'styles/style.css', array(), WC_GIFTS_VERSION, 'all');39 wp_localize_script(WC_GIFTS_NAME, 'PluginConfig', $pluginConfig);40 }29 function add_style_scripts() { 30 $pluginConfig = array( 31 'pluginName' => WC_GIFTS_NAME, 32 'pluginVersion' => WC_GIFTS_VERSION, 33 'pageSlug' => WC_GIFTS_SLUG, 34 'wpVersion' => get_bloginfo( 'version' ), 35 'wcVersion' => $this->cwrf_get_woo_version_number(), 36 ); 37 wp_enqueue_script( WC_GIFTS_NAME, plugin_dir_url( __FILE__ ) . 'scripts/adscript.js', array( 'jquery' ), WC_GIFTS_VERSION, false ); 38 wp_enqueue_style( WC_GIFTS_NAME . '- codupads-styles', plugin_dir_url( __FILE__ ) . 'styles/style.css', array(), WC_GIFTS_VERSION, 'all' ); 39 wp_localize_script( WC_GIFTS_NAME, 'PluginConfig', $pluginConfig ); 40 } 41 41 42 function codup_render_top_ads() {43 echo '<div id="codup-topad" class="wrap"></div>';44 }42 function codup_render_top_ads() { 43 echo '<div id="codup-topad" class="wrap"></div>'; 44 } 45 45 46 function codup_render_right_ads() {47 echo '<div id="codup-rightad" class="stick-to-right"></div>';48 }46 function codup_render_right_ads() { 47 echo '<div id="codup-rightad" class="stick-to-right"></div>'; 48 } 49 49 50 }50 } 51 51 52 52 53 53 54 54 endif; 55 56 57 55 58 56 57 58 -
woo-product-as-gift/trunk/lib/codupads/scripts/adscript.js
r2119189 r2703109 1 1 (function($) { 2 3 4 $.ajax({5 url: "http://wpads.coduplabs.com/",6 7 data: {8 pluginConfig: PluginConfig9 },10 type: 'GET',11 headers: {12 'X-Codup-Ads' : 'ae237uiew4222ghq'13 },14 success: appendAds15 });16 17 function appendAds(data) {18 2 19 data = JSON.parse(data); 20 $('#codup-topad').html(data.topad); 21 $('#codup-rightad').html(data.rightad); 3 $.ajax( 4 { 5 url: "http://wpads.coduplabs.com/", 22 6 23 } 24 25 })(jQuery); 7 data: { 8 pluginConfig: PluginConfig 9 }, 10 type: 'GET', 11 headers: { 12 'X-Codup-Ads' : 'ae237uiew4222ghq' 13 }, 14 success: appendAds 15 } 16 ); 17 18 function appendAds(data) { 19 20 data = JSON.parse( data ); 21 $( '#codup-topad' ).html( data.topad ); 22 $( '#codup-rightad' ).html( data.rightad ); 23 24 } 25 26 })( jQuery ); -
woo-product-as-gift/trunk/lib/codupads/styles/style.css
r2022730 r2703109 1 1 .codup-settings-page { 2 width : 68%;3 display: inline-block;4 float: left;2 width : 68%; 3 display: inline-block; 4 float: left; 5 5 } 6 6 7 7 .stick-to-right { 8 margin-top: 60px;9 display: inline-block;8 margin-top: 60px; 9 display: inline-block; 10 10 } 11 11 12 12 #codup-topad{ 13 13 box-shadow: 0 1px 1px 0 rgba(0,0,0,.1); 14 background-color: white;15 margin-right: 0;14 background-color: white; 15 margin-right: 0; 16 16 } 17 17 18 18 #codup-topad img{ 19 19 vertical-align: middle; 20 padding: 10px;21 height: 16px;20 padding: 10px; 21 height: 16px; 22 22 } 23 23 #codup-topad a{ -
woo-product-as-gift/trunk/partials/gifts-settings.php
r2022730 r2703109 1 <?php echo do_shortcode( "[codup_ads_top]"); ?>1 <?php echo do_shortcode( '[codup_ads_top]' ); ?> 2 2 <div class="wc-gifts-wrapper"> 3 <h2>Woocommerce Gifts Settings</h2>4 <?php5 $active_tab = "";6 if ( filter_input(INPUT_GET, 'page') == "wc-gift-settings") {7 if ( filter_input(INPUT_GET, 'tab') ) {8 $active_tab = $_GET['tab'];9 }10 }3 <h2>Woocommerce Gifts Settings</h2> 4 <?php 5 $active_tab = ''; 6 if ( filter_input( INPUT_GET, 'page' ) == 'wc-gift-settings' ) { 7 if ( filter_input( INPUT_GET, 'tab' ) ) { 8 $active_tab = $_GET['tab']; 9 } 10 } 11 11 12 require_once 'nav.php';13 switch ( $active_tab ) {14 case 'note':15 require_once 'note.php';16 break;17 default:18 require_once 'wrapping.php';19 break;20 }21 ?>12 require_once 'nav.php'; 13 switch ( $active_tab ) { 14 case 'note': 15 require_once 'note.php'; 16 break; 17 default: 18 require_once 'wrapping.php'; 19 break; 20 } 21 ?> 22 22 </div> -
woo-product-as-gift/trunk/partials/nav.php
r2022730 r2703109 1 <?php echo do_shortcode( "[codup_ads_top]"); ?>1 <?php echo do_shortcode( '[codup_ads_top]' ); ?> 2 2 <h2 class="nav-tab-wrapper wp-clearfix"> 3 <a href="admin.php?page=wc-gift-settings" class="nav-tab<?php echo ($active_tab == "") ? " nav-tab-active" : ""; ?>">Wrapping</a>4 <a href="admin.php?page=wc-gift-settings&tab=note" class="nav-tab<?php echo ($active_tab == "note") ? " nav-tab-active" : ""; ?>">Note</a>3 <a href="admin.php?page=wc-gift-settings" class="nav-tab<?php echo ( $active_tab == '' ) ? ' nav-tab-active' : ''; ?>">Wrapping</a> 4 <a href="admin.php?page=wc-gift-settings&tab=note" class="nav-tab<?php echo ( $active_tab == 'note' ) ? ' nav-tab-active' : ''; ?>">Note</a> 5 5 </h2> -
woo-product-as-gift/trunk/partials/note.php
r2388090 r2703109 1 <?php echo do_shortcode( "[codup_ads_top]"); ?>1 <?php echo do_shortcode( '[codup_ads_top]' ); ?> 2 2 <div class="wcgw-gifts-wrapper-section"> 3 <form class="wcgw-gifts-form" method="post">4 <table class="form-table">5 <tr valign="top">6 <th scope="row" class="titledesc">7 <label>Charge Fee for message</label>8 </th>9 <td>10 <input name="wcgw-charge-fee-message"<?php echo get_option("wcgw-charge-fee-message") ? " checked" : ""; ?> type="checkbox" />11 </td>12 </tr>13 <tr valign="top">14 <th scope="row" class="titledesc">15 <label>Charges for message</label>16 </th>17 <td>18 <input name="wcgw-message-charges" value="<?php echo get_option("wcgw-message-charges"); ?>" type="number" />19 </td>20 </tr>21 <tr valign="top">22 <th scope="row" class="titledesc">23 <label>Change Label for "Add a message with gift"</label>24 </th>25 <td>26 <input name="wcgw-add-message" type="text" value="<?php echo get_option("wcgw-add-message"); ?>" />27 </td>28 </tr>29 </table>30 <input type="submit" class="button button-primary" name="wcgw_note_submit" value="Apply">31 </form>3 <form class="wcgw-gifts-form" method="post"> 4 <table class="form-table"> 5 <tr valign="top"> 6 <th scope="row" class="titledesc"> 7 <label>Charge Fee for message</label> 8 </th> 9 <td> 10 <input name="wcgw-charge-fee-message"<?php echo get_option( 'wcgw-charge-fee-message' ) ? ' checked' : ''; ?> type="checkbox" /> 11 </td> 12 </tr> 13 <tr valign="top"> 14 <th scope="row" class="titledesc"> 15 <label>Charges for message</label> 16 </th> 17 <td> 18 <input name="wcgw-message-charges" value="<?php echo get_option( 'wcgw-message-charges' ); ?>" type="number" /> 19 </td> 20 </tr> 21 <tr valign="top"> 22 <th scope="row" class="titledesc"> 23 <label>Change Label for "Add a message with gift"</label> 24 </th> 25 <td> 26 <input name="wcgw-add-message" type="text" value="<?php echo get_option( 'wcgw-add-message' ); ?>" /> 27 </td> 28 </tr> 29 </table> 30 <input type="submit" class="button button-primary" name="wcgw_note_submit" value="Apply"> 31 </form> 32 32 </div> -
woo-product-as-gift/trunk/partials/wrapping.php
r2388090 r2703109 1 <?php echo do_shortcode( "[codup_ads_top]"); ?>1 <?php echo do_shortcode( '[codup_ads_top]' ); ?> 2 2 <div class="wcgw-gifts-wrapper-section"> 3 <form class="wcgw-gifts-form" method="post"> 4 <table class="form-table"> 5 <tr valign="top"> 6 <th scope="row"> 7 <label>Enable Gift Options</label> 8 <span class="help-notice" title="Enable gift options"></span> 9 </th> 10 <td> 11 <input name="wcgw-enable-gift-options"<?php echo get_option("wcgw-enable-gift-options") ? " checked" : ""; ?> type="checkbox" /> 12 </td> 13 </tr> 14 <tr valign="top"> 15 <th scope="row"> 16 <label>Change Label for "Is this gift"</label> 17 </th> 18 <td> 19 <input name="wcgw-is-this-gift" value="<?php echo get_option("wcgw-is-this-gift"); ?>" type="text" /> 20 </td> 21 </tr> 22 <tr valign="top"> 23 <th scope="row"> 24 <label>Add wrapping style</label> 25 </th> 26 <td> 27 <?php 28 $styles = get_option("wcgw-wrapping-style"); 29 $no_image = WC_GIFTS_URL . "assets/admin/img/no-image.jpg"; 30 if ( !empty($styles) ) { 31 32 $styles = json_decode($styles, true); 33 $total_styles = count($styles); 34 $x = 0; 35 foreach ( $styles as $style ) { 36 $x++; 37 $class = "dashicons-minus"; 38 if ( $x == $total_styles ) { 39 $class = "dashicons-plus"; 40 } 41 ?> 42 <div class="wcgw-wrapping-style"> 43 <div class="wcgw-wrapping-style-wrapper"> 44 <input name="wcgw-wrapping-style[name][]" value="<?php echo $style["name"]; ?>" placeholder="Title" type="text" /> 45 <input name="wcgw-wrapping-style[price][]" value="<?php echo $style["price"]; ?>" placeholder="Price" type="number" /> 46 <div class="upload"> 47 <?php 48 if ( !empty($style["image"]) ) { 49 $image = wp_get_attachment_thumb_url($style["image"]); 50 ?> 51 <img src="<?php echo $image; ?>" width="150" /> 52 <?php 53 } 54 else { 55 ?> 56 <img src="<?php echo $no_image; ?>" width="150" /> 57 <?php 58 } 59 ?> 60 <div> 61 <input name="wcgw-wrapping-style[image][]" data-image='<?php echo $no_image; ?>' value="<?php echo $style["image"]; ?>" type="hidden" /> 62 <button type="button" class="upload_image_button button">Upload</button> 63 </div> 64 </div> 65 66 </div> 67 <?php 68 69 if ( $x == $total_styles ) { 70 ?> 71 <!-- <p class="dashicons dashicons-minus last"></p> --> 3 <form class="wcgw-gifts-form" method="post"> 4 <table class="form-table"> 5 <tr valign="top"> 6 <th scope="row"> 7 <label>Enable Gift Options</label> 8 <span class="help-notice" title="Enable gift options"></span> 9 </th> 10 <td> 11 <input name="wcgw-enable-gift-options"<?php echo get_option( 'wcgw-enable-gift-options' ) ? ' checked' : ''; ?> type="checkbox" /> 12 </td> 13 </tr> 14 <tr valign="top"> 15 <th scope="row"> 16 <label>Change Label for "Is this gift"</label> 17 </th> 18 <td> 19 <input name="wcgw-is-this-gift" value="<?php echo get_option( 'wcgw-is-this-gift' ); ?>" type="text" /> 20 </td> 21 </tr> 22 <tr valign="top"> 23 <th scope="row"> 24 <label>Add wrapping style</label> 25 </th> 26 <td> 27 <?php 28 $styles = get_option( 'wcgw-wrapping-style' ); 29 $no_image = WC_GIFTS_URL . 'assets/admin/img/no-image.jpg'; 30 if ( ! empty( $styles ) ) { 72 31 73 <?php 74 } 75 76 ?> 77 <p class="dashicons <?php echo $class; ?>"></p> 78 </div> 79 <?php 80 } 81 } 82 else { 83 ?> 84 <div class="wcgw-wrapping-style"> 85 <div class="wcgw-wrapping-style-wrapper"> 86 <input name="wcgw-wrapping-style[name][]" value="" placeholder="Title" type="text" /> 87 <input name="wcgw-wrapping-style[price][]" value="" placeholder="Price" type="number" /> 88 <div class="upload"> 89 <img data-src="" src="<?php echo $no_image; ?>" width="150" /> 90 <div> 91 <input name="wcgw-wrapping-style[image][]" value="" type="hidden" /> 92 <button type="button" class="upload_image_button button">Upload</button> 93 </div> 94 </div> 95 </div> 96 <!-- <p class="dashicons dashicons-minus"></p> --> 97 <p class="dashicons dashicons-plus"></p> 98 </div> 99 <?php 100 } 101 ?> 102 </td> 103 </tr> 104 </table> 105 <input type="submit" class="button button-primary" name="wcgw_submit" value="Apply"> 106 </form> 32 $styles = json_decode( $styles, true ); 33 $total_styles = count( $styles ); 34 $x = 0; 35 foreach ( $styles as $style ) { 36 $x++; 37 $class = 'dashicons-minus'; 38 if ( $x == $total_styles ) { 39 $class = 'dashicons-plus'; 40 } 41 ?> 42 <div class="wcgw-wrapping-style"> 43 <div class="wcgw-wrapping-style-wrapper"> 44 <input name="wcgw-wrapping-style[name][]" value="<?php echo $style['name']; ?>" placeholder="Title" type="text" /> 45 <input name="wcgw-wrapping-style[price][]" value="<?php echo $style['price']; ?>" placeholder="Price" type="number" /> 46 <div class="upload"> 47 <?php 48 if ( ! empty( $style['image'] ) ) { 49 $image = wp_get_attachment_thumb_url( $style['image'] ); 50 ?> 51 <img src="<?php echo $image; ?>" width="150" /> 52 <?php 53 } else { 54 ?> 55 <img src="<?php echo $no_image; ?>" width="150" /> 56 <?php 57 } 58 ?> 59 <div> 60 <input name="wcgw-wrapping-style[image][]" data-image='<?php echo $no_image; ?>' value="<?php echo $style['image']; ?>" type="hidden" /> 61 <button type="button" class="upload_image_button button">Upload</button> 62 </div> 63 </div> 64 65 </div> 66 <?php 67 68 if ( $x == $total_styles ) { 69 ?> 70 <!-- <p class="dashicons dashicons-minus last"></p> --> 71 72 <?php 73 } 74 75 ?> 76 <p class="dashicons <?php echo $class; ?>"></p> 77 </div> 78 <?php 79 } 80 } else { 81 ?> 82 <div class="wcgw-wrapping-style"> 83 <div class="wcgw-wrapping-style-wrapper"> 84 <input name="wcgw-wrapping-style[name][]" value="" placeholder="Title" type="text" /> 85 <input name="wcgw-wrapping-style[price][]" value="" placeholder="Price" type="number" /> 86 <div class="upload"> 87 <img data-src="" src="<?php echo $no_image; ?>" width="150" /> 88 <div> 89 <input name="wcgw-wrapping-style[image][]" value="" type="hidden" /> 90 <button type="button" class="upload_image_button button">Upload</button> 91 </div> 92 </div> 93 </div> 94 <!-- <p class="dashicons dashicons-minus"></p> --> 95 <p class="dashicons dashicons-plus"></p> 96 </div> 97 <?php 98 } 99 ?> 100 </td> 101 </tr> 102 </table> 103 <input type="submit" class="button button-primary" name="wcgw_submit" value="Apply"> 104 </form> 107 105 </div> 108 106 <input id="defaultImg" name="wcgw-wrapping-style[image][]" data-image='<?php echo $no_image; ?>' value="" type="hidden" /> -
woo-product-as-gift/trunk/readme.txt
r2388090 r2703109 3 3 Tags: Product, Gift, Wrap, Woocommerce 4 4 Requires at least: 4.4 5 Tested up to: 5. 56 Stable tag: 1.1.1. 75 Tested up to: 5.9.2 6 Stable tag: 1.1.1.11 7 7 License: GPLv2 or later 8 8 -
woo-product-as-gift/trunk/woocommerce-gift-wrap.php
r2388090 r2703109 3 3 * Plugin Name: WooCommerce Product as Gift 4 4 * Description: This plugin gives you the ability to add gift wrapping on your order. 5 * Version: 1.1.1.1 05 * Version: 1.1.1.11 6 6 * Author: Codup.io 7 7 * Author URI: http://codup.io 8 8 * Requires at least: 4.4 9 * Tested up to: 5. 410 * 9 * Tested up to: 5.9.2 10 * 11 11 * Text Domain: product-as-gift 12 12 * Domain Path: /languages 13 * 13 * 14 14 * @package WooCommerce 15 15 * @category Core 16 16 * @author Codup.io 17 17 */ 18 if ( !defined('ABSPATH') ) { 19 exit; // Exit if accessed directly 20 } 21 if ( !defined('WC_GIFTS_NAME') ) 22 define('WC_GIFTS_NAME', 'WooCommerce Product as Gift'); 23 24 if ( !defined('WC_GIFTS_SLUG') ) 25 define('WC_GIFTS_SLUG', 'product-as-gift'); 26 27 if ( !defined('WC_GIFTS_VERSION') ) 28 define('WC_GIFTS_VERSION', '1.1.1.3'); 29 30 if ( !defined('WC_GIFTS_DIR') ) 31 define('WC_GIFTS_DIR', dirname(__FILE__)); 32 33 if ( !defined('WC_GIFTS_PATH') ) 34 define('WC_GIFTS_PATH', __FILE__); 35 36 if ( !defined('WC_GIFTS_URL') ) 37 define('WC_GIFTS_URL', plugin_dir_url(__FILE__)); 38 39 40 if ( !class_exists('WCGR_Gifts_Wrapping_Main') ) { 41 42 class WCGR_Gifts_Wrapping_Main { 43 44 protected $session = false; 45 46 public function __construct() { 47 add_action('plugins_loaded', array($this, 'init')); 48 add_action('wp_head', array($this, 'admin_url_init')); 49 add_action('wp_enqueue_scripts', array($this, 'register_scripts')); 50 add_action('woocommerce_checkout_update_order_meta', array($this, 'update_order_meta')); 51 add_action('woocommerce_before_checkout_form', array($this, 'add_giftwrap_to_checkout'), 10, 0); 52 add_action('woocommerce_cart_calculate_fees', array($this, 'cal_giftwrap_fees'), 10, 0); 53 add_action('wp_ajax_is_order_is_gift', array($this, 'is_order_is_gift')); 54 add_action('wp_ajax_nopriv_is_order_is_gift', array($this, 'is_order_is_gift')); 55 } 56 57 public function init_session() { 58 if ( session_id() == '' ) { 59 ob_start(); 60 session_start(); 61 ob_clean(); 62 } 63 } 64 65 public function init() { 66 // Checks if WooCommerce is active. 67 if ( in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins'))) ) { 68 if ( !class_exists('WC_Gift_Settings') ) { 69 include_once( 'class/class-wc-gift-settings.php' ); 70 } 71 } 72 } 73 74 public function update_order_meta($order_id) { 75 $order = wc_get_order($order_id); 76 $wrap_data = $_SESSION['wcgw_wrap_content']; 77 78 if ( isset($wrap_data["wrap"]) ) { 79 update_post_meta($order_id, "wrapping", $wrap_data["wrap"]); 80 } 81 if ( isset($wrap_data["message"]) ) { 82 update_post_meta($order_id, "message", $wrap_data["message"]); 83 } 84 } 85 86 /** 87 * add script to admin panel head section 88 */ 89 public function admin_url_init() { 90 ?> 91 <script language="javascript"> 92 if (!admin_url) { 93 var admin_url = "<?php echo admin_url('admin-ajax.php'); ?>"; 94 } 95 </script> 96 <?php 97 } 98 99 public function cal_giftwrap_fees() { 100 $this->init_session(); 101 if ( $_SESSION['is_this_gift'] == "1" ) { 102 if ( isset($_SESSION['wcgw_cart_fees']) ) { 103 WC()->cart->fees_api()->set_fees($_SESSION['wcgw_cart_fees']); 104 } 105 } 106 else { 107 unset($_SESSION['wcgw_cart_fees']); 108 unset($_SESSION['wcgw_wrap_content']); 109 } 110 } 111 112 public function get_style_by_key($key) { 113 if ( $key !== "" ) { 114 $all_styles = get_option("wcgw-wrapping-style"); 115 $all_styles = json_decode($all_styles, true); 116 if ( !empty($all_styles) ) { 117 return $all_styles[$key]; 118 } 119 } 120 return false; 121 } 122 123 public function get_styles_names() { 124 $styles_names = []; 125 $styles = get_option("wcgw-wrapping-style"); 126 $styles = json_decode($styles, true); 127 foreach ( $styles as $key => $style ) { 128 array_push($styles_names, $style["name"]); 129 } 130 return $styles_names; 131 } 132 133 public function is_order_is_gift() { 134 $this->init_session(); 135 if ( $_SESSION['is_this_gift'] == "1" ) { 136 $_SESSION['is_this_gift'] = "0"; 137 $this->remove_old_style_from_cart(); 138 unset($_SESSION['wcgw_cart_fees']); 139 unset($_SESSION['wcgw_wrap_content']); 140 } 141 else { 142 $_SESSION['is_this_gift'] = "1"; 143 } 144 wp_die(); 145 } 146 147 public function remove_old_style_from_cart() { 148 $WC_Cart = new WC_Cart(); 149 $fees = $WC_Cart->get_fees(); 150 $styles_names = $this->get_styles_names(); 151 if ( !empty($fees) ) { 152 foreach ( $fees as $key => $fee ) { 153 if ( in_array($fee->name, $styles_names) ) { 154 unset($fees[$key]); 155 } 156 } 157 } 158 return WC()->cart->fees_api()->set_fees($fees); 159 } 160 161 /** 162 * register all scripts related to this plugin 163 */ 164 public function register_scripts() { 165 wp_enqueue_script("wcgw-gift-script", WC_GIFTS_URL . 'assets/js/script.js', array('jquery'), WC_GIFTS_VERSION); 166 wp_enqueue_style("wcgw-gift-style", WC_GIFTS_URL . 'assets/css/style.css', array(), WC_GIFTS_VERSION); 167 } 168 169 public function add_giftwrap_to_checkout() { 170 $this->init_session(); 171 if ( !isset($_SESSION['is_this_gift']) ) { 172 $_SESSION['is_this_gift'] = "0"; 173 } 174 if ( get_option("wcgw-enable-gift-options") == "on" ) { 175 $selected = false; 176 $WC_Cart = new WC_Cart(); 177 if ( isset($_SESSION["wcgw_notice"]) ) { 178 ?> 179 <p class="wcgw-success-notice"><?php echo $_SESSION["wcgw_notice"]; ?></p> 180 <?php 181 unset($_SESSION["wcgw_notice"]); 182 } 183 ?> 184 <div class="woocommerce-info"><input type="checkbox"<?php echo ($_SESSION['is_this_gift'] == "1") ? " checked" : ""; ?> name="wcgw-apply-gift-options" /> <?php echo get_option("wcgw-is-this-gift"); ?></div> 185 <?php 186 if ( $_SESSION['is_this_gift'] == "1" ) { 187 if ( filter_input(INPUT_POST, "wcgw_select_style") != NULL ) { 188 $_SESSION['wcgw_notice'] = "Gift wrap successfully added into the cart."; 189 $quantity = WC()->cart->get_cart_contents_count(); 190 $selected_style_data = $this->get_style_by_key(filter_input(INPUT_POST, "wcgw_select_style")); 191 $this->remove_old_style_from_cart(); 192 if ( get_option("wcgw-charge-fee-message") == "on" ) { 193 $WC_Cart->add_fee($selected_style_data["name"], ($selected_style_data["price"] * $quantity) + get_option("wcgw-message-charges")); 194 } 195 else { 196 $WC_Cart->add_fee($selected_style_data["name"], ($selected_style_data["price"] * $quantity)); 197 } 198 $_SESSION['wcgw_cart_fees'] = $WC_Cart->get_fees(); 199 $_SESSION['wcgw_wrap_content'] = [ 200 "wrap" => $selected_style_data["name"], 201 "message" => filter_input(INPUT_POST, "wcgw_add_message_text"), 202 ]; 203 wp_redirect(wc_get_checkout_url()); 204 } 205 ?> 206 <form method="post" class="wcgw_giftwrap_products"> 207 <?php 208 if ( !empty($_SESSION['wcgw_cart_fees']) ) { 209 $selected = reset($_SESSION['wcgw_cart_fees']); 210 $this->giftwrap_products($selected->name); 211 } 212 else { 213 $this->giftwrap_products(); 214 } 215 if ( get_option("wcgw-add-message") ) { 216 ?> 217 <p><?php echo get_option("wcgw-add-message"); ?><span class="wcgw_message_charges_message"><?php 218 if ( get_option("wcgw-message-charges") != "" && get_option("wcgw-message-charges") != "0" && get_option("wcgw-charge-fee-message") ) { 219 echo " - (" . get_woocommerce_currency_symbol() . get_option("wcgw-message-charges") . " message charges will be charged)"; 220 } 221 ?></span></p> 222 <?php 223 } 224 else { 225 ?> 226 <p>Add a message with gift<span class="wcgw_message_charges_message"><?php 227 if ( get_option("wcgw-message-charges") != "" && get_option("wcgw-message-charges") != "0" && get_option("wcgw-charge-fee-message") ) { 228 echo " - (" . get_woocommerce_currency_symbol() . get_option("wcgw-message-charges") . " message charges will be charged)"; 229 } 230 ?></span></p> 231 <?php 232 } 233 ?> 234 <textarea name="wcgw_add_message_text" required maxlength="500"><?php echo (filter_input(INPUT_POST, "wcgw_add_message_text")) ? filter_input(INPUT_POST, "wcgw_add_message_text") : ""; ?></textarea> 235 <br><br> 236 <button type="submit" id="wcgw_giftwrap_submit" class="button btn">Add Gift Wrap</button> 237 </form> 238 <?php 239 } 240 } 241 else { 242 $_SESSION['is_this_gift'] = "0"; 243 } 244 } 245 246 public function giftwrap_products($selected = false) { 247 $styles = get_option("wcgw-wrapping-style"); 248 $styles = json_decode($styles); 249 if ( !empty($styles) ) { 250 ?> 251 <ul> 252 <?php 253 foreach ( $styles as $key => $style ) { 254 ?> 255 <li> 256 <p><input type="radio" required name="wcgw_select_style"<?php echo ($selected == $style->name) ? " checked" : ""; ?> value="<?php echo $key; ?>" /> <?php echo get_woocommerce_currency_symbol() . $style->price; ?> - <?php echo $style->name; ?></p> 257 <div class="wcgw_image"> 258 <img src="<?php echo ($style->image == "") ? plugin_dir_url(__FILE__).'assets/admin/img/no-image.jpg' : wp_get_attachment_image_src($style->image, ["300", "300"])[0]; ?>" width="100%" class="showImg" /> 259 </div> 260 </li> 261 <?php 262 } 263 ?> 264 </ul> 265 <br><br> 266 <?php 267 } 268 } 269 270 } 271 272 $WCGR_Gifts_Wrapping_Main = new WCGR_Gifts_Wrapping_Main(); 273 } 18 if ( ! defined( 'ABSPATH' ) ) { 19 exit; // Exit if accessed directly 20 } 21 if ( ! defined( 'WC_GIFTS_NAME' ) ) { 22 define( 'WC_GIFTS_NAME', 'WooCommerce Product as Gift' ); 23 } 24 25 if ( ! defined( 'WC_GIFTS_SLUG' ) ) { 26 define( 'WC_GIFTS_SLUG', 'product-as-gift' ); 27 } 28 29 if ( ! defined( 'WC_GIFTS_VERSION' ) ) { 30 define( 'WC_GIFTS_VERSION', '1.1.1.11' ); 31 } 32 33 if ( ! defined( 'WC_GIFTS_DIR' ) ) { 34 define( 'WC_GIFTS_DIR', dirname( __FILE__ ) ); 35 } 36 37 if ( ! defined( 'WC_GIFTS_PATH' ) ) { 38 define( 'WC_GIFTS_PATH', __FILE__ ); 39 } 40 41 if ( ! defined( 'WC_GIFTS_URL' ) ) { 42 define( 'WC_GIFTS_URL', plugin_dir_url( __FILE__ ) ); 43 } 44 45 46 if ( ! class_exists( 'WCGR_Gifts_Wrapping_Main' ) ) { 47 48 class WCGR_Gifts_Wrapping_Main { 49 50 protected $session = false; 51 52 public function __construct() { 53 add_action( 'plugins_loaded', array( $this, 'init' ) ); 54 add_action( 'wp_head', array( $this, 'admin_url_init' ) ); 55 add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) ); 56 add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'update_order_meta' ) ); 57 add_action( 'woocommerce_before_checkout_form', array( $this, 'add_giftwrap_to_checkout' ), 10, 0 ); 58 add_action( 'woocommerce_cart_calculate_fees', array( $this, 'cal_giftwrap_fees' ), 10, 0 ); 59 add_action( 'wp_ajax_is_order_is_gift', array( $this, 'is_order_is_gift' ) ); 60 add_action( 'wp_ajax_nopriv_is_order_is_gift', array( $this, 'is_order_is_gift' ) ); 61 } 62 63 public function init_session() { 64 if ( session_id() == '' ) { 65 ob_start(); 66 session_start(); 67 ob_clean(); 68 } 69 } 70 71 public function init() { 72 // Checks if WooCommerce is active. 73 if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { 74 if ( ! class_exists( 'WC_Gift_Settings' ) ) { 75 include_once 'class/class-wc-gift-settings.php'; 76 } 77 } 78 } 79 80 public function update_order_meta( $order_id ) { 81 $order = wc_get_order( $order_id ); 82 $wrap_data = $_SESSION['wcgw_wrap_content']; 83 84 if ( isset( $wrap_data['wrap'] ) ) { 85 update_post_meta( $order_id, 'wrapping', $wrap_data['wrap'] ); 86 } 87 if ( isset( $wrap_data['message'] ) ) { 88 update_post_meta( $order_id, 'message', $wrap_data['message'] ); 89 } 90 } 91 92 /** 93 * add script to admin panel head section 94 */ 95 public function admin_url_init() { 96 ?> 97 <script language="javascript"> 98 if (!admin_url) { 99 var admin_url = "<?php echo admin_url( 'admin-ajax.php' ); ?>"; 100 } 101 </script> 102 <?php 103 } 104 105 public function cal_giftwrap_fees() { 106 $this->init_session(); 107 if ( $_SESSION['is_this_gift'] == '1' ) { 108 if ( isset( $_SESSION['wcgw_cart_fees'] ) ) { 109 WC()->cart->fees_api()->set_fees( $_SESSION['wcgw_cart_fees'] ); 110 } 111 } else { 112 unset( $_SESSION['wcgw_cart_fees'] ); 113 unset( $_SESSION['wcgw_wrap_content'] ); 114 } 115 } 116 117 public function get_style_by_key( $key ) { 118 if ( $key !== '' ) { 119 $all_styles = get_option( 'wcgw-wrapping-style' ); 120 $all_styles = json_decode( $all_styles, true ); 121 if ( ! empty( $all_styles ) ) { 122 return $all_styles[ $key ]; 123 } 124 } 125 return false; 126 } 127 128 public function get_styles_names() { 129 $styles_names = array(); 130 $styles = get_option( 'wcgw-wrapping-style' ); 131 $styles = json_decode( $styles, true ); 132 foreach ( $styles as $key => $style ) { 133 array_push( $styles_names, $style['name'] ); 134 } 135 return $styles_names; 136 } 137 138 public function is_order_is_gift() { 139 $this->init_session(); 140 if ( $_SESSION['is_this_gift'] == '1' ) { 141 $_SESSION['is_this_gift'] = '0'; 142 $this->remove_old_style_from_cart(); 143 unset( $_SESSION['wcgw_cart_fees'] ); 144 unset( $_SESSION['wcgw_wrap_content'] ); 145 } else { 146 $_SESSION['is_this_gift'] = '1'; 147 } 148 wp_die(); 149 } 150 151 public function remove_old_style_from_cart() { 152 $WC_Cart = new WC_Cart(); 153 $fees = $WC_Cart->get_fees(); 154 $styles_names = $this->get_styles_names(); 155 if ( ! empty( $fees ) ) { 156 foreach ( $fees as $key => $fee ) { 157 if ( in_array( $fee->name, $styles_names ) ) { 158 unset( $fees[ $key ] ); 159 } 160 } 161 } 162 return WC()->cart->fees_api()->set_fees( $fees ); 163 } 164 165 /** 166 * register all scripts related to this plugin 167 */ 168 public function register_scripts() { 169 wp_enqueue_script( 'wcgw-gift-script', WC_GIFTS_URL . 'assets/js/script.js', array( 'jquery' ), WC_GIFTS_VERSION ); 170 wp_enqueue_style( 'wcgw-gift-style', WC_GIFTS_URL . 'assets/css/style.css', array(), WC_GIFTS_VERSION ); 171 } 172 173 public function add_giftwrap_to_checkout() { 174 $this->init_session(); 175 if ( ! isset( $_SESSION['is_this_gift'] ) ) { 176 $_SESSION['is_this_gift'] = '0'; 177 } 178 if ( get_option( 'wcgw-enable-gift-options' ) == 'on' ) { 179 $selected = false; 180 $WC_Cart = new WC_Cart(); 181 if ( isset( $_SESSION['wcgw_notice'] ) ) { 182 ?> 183 <p class="wcgw-success-notice"><?php echo $_SESSION['wcgw_notice']; ?></p> 184 <?php 185 unset( $_SESSION['wcgw_notice'] ); 186 } 187 ?> 188 <div class="woocommerce-info"><input type="checkbox"<?php echo ( $_SESSION['is_this_gift'] == '1' ) ? ' checked' : ''; ?> name="wcgw-apply-gift-options" /> <?php echo get_option( 'wcgw-is-this-gift' ); ?></div> 189 <?php 190 if ( $_SESSION['is_this_gift'] == '1' ) { 191 if ( filter_input( INPUT_POST, 'wcgw_select_style' ) != null ) { 192 $_SESSION['wcgw_notice'] = 'Gift wrap successfully added into the cart.'; 193 $quantity = WC()->cart->get_cart_contents_count(); 194 $selected_style_data = $this->get_style_by_key( filter_input( INPUT_POST, 'wcgw_select_style' ) ); 195 $this->remove_old_style_from_cart(); 196 if ( get_option( 'wcgw-charge-fee-message' ) == 'on' ) { 197 $WC_Cart->add_fee( $selected_style_data['name'], ( $selected_style_data['price'] * $quantity ) + get_option( 'wcgw-message-charges' ) ); 198 } else { 199 $WC_Cart->add_fee( $selected_style_data['name'], ( $selected_style_data['price'] * $quantity ) ); 200 } 201 $_SESSION['wcgw_cart_fees'] = $WC_Cart->get_fees(); 202 $_SESSION['wcgw_wrap_content'] = array( 203 'wrap' => $selected_style_data['name'], 204 'message' => filter_input( INPUT_POST, 'wcgw_add_message_text' ), 205 ); 206 wp_redirect( wc_get_checkout_url() ); 207 } 208 ?> 209 <form method="post" class="wcgw_giftwrap_products"> 210 <?php 211 if ( ! empty( $_SESSION['wcgw_cart_fees'] ) ) { 212 $selected = reset( $_SESSION['wcgw_cart_fees'] ); 213 $this->giftwrap_products( $selected->name ); 214 } else { 215 $this->giftwrap_products(); 216 } 217 if ( get_option( 'wcgw-add-message' ) ) { 218 ?> 219 <p><?php echo get_option( 'wcgw-add-message' ); ?><span class="wcgw_message_charges_message"> 220 <?php 221 if ( get_option( 'wcgw-message-charges' ) != '' && get_option( 'wcgw-message-charges' ) != '0' && get_option( 'wcgw-charge-fee-message' ) ) { 222 echo ' - (' . get_woocommerce_currency_symbol() . get_option( 'wcgw-message-charges' ) . ' message charges will be charged)'; 223 } 224 ?> 225 </span></p> 226 <?php 227 } else { 228 ?> 229 <p>Add a message with gift<span class="wcgw_message_charges_message"> 230 <?php 231 if ( get_option( 'wcgw-message-charges' ) != '' && get_option( 'wcgw-message-charges' ) != '0' && get_option( 'wcgw-charge-fee-message' ) ) { 232 echo ' - (' . get_woocommerce_currency_symbol() . get_option( 'wcgw-message-charges' ) . ' message charges will be charged)'; 233 } 234 ?> 235 </span></p> 236 <?php 237 } 238 ?> 239 <textarea name="wcgw_add_message_text" required maxlength="500"><?php echo ( filter_input( INPUT_POST, 'wcgw_add_message_text' ) ) ? filter_input( INPUT_POST, 'wcgw_add_message_text' ) : ''; ?></textarea> 240 <br><br> 241 <button type="submit" id="wcgw_giftwrap_submit" class="button btn">Add Gift Wrap</button> 242 </form> 243 <?php 244 } 245 } else { 246 $_SESSION['is_this_gift'] = '0'; 247 } 248 } 249 250 public function giftwrap_products( $selected = false ) { 251 $styles = get_option( 'wcgw-wrapping-style' ); 252 $styles = json_decode( $styles ); 253 if ( ! empty( $styles ) ) { 254 ?> 255 <ul> 256 <?php 257 foreach ( $styles as $key => $style ) { 258 ?> 259 <li> 260 <p><input type="radio" required name="wcgw_select_style"<?php echo ( $selected == $style->name ) ? ' checked' : ''; ?> value="<?php echo $key; ?>" /> <?php echo get_woocommerce_currency_symbol() . $style->price; ?> - <?php echo $style->name; ?></p> 261 <div class="wcgw_image"> 262 <img src="<?php echo ( $style->image == '' ) ? plugin_dir_url( __FILE__ ) . 'assets/admin/img/no-image.jpg' : wp_get_attachment_image_src( $style->image, array( '300', '300' ) )[0]; ?>" width="100%" class="showImg" /> 263 </div> 264 </li> 265 <?php 266 } 267 ?> 268 </ul> 269 <br><br> 270 <?php 271 } 272 } 273 274 } 275 276 $WCGR_Gifts_Wrapping_Main = new WCGR_Gifts_Wrapping_Main(); 277 }
Note: See TracChangeset
for help on using the changeset viewer.