shatner_label = get_option('shatner_label', "Name your own price"); add_action('wp_enqueue_scripts', function () { wp_enqueue_script('shatner', plugins_url('/shatner.js',__FILE__), array('jquery') ); }); if ( is_admin() ){ // admin actions $this->init_form_fields(); add_action( 'admin_menu', array($this, 'add_shatner_menu' )); add_action( 'admin_init', array($this, 'admin_init' )); add_action('woocommerce_before_calculate_totals', array($this, 'add_custom_price' )); add_action('woocommerce_product_options_pricing', array($this, 'add_donation_radio')); add_action('save_post', array($this, 'set_named_price')); } else { if(get_option('use_shatner_templates', 1 ) == 1) { add_filter('woocommerce_locate_template', array($this, 'template_override'),10,3); add_filter('woocommerce_loop_add_to_cart_link', array($this, 'remove_link'),10); } add_action('woocommerce_product_options_pricing', array($this, 'add_donation_radio')); add_action('save_post', array($this, 'set_named_price')); add_action('woocommerce_add_to_cart', array($this, 'add_to_cart_hook')); add_action('woocommerce_before_calculate_totals', array($this, 'add_custom_price' )); add_action('init', array($this, 'init_css')); } } public function remove_link($link) { global $post; $post = get_post_meta($post->ID, '_own_price', true); if ($post === 'yes') return ''; return $link; } public function add_shatner_menu() { add_options_page( 'Shatner Plugin Settings', 'Shatner Settings', 'manage_options', 'shatner_plugin', array($this, 'shatner_plugin_settings_page') ); } public function shatner_plugin_settings_page() { include(sprintf("%s/templates/settings.php", dirname(__FILE__))); } /** * hook into WP's admin_init action hook */ public function admin_init() { // add your settings section add_settings_section( 'wp_plugin_template-section_shatner', 'Shatner Plugin Template Settings', array($this, 'settings_section_shatner_plugin_template'), 'wp_plugin_template_shatner' ); foreach($this->form_fields as $setting) { // register your plugin's settings register_setting('wp_plugin_template-group-shatner', $setting['title']); // add your setting's fields add_settings_field( $setting['title'], $setting['description'], array(&$this, 'settings_field_input_'. $setting['type']), 'wp_plugin_template_shatner', 'wp_plugin_template-section_shatner', array( 'field' => $setting['title'] ) ); } } // END public static function activate public function init_form_fields() { $this->form_fields = array( array( 'type' => 'text', 'title' => esc_html__('shatner_label', 'woothemes'), 'description' => esc_html__('Shatner Label', 'woothemes'), 'default' => esc_html__('Name your own price', 'woothemes') ), array( 'type' => 'radio_button', 'title' => esc_html__('use_shatner_templates', 'woothemes'), 'description' => esc_html__('Shatner Templates override pricing, disable if you want to customize using your theme', 'woothemes'), 'default' => esc_html__('1', 'woothemes') ) ); } public function settings_section_shatner_plugin_template() { // Think of this as help text for the section. echo 'These settings set values for Shatner'; } /** * This function provides text inputs for settings fields */ public function settings_field_input_text($args) { // Get the field name from the $args array $field = $args['field']; // Get the value of this setting $value = get_option($field); // echo a proper input type="text" echo sprintf('', $field, $field, $value); } // END public function settings_field_input_text($args) /** * This function provides text inputs for settings fields */ public function settings_field_input_radio_button($args) { // Get the field name from the $args array $field = $args['field']; // Get the value of this setting $value = get_option($field); $html = ' '; $html .= '
'; $html .= ' '; $html .= ' '; echo $html; } // END public function settings_field_input_radio($args) public function template_override($template, $template_name, $template_path ) { // Modification: Get the template from this plugin, if it exists $plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) ). '/templates/'; if ( file_exists( $plugin_path . $template_name ) ) { $template = $plugin_path . $template_name; return $template; } return $template; } public function init_css() { wp_register_style('donation_css', plugins_url('custom_styles.css',__FILE__ ), false, '1.0.1', 'all'); wp_enqueue_style( 'donation_css' ); } public function add_to_cart_hook($key) { global $woocommerce; foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) { if(!get_post_meta($values['product_id'], '_own_price', true ) || get_post_meta($values['product_id'], '_own_price', true ) === 'no') { $values['data']->set_price($_POST['price']); continue; } $thousands_sep = wp_specialchars_decode( stripslashes( get_option( 'woocommerce_price_thousand_sep' ) ), ENT_QUOTES ); $decimal_sep = stripslashes( get_option( 'woocommerce_price_decimal_sep' ) ); $_POST['price'] = str_replace($thousands_sep, '', $_POST['price']); $_POST['price'] = str_replace($decimal_sep, '.', $_POST['price']); $_POST['price'] = wc_format_decimal($_POST['price']); if($cart_item_key == $key) { $values['data']->set_price($_POST['price']); $woocommerce->session->__set($key .'_named_price', $_POST['price']); } } return $key; } public function set_named_price($post) { if(isset($_POST['_own_price'])){ if(!get_post_meta($_POST['post_ID'], '_own_price', true )){ add_post_meta($_POST['post_ID'], '_own_price', $_POST['_own_price']); } else { update_post_meta($_POST['post_ID'], '_own_price', $_POST['_own_price']); } } if(isset($_POST['_own_price_enforce_minimum'])){ if(!get_post_meta($_POST['post_ID'], '_own_price_enforce_minimum', true )){ add_post_meta($_POST['post_ID'], '_own_price_enforce_minimum', $_POST['_own_price_enforce_minimum']); } else { update_post_meta($_POST['post_ID'], '_own_price_enforce_minimum', $_POST['_own_price_enforce_minimum']); } } } public function add_donation_radio($content) { global $post; woocommerce_wp_radio(array( 'id' => '_own_price', 'class' => 'wc_own_price short', 'label' => esc_html__( 'Name your own price', 'woocommerce' ), 'options' => array( 'yes' => 'Yes', 'no' => 'No', ) ) ); woocommerce_wp_radio(array( 'id' => '_own_price_enforce_minimum', 'class' => 'wc_own_price_e short', 'label' => esc_html__( 'Enforce "Regular price" as the minimum price', 'woocommerce' ), 'options' => array( 'yes' => 'Yes', 'no' => 'No', ) ) ); } public function add_custom_price( $cart_object ) { global $woocommerce; foreach ( $cart_object->cart_contents as $key => $value ) { if(!get_post_meta($value['product_id'], '_own_price', true ) || get_post_meta($value['product_id'], '_own_price', true ) === 'no') { continue; } $named_price = $woocommerce->session->__get($key .'_named_price'); if($named_price) { $product = $value['data']; $product->set_price( $named_price ); } } } } new SV_WC_Donation(); BEGIN:VCALENDAR VERSION:2.0 PRODID:-//REACH Foundation - ECPv6.15.17.1//NONSGML v1.0//EN CALSCALE:GREGORIAN METHOD:PUBLISH X-WR-CALNAME:REACH Foundation X-ORIGINAL-URL:https://reachfoundation.life X-WR-CALDESC:Events for REACH Foundation REFRESH-INTERVAL;VALUE=DURATION:PT1H X-Robots-Tag:noindex X-PUBLISHED-TTL:PT1H BEGIN:VTIMEZONE TZID:America/Toronto BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20140309T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20141102T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20150308T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20151101T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20160313T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20161106T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20170312T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20171105T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20180311T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20181104T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20190310T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20191103T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20200308T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20201101T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20210314T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20211107T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20220313T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20221106T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20230312T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20231105T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20240310T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20241103T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20250309T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20251102T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20260308T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20261101T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20270314T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20271107T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20280312T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20281105T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20290311T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20291104T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20300310T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20301103T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20310309T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20311102T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20320314T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20321107T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20330313T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20331106T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20340312T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20341105T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20350311T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20351104T060000 END:STANDARD BEGIN:DAYLIGHT TZOFFSETFROM:-0500 TZOFFSETTO:-0400 TZNAME:EDT DTSTART:20360309T070000 END:DAYLIGHT BEGIN:STANDARD TZOFFSETFROM:-0400 TZOFFSETTO:-0500 TZNAME:EST DTSTART:20361102T060000 END:STANDARD END:VTIMEZONE BEGIN:VEVENT DTSTART;VALUE=DATE:20150913 DTEND;VALUE=DATE:20350914 DTSTAMP:20260317T063314 CREATED:20140911T154529Z LAST-MODIFIED:20140911T154529Z UID:317-1442102400-2073340799@reachfoundation.life SUMMARY:Community Carnaval DESCRIPTION:Fusce dapibus\, tellus ac cursus commodo\, tortor mauris condimentum nibh\, ut fermentum massa justo sit amet risus. Nulla vitae elit libero\, a pharetra augue. Nullam id dolor id nibh ultricies vehicula ut id elit. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Lorem ipsum dolor sit amet\, consectetur adipiscing elit. Maecenas faucibus mollis interdum. Cum sociis natoque penatibus et magnis dis parturient montes\, nascetur ridiculus mus. \nCras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus\, tellus ac cursus commodo\, tortor mauris condimentum nibh\, ut fermentum massa justo sit amet risus. Lorem ipsum dolor sit amet\, consectetur adipiscing elit. Curabitur blandit tempus porttitor. \nVestibulum id ligula porta felis euismod semper. Praesent commodo cursus magna\, vel scelerisque nisl consectetur et. Vestibulum id ligula porta felis euismod semper. Cum sociis natoque penatibus et magnis dis parturient montes\, nascetur ridiculus mus. Morbi leo risus\, porta ac consectetur ac\, vestibulum at eros. Nullam id dolor id nibh ultricies vehicula ut id elit. URL:https://reachfoundation.life/event/community-carnaval/ LOCATION:path ATTACH;FMTTYPE=image/jpeg:https://reachfoundation.life/wp-content/uploads/2014/09/path.jpg END:VEVENT BEGIN:VEVENT DTSTART;VALUE=DATE:20150913 DTEND;VALUE=DATE:20350914 DTSTAMP:20260317T063314 CREATED:20140911T154529Z LAST-MODIFIED:20140911T154529Z UID:318-1442102400-2073340799@reachfoundation.life SUMMARY:Community Carnaval DESCRIPTION:Fusce dapibus\, tellus ac cursus commodo\, tortor mauris condimentum nibh\, ut fermentum massa justo sit amet risus. Nulla vitae elit libero\, a pharetra augue. Nullam id dolor id nibh ultricies vehicula ut id elit. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Lorem ipsum dolor sit amet\, consectetur adipiscing elit. Maecenas faucibus mollis interdum. Cum sociis natoque penatibus et magnis dis parturient montes\, nascetur ridiculus mus. \nCras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus\, tellus ac cursus commodo\, tortor mauris condimentum nibh\, ut fermentum massa justo sit amet risus. Lorem ipsum dolor sit amet\, consectetur adipiscing elit. Curabitur blandit tempus porttitor. \nVestibulum id ligula porta felis euismod semper. Praesent commodo cursus magna\, vel scelerisque nisl consectetur et. Vestibulum id ligula porta felis euismod semper. Cum sociis natoque penatibus et magnis dis parturient montes\, nascetur ridiculus mus. Morbi leo risus\, porta ac consectetur ac\, vestibulum at eros. Nullam id dolor id nibh ultricies vehicula ut id elit. URL:https://reachfoundation.life/event/community-carnaval-2/ LOCATION:path ATTACH;FMTTYPE=image/jpeg:https://reachfoundation.life/wp-content/uploads/2014/09/path.jpg END:VEVENT BEGIN:VEVENT DTSTART;VALUE=DATE:20150913 DTEND;VALUE=DATE:20350914 DTSTAMP:20260317T063314 CREATED:20140911T154529Z LAST-MODIFIED:20140911T154529Z UID:356-1442102400-2073340799@reachfoundation.life SUMMARY:Community Carnaval DESCRIPTION:Fusce dapibus\, tellus ac cursus commodo\, tortor mauris condimentum nibh\, ut fermentum massa justo sit amet risus. Nulla vitae elit libero\, a pharetra augue. Nullam id dolor id nibh ultricies vehicula ut id elit. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Lorem ipsum dolor sit amet\, consectetur adipiscing elit. Maecenas faucibus mollis interdum. Cum sociis natoque penatibus et magnis dis parturient montes\, nascetur ridiculus mus. \nCras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Fusce dapibus\, tellus ac cursus commodo\, tortor mauris condimentum nibh\, ut fermentum massa justo sit amet risus. Lorem ipsum dolor sit amet\, consectetur adipiscing elit. Curabitur blandit tempus porttitor. \nVestibulum id ligula porta felis euismod semper. Praesent commodo cursus magna\, vel scelerisque nisl consectetur et. Vestibulum id ligula porta felis euismod semper. Cum sociis natoque penatibus et magnis dis parturient montes\, nascetur ridiculus mus. Morbi leo risus\, porta ac consectetur ac\, vestibulum at eros. Nullam id dolor id nibh ultricies vehicula ut id elit. URL:https://reachfoundation.life/event/community-carnaval-3/ LOCATION:path ATTACH;FMTTYPE=image/jpeg:https://reachfoundation.life/wp-content/uploads/2014/09/path-1.jpg END:VEVENT BEGIN:VEVENT DTSTART;TZID=America/Toronto:20150913T190000 DTEND;TZID=America/Toronto:20350913T210000 DTSTAMP:20260317T063314 CREATED:20140911T154817Z LAST-MODIFIED:20140911T154817Z UID:322-1442170800-2073330000@reachfoundation.life SUMMARY:Silent Auction DESCRIPTION:Maecenas sed diam eget risus varius blandit sit amet non magna. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Donec sed odio dui. Cras justo odio\, dapibus ac facilisis in\, egestas eget quam. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec sed odio dui. Curabitur blandit tempus porttitor. \nDonec sed odio dui. Maecenas faucibus mollis interdum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Nullam quis risus eget urna mollis ornare vel eu leo. URL:https://reachfoundation.life/event/silent-auction/ LOCATION:path END:VEVENT BEGIN:VEVENT DTSTART;TZID=America/Toronto:20150913T190000 DTEND;TZID=America/Toronto:20350913T210000 DTSTAMP:20260317T063314 CREATED:20140911T154817Z LAST-MODIFIED:20140911T154817Z UID:323-1442170800-2073330000@reachfoundation.life SUMMARY:Silent Auction DESCRIPTION:Maecenas sed diam eget risus varius blandit sit amet non magna. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Donec sed odio dui. Cras justo odio\, dapibus ac facilisis in\, egestas eget quam. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec sed odio dui. Curabitur blandit tempus porttitor. \nDonec sed odio dui. Maecenas faucibus mollis interdum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Nullam quis risus eget urna mollis ornare vel eu leo. URL:https://reachfoundation.life/event/silent-auction/ LOCATION:path END:VEVENT BEGIN:VEVENT DTSTART;TZID=America/Toronto:20150913T190000 DTEND;TZID=America/Toronto:20350913T210000 DTSTAMP:20260317T063314 CREATED:20140911T154817Z LAST-MODIFIED:20140911T154817Z UID:357-1442170800-2073330000@reachfoundation.life SUMMARY:Silent Auction DESCRIPTION:Maecenas sed diam eget risus varius blandit sit amet non magna. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Donec sed odio dui. Cras justo odio\, dapibus ac facilisis in\, egestas eget quam. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec sed odio dui. Curabitur blandit tempus porttitor. \nDonec sed odio dui. Maecenas faucibus mollis interdum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Nullam quis risus eget urna mollis ornare vel eu leo. URL:https://reachfoundation.life/event/silent-auction-2/ LOCATION:path END:VEVENT END:VCALENDAR