public static function cc_product($args, $content) { $product_loader = CC_Admin_Setting::get_option('cart66_main_settings', 'product_loader'); $subdomain = CC_Cloud_Subdomain::load_from_wp(); $id = cc_rand_string(12, 'lower'); $product_form = ''; $client_loading = 'true'; $product_id = isset($args['id']) ? $args['id'] : false; $product_sku = isset($args['sku']) ? $args['sku'] : false; $display_quantity = isset($args['quantity']) ? $args['quantity'] : 'true'; $display_price = isset($args['price']) ? $args['price'] : 'true'; $display_mode = isset($args['display']) ? $args['display'] : ''; CC_Log::write("cc_product shortcode: subdomain: {$subdomain} :: product loader: {$product_loader}"); if ($product_loader == 'server' || preg_match('/(?i)msie [2-9]/', $_SERVER['HTTP_USER_AGENT'])) { // if IE<=9 do not use the ajax product form method $product_form = self::cc_product_via_api($args, $content); $client_loading = 'false'; } $out = "<div class=\"cc_product_wrapper\"><div id='" . $id . "' class='cc_product' data-subdomain='{$subdomain}' data-sku='{$product_sku}' data-quantity='{$display_quantity}' data-price='{$display_price}' data-display='{$display_mode}' data-client='{$client_loading}'>{$product_form}</div></div>"; // Enqueue client side script when needed $product_loader = CC_Admin_Setting::get_option('cart66_main_settings', 'product_loader'); if ('client' == $product_loader) { CC_Log::write('Force load client add to cart scripts'); cc_enqueue_cart66_wordpress_js(true); } return $out; }
/** * Attempt to load subdomain from WordPress database. If not available, load from the cloud. */ public static function load_from_wp() { $subdomain = null; if (isset(self::$subdomain)) { $subdomain = self::$subdomain; } else { $subdomain = CC_Admin_Setting::get_option('cart66_main_settings', 'subdomain'); } return $subdomain; }
function product_sort_order($wp_query) { if (!is_admin() && $wp_query->is_main_query()) { $sort_method = CC_Admin_Setting::get_option('cart66_post_type_settings', 'sort_method'); $is_product_query = false; // Is this a query for cart66 products? if (isset($wp_query->query['post_type']) && 'cc_product' == $wp_query->query['post_type']) { $is_product_query = true; CC_Log::write('The post type is cc_product'); } elseif (isset($wp_query->query['product-category'])) { $is_product_query = true; CC_Log::write('The product category is set'); } if ($wp_query->is_main_query() && $is_product_query) { // $wp_query->set('orderby', 'title'); switch ($sort_method) { case 'price_desc': $wp_query->set('orderby', 'meta_value_num'); $wp_query->set('meta_key', '_cc_product_price'); $wp_query->set('order', 'DESC'); break; case 'price_asc': $wp_query->set('orderby', 'meta_value_num'); $wp_query->set('meta_key', '_cc_product_price'); $wp_query->set('order', 'ASC'); break; case 'name_desc': $wp_query->set('orderby', 'title'); $wp_query->set('order', 'DESC'); break; case 'name_asc': $wp_query->set('orderby', 'title'); $wp_query->set('order', 'ASC'); break; case 'menu_order': $wp_query->set('orderby', 'menu_order'); $wp_query->set('order', 'ASC'); break; } // Set the number of products to show per page $max_products = CC_Admin_Setting::get_option('cart66_post_type_settings', 'max_products'); if (!(is_numeric($max_products) && $max_products >= 2)) { $max_products = 4; } $wp_query->set('posts_per_page', $max_products); } } // End of is_main_query }
/** * Return the title for the page depending on the context of the request * * @return string */ function cc_page_title() { if (is_search()) { $page_title = sprintf(__('Search Results: “%s”', 'cart66'), get_search_query()); if (get_query_var('paged')) { $page_title .= sprintf(__(' – Page %s', 'cart66'), get_query_var('paged')); } } elseif (is_tax()) { $page_title = single_term_title("", false); } else { $page_title = CC_Admin_Setting::get_option('cart66_post_type_settings', 'shop_name', 'Shop'); } $page_title = apply_filters('cc_page_title', $page_title); return $page_title; }
public function render($args) { $skip_types = array('cc_product', 'revision', 'attachment'); $this->new_option('products', 'cc_product', true, false); $post_types = get_post_types(); foreach ($post_types as $type) { if (!in_array($type, $skip_types)) { $this->new_option($type, $type, false); } } $selected_post_types = CC_Admin_Setting::get_option('cart66_main_settings', 'product_post_types'); $selected_post_types[] = 'cc_product'; $this->set_selected($selected_post_types); parent::render($args); }
public function sign_in($send_return_url = false) { $url = self::$cloud->subdomain_url() . 'sign_in'; $send_return_url = is_bool($send_return_url) ? $send_return_url : false; // A non-boolean may be passed in from CC_Library if ($send_return_url) { $return_url = ''; $page_id = CC_Admin_Setting::get_option('cart66_members_notifications', 'member_home'); if ($page_id > 0) { $return_url = get_permalink($page_id); $encoded_return_url = empty($return_url) ? '' : '?return_url=' . urlencode($return_url); $url .= $encoded_return_url; } } return $url; }
public function register_actions() { // Initialize core classes add_action('init', array($this, 'init'), 0); // Check for incoming cart66 tasks and actions add_action('wp_loaded', 'cc_task_dispatcher'); add_action('parse_query', 'cc_route_handler'); // Register custom post type for products add_action('init', 'cc_register_product_post_type'); // Add actions to process all add to cart requests via ajax add_action('wp_enqueue_scripts', 'cc_enqueue_ajax_add_to_cart'); add_action('wp_enqueue_scripts', 'cc_enqueue_cart66_wordpress_js'); add_action('wp_enqueue_scripts', 'cc_enqueue_cart66_styles'); add_action('wp_enqueue_scripts', 'cc_enqueue_featherlight'); add_action('wp_ajax_cc_ajax_add_to_cart', array('CC_Cart', 'ajax_add_to_cart')); add_action('wp_ajax_nopriv_cc_ajax_add_to_cart', array('CC_Cart', 'ajax_add_to_cart')); // Check if request is a page slurp add_action('template_redirect', array('CC_Page_Slurp', 'check_slurp')); // Preload cart summary if available, otherwise drop unknown carts add_action('template_redirect', array('CC_Cart', 'preload_summary')); // Register sidebar widget add_action('widgets_init', function () { register_widget('CC_Cart_Widget'); }); // Write custom css to the head add_action('wp_head', 'cc_custom_css'); // Refresh notices after theme switch add_action('after_switch_theme', 'cc_reset_theme_notices'); // Register activation and deactivation hooks register_activation_hook(__FILE__, 'cc_activate'); register_deactivation_hook(__FILE__, 'cc_deactivate'); // Add filter for hiding slurp page from navigation add_filter('get_pages', 'CC_Page_Slurp::hide_page_slurp'); if ('yes' == CC_Admin_Setting::get_option('cart66_post_type_settings', 'product_templates')) { // Add filter for rendering post type page templates add_filter('template_include', 'cc_template_include'); // Only register category widget when using product post type templates add_action('widgets_init', create_function('', 'return register_widget("CC_Category_Widget");')); } else { // Add filter for to attempt to get products showing as pages rather than posts add_filter('template_include', 'cc_use_page_template'); // Add filter for rendering product partial with gallery and order form add_filter('the_content', 'cc_filter_product_single'); } }
/** * Register custom post type and taxonomy for cart66 products */ function cc_register_product_post_type() { // If the post type should not be used, just stop $use_post_type = CC_Admin_Setting::get_option('cart66_post_type_settings', 'use_product_post_type'); if ('disable' == $use_post_type) { CC_Log::write('Cart66 post type is disabled - not registering custom post type or taxonomies'); return; } register_taxonomy('product-category', 'cc_product', array('label' => __('Product Categories'), 'name' => 'Product Categories', 'singular_name' => 'Product Category', 'rewrite' => array('slug' => 'product-category'), 'hierarchical' => true)); $labels = array('name' => 'Products', 'singular_name' => 'Product', 'add_new' => 'Add New', 'add_new_item' => 'Add New Product', 'edit_item' => 'Edit Product', 'new_item' => 'New Product', 'all_items' => 'All Products', 'view_item' => 'View Product', 'search_items' => 'Search Products', 'not_found' => 'No products found', 'not_found_in_trash' => 'No products found in trash', 'parent_item_colon' => '', 'menu_name' => 'Products'); $show = false; if ('no' != $use_post_type) { $show = true; } else { // CC_Log::write( 'Hiding Cart66 Product Custom Post Types' ); } $post_type_attrs = array('labels' => $labels, 'public' => $show, 'publicly_queryable' => true, 'show_ui' => $show, 'show_in_menu' => $show, 'show_in_nav_menus' => $show, 'query_var' => true, 'rewrite' => array('slug' => 'products'), 'capability_type' => 'post', 'taxonomies' => array('product-category'), 'has_archive' => true, 'hierarchical' => false, 'menu_position' => null, 'menu_icon' => 'dashicons-tag', 'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'comments', 'revisions')); /* Register the post type. */ // CC_Log::write( 'Registering Cart66 product post type: cc_product' ); register_post_type('cc_product', $post_type_attrs); }
</p> <?php } else { ?> <p class="cc-product-price"> <span class="cc-product-price-label"><?php echo CC_Admin_Setting::get_option('cart66_labels', 'price'); ?> </span> <span class="cc-product-price-amount"><?php echo get_post_meta($post->ID, '_cc_product_formatted_price', true); ?> </span> </p> <?php } ?> <a class="cc-button-primary" href="<?php echo get_permalink(); ?> " title="<?php the_title(); ?> "><?php echo CC_Admin_Setting::get_option('cart66_labels', 'view'); ?> </a> </li>
public static function ajax_add_to_cart() { $response = self::add_to_cart($_POST); if (is_wp_error($response)) { $response_code = $response->get_error_code(); } else { $response_code = $response['response']['code']; } // CC_Log::write('Ajax response code: ' . print_r($response_code, TRUE)); if ($response_code == '500') { header('HTTP/1.1 500: SERVER ERROR', true, 500); } elseif ($response_code != '201') { header('HTTP/1.1 422: UNPROCESSABLE ENTITY', true, 422); echo $response['body']; } else { $redirect_type = CC_Admin_Setting::get_option('cart66_main_settings', 'add_to_cart_redirect_type'); $out = array('task' => 'redirect'); $url = new CC_Cloud_URL(); if ('view_cart' == $redirect_type) { $out['url'] = $url->view_cart(); } elseif ('checkout' == $redirect_type) { $out['url'] = $url->checkout(); } else { $product_info = json_decode($response['body'], true); $product_name = $product_info['product_name']; $message = $product_name . ' added to cart'; $view_cart = '<a href="' . $url->view_cart() . '" class="btn btn-small pull-right ajax_view_cart_button" rel="nofollow">View Cart <i class="icon-arrow-right" /></a>'; $out = array('task' => 'stay', 'response' => $message . $view_cart); } CC_Log::write('Ajax created :: response code 201 :: output: ' . print_r($out, TRUE)); header('HTTP/1.1 201 Created', true, 201); header('Content-Type: application/json'); echo json_encode($out); do_action('cc_after_add_to_cart'); } die; }
/** * Implementation of authenticated API calls from cc-request-handler.php */ function cc_auth_verify_secret_key($key) { $secret_key = CC_Admin_Setting::get_option('cart66_main_settings', 'secret_key'); return $secret_key == $key; }
function cc_theme_support_notice() { $product_templates = CC_Admin_Setting::get_option('cart66_post_type_settings', 'product_templates'); if (!current_theme_supports('cart66') && 'yes' == $product_templates && CC_Admin_Notifications::show('cart66_theme_support')) { ?> <div class="error"> <p> <?php _e('The active theme does not declare support for the Cart66 product post type. ', 'cart66'); ?> <br /> <?php _e('Here are some times for <a href="http://help.cart66.com/article/330-fixing-layout-problems">fixing layout problems</a> and making <a href="http://help.cart66.com/article/329-custom-page-layouts">custom page layouts</a>.', 'cart66'); ?> <br/> <a href="<?php echo add_query_arg('cc-task', 'dismiss_notification_theme_support'); ?> " class="button" style="margin-top: 10px;" ><?php _e('Dismiss this message', 'cart66'); ?> </a> </p> </div> <?php } }
<?php // Allow a defined constant to override the database setting for debugging if (!defined('CC_DEBUG')) { $debug = CC_Admin_Setting::get_option('cart66_main_settings', 'debug'); CC_Log::write('Debug value: ' . $debug); $debug = 'on' == $debug ? true : false; define('CC_DEBUG', $debug); } class CC_Log { public static $log_file; public static function init() { if (!isset(self::$log_file)) { self::$log_file = CC_PATH . 'log.txt'; } } public static function write($data) { if (defined('CC_DEBUG') && CC_DEBUG) { self::init(); $backtrace = debug_backtrace(); $file = $backtrace[0]['file']; $line = $backtrace[0]['line']; $date = current_time('m/d/Y g:i:s A') . ' ' . get_option('timezone_string'); $out = "========== {$date} ==========\nFile: {$file}" . ' :: Line: ' . $line . "\n{$data}"; if (is_writable(CC_PATH)) { file_put_contents(self::$log_file, $out . "\n\n", FILE_APPEND); } }