Esempio n. 1
0
 function global_get_post_id() {
     if (function_exists('is_woocommerce') && is_woocommerce() && is_shop()) {
         
         return wc_get_page_id('shop');
     } 
     else if (is_singular()) {
         global $post;
         
         return $post->ID;
     } 
     else if (is_home()) {
         
         $page_on_front = get_option('page_on_front');
         $show_on_front = get_option('show_on_front');
         
         if ($page_on_front == 'page' && !empty($page_on_front)) {
             global $post;
             return $post->ID;
         } 
         else {
             return false;
         }
     } 
     else {
         
         return false;
     }
 }
 /**
  * Load a template.
  *
  * Handles template usage so that we can use our own templates instead of the themes.
  *
  * Templates are in the 'templates' folder. woocommerce looks for theme
  * overrides in /theme/woocommerce/ by default
  *
  * For beginners, it also looks for a woocommerce.php template first. If the user adds
  * this to the theme (containing a woocommerce() inside) this will be used for all
  * woocommerce templates.
  *
  * @param mixed $template
  * @return string
  */
 public function template_loader($template)
 {
     $find = array('woocommerce.php');
     $file = '';
     if (is_single() && get_post_type() == 'product') {
         $file = 'single-product.php';
         $find[] = $file;
         $find[] = WC_TEMPLATE_PATH . $file;
     } elseif (is_tax('product_cat') || is_tax('product_tag')) {
         $term = get_queried_object();
         $file = 'taxonomy-' . $term->taxonomy . '.php';
         $find[] = 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
         $find[] = WC_TEMPLATE_PATH . 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
         $find[] = $file;
         $find[] = WC_TEMPLATE_PATH . $file;
     } elseif (is_post_type_archive('product') || is_page(wc_get_page_id('shop'))) {
         $file = 'archive-product.php';
         $find[] = $file;
         $find[] = WC_TEMPLATE_PATH . $file;
     }
     if ($file) {
         $template = locate_template($find);
         $status_options = get_option('woocommerce_status_options', array());
         if (!$template || !empty($status_options['template_debug_mode']) && current_user_can('manage_options')) {
             $template = WC()->plugin_path() . '/templates/' . $file;
         }
     }
     return $template;
 }
/**
 * Register a new meta box to the post or page edit screen, so that the user can add landing section
 * on a per-post or per-page basis.
 */
function cuttz_add_landing_sections_meta_box()
{
    if (!current_theme_supports('cuttz-landing-sections')) {
        return;
    }
    global $post;
    if (get_option('show_on_front') == 'page') {
        $posts_page_id = get_option('page_for_posts');
        if ($posts_page_id == $post->ID) {
            add_action('edit_form_after_title', 'cuttz_landing_section_posts_notice');
            return;
        }
    }
    if (in_array('woocommerce/woocommerce.php', get_option('active_plugins'))) {
        if ($post->ID == wc_get_page_id('shop')) {
            add_action('edit_form_after_title', 'cuttz_landing_section_shop_notice');
            return;
        }
    }
    $context = 'normal';
    $priority = 'high';
    foreach ((array) get_post_types(array('public' => true)) as $type) {
        if (post_type_supports($type, 'cuttz-landing-sections')) {
            add_meta_box('landing-sections', __('Cuttz Landing Sections', 'cuttz-framework'), 'cuttz_landing_sections_box', $type, $context, $priority);
        }
    }
}
function wc_update_200_permalinks()
{
    // Setup default permalinks if shop page is defined
    $permalinks = get_option('woocommerce_permalinks');
    $shop_page_id = wc_get_page_id('shop');
    if (empty($permalinks) && $shop_page_id > 0) {
        $base_slug = $shop_page_id > 0 && get_post($shop_page_id) ? get_page_uri($shop_page_id) : 'shop';
        $category_base = get_option('woocommerce_prepend_shop_page_to_urls') == "yes" ? trailingslashit($base_slug) : '';
        $category_slug = get_option('woocommerce_product_category_slug') ? get_option('woocommerce_product_category_slug') : _x('product-category', 'slug', 'woocommerce');
        $tag_slug = get_option('woocommerce_product_tag_slug') ? get_option('woocommerce_product_tag_slug') : _x('product-tag', 'slug', 'woocommerce');
        if ('yes' == get_option('woocommerce_prepend_shop_page_to_products')) {
            $product_base = trailingslashit($base_slug);
        } else {
            if (($product_slug = get_option('woocommerce_product_slug')) !== false && !empty($product_slug)) {
                $product_base = trailingslashit($product_slug);
            } else {
                $product_base = trailingslashit(_x('product', 'slug', 'woocommerce'));
            }
        }
        if (get_option('woocommerce_prepend_category_to_products') == 'yes') {
            $product_base .= trailingslashit('%product_cat%');
        }
        $permalinks = array('product_base' => untrailingslashit($product_base), 'category_base' => untrailingslashit($category_base . $category_slug), 'attribute_base' => untrailingslashit($category_base), 'tag_base' => untrailingslashit($category_base . $tag_slug));
        update_option('woocommerce_permalinks', $permalinks);
    }
}
 /**
  * Prevent caching on dynamic pages.
  *
  * @access public
  * @return void
  */
 public static function prevent_caching()
 {
     if (false === ($wc_page_uris = get_transient('woocommerce_cache_excluded_uris'))) {
         if (wc_get_page_id('cart') < 1 || wc_get_page_id('checkout') < 1 || wc_get_page_id('myaccount') < 1) {
             return;
         }
         $wc_page_uris = array();
         // Exclude querystring when using page ID
         $wc_page_uris[] = 'p=' . wc_get_page_id('cart');
         $wc_page_uris[] = 'p=' . wc_get_page_id('checkout');
         $wc_page_uris[] = 'p=' . wc_get_page_id('myaccount');
         // Exclude permalinks
         $cart_page = get_post(wc_get_page_id('cart'));
         $checkout_page = get_post(wc_get_page_id('checkout'));
         $account_page = get_post(wc_get_page_id('myaccount'));
         if (!is_null($cart_page)) {
             $wc_page_uris[] = '/' . $cart_page->post_name;
         }
         if (!is_null($checkout_page)) {
             $wc_page_uris[] = '/' . $checkout_page->post_name;
         }
         if (!is_null($account_page)) {
             $wc_page_uris[] = '/' . $account_page->post_name;
         }
         set_transient('woocommerce_cache_excluded_uris', $wc_page_uris);
     }
     if (is_array($wc_page_uris)) {
         foreach ($wc_page_uris as $uri) {
             if (strstr($_SERVER['REQUEST_URI'], $uri)) {
                 self::nocache();
                 break;
             }
         }
     }
 }
 /**
  * Handle a renewal url
  */
 public function renew_handler()
 {
     if (!empty($_GET['renew_licence']) && is_user_logged_in()) {
         global $wpdb;
         $licence_key = sanitize_text_field($_GET['renew_licence']);
         $licence = $wpdb->get_row($wpdb->prepare("\n\t\t\t\tSELECT * FROM {$wpdb->prefix}wp_plugin_licencing_licences\n\t\t\t\tWHERE licence_key = %s\n\t\t\t\tAND ( user_id = %d OR user_id = 0 )\n\t\t\t", $licence_key, get_current_user_id()));
         // Renewable?
         if (!$licence) {
             wc_add_notice(__('Invalid licence', 'wp-plugin-licencing'), 'error');
             return;
         }
         if (!$licence->date_expires || strtotime($licence->date_expires) > current_time('timestamp')) {
             wc_add_notice(__('This licence does not need to be renewed yet', 'wp-plugin-licencing'), 'notice');
             return;
         }
         // Purchasable?
         $product = get_product($licence->product_id);
         if (!$product->is_purchasable()) {
             wc_add_notice(__('This product can no longer be purchased', 'wp-plugin-licencing'), 'error');
             return;
         }
         // Add to cart
         WC()->cart->empty_cart();
         WC()->cart->add_to_cart($licence->product_id, 1, '', '', array('renewing_key' => $licence_key));
         // Message
         wc_add_notice(sprintf(__('The product has been added to your cart with a %d%% discount.', 'wp-plugin-licencing'), apply_filters('wp_plugin_licencing_renewal_discount_percent', 30)), 'success');
         // Redirect to checkout
         wp_redirect(get_permalink(wc_get_page_id('checkout')));
         exit;
     }
 }
 /**
  * Setup the cart for paying for a delayed initial payment for a subscription.
  *
  * @since 2.0
  */
 public function maybe_setup_cart()
 {
     global $wp;
     if (isset($_GET['pay_for_order']) && isset($_GET['key']) && isset($wp->query_vars['order-pay'])) {
         // Pay for existing order
         $order_key = $_GET['key'];
         $order_id = isset($wp->query_vars['order-pay']) ? $wp->query_vars['order-pay'] : absint($_GET['order_id']);
         $order = wc_get_order($wp->query_vars['order-pay']);
         if ($order->order_key == $order_key && $order->has_status(array('pending', 'failed')) && !wcs_order_contains_subscription($order, array('renewal', 'resubscribe'))) {
             $subscriptions = wcs_get_subscriptions_for_order($order, array('order_type' => 'parent'));
             if (get_current_user_id() !== $order->get_user_id()) {
                 wc_add_notice(__('That doesn\'t appear to be your order.', 'woocommerce-subscriptions'), 'error');
                 wp_safe_redirect(get_permalink(wc_get_page_id('myaccount')));
                 exit;
             } elseif (!empty($subscriptions)) {
                 // Setup cart with all the original order's line items
                 $this->setup_cart($order, array('order_id' => $order_id));
                 WC()->session->set('order_awaiting_payment', $order_id);
                 // Set cart hash for orders paid in WC >= 2.6
                 $this->set_cart_hash($order_id);
                 wp_safe_redirect(WC()->cart->get_checkout_url());
                 exit;
             }
         }
     }
 }
 /**
  * Get things started
  *
  * @since 1.0
  */
 public function __construct()
 {
     $this->set_expiration_time();
     $this->set_referral_var();
     /*
      * Referrals are tracked via javascript by default
      * This fails on sites that have jQuery errors, so a fallback method is available
      * With the fallback, the template_redirect action is used
      */
     if (!$this->use_fallback_method()) {
         add_action('wp_head', array($this, 'header_scripts'));
         add_action('wp_enqueue_scripts', array($this, 'load_scripts'));
         add_action('wp_ajax_nopriv_affwp_track_visit', array($this, 'track_visit'));
         add_action('wp_ajax_affwp_track_visit', array($this, 'track_visit'));
         add_action('wp_ajax_affwp_get_affiliate_id', array($this, 'ajax_get_affiliate_id_from_login'));
         add_action('wp_ajax_nopriv_affwp_get_affiliate_id', array($this, 'ajax_get_affiliate_id_from_login'));
     } else {
         add_action('template_redirect', array($this, 'fallback_track_visit'), -9999);
     }
     add_action('init', array($this, 'rewrites'));
     if (function_exists('wc_get_page_id') && get_option('page_on_front') == wc_get_page_id('shop')) {
         add_action('pre_get_posts', array($this, 'unset_query_arg'), -1);
     } else {
         add_action('pre_get_posts', array($this, 'unset_query_arg'), 999999);
     }
     add_action('redirect_canonical', array($this, 'prevent_canonical_redirect'), 0, 2);
     add_action('wp_ajax_nopriv_affwp_track_conversion', array($this, 'track_conversion'));
     add_action('wp_ajax_affwp_track_conversion', array($this, 'track_conversion'));
 }
 /**
  * Check If The Gateway Is Available For Use
  *
  * @return bool
  */
 public function is_available()
 {
     if (!empty($this->enable_for_methods)) {
         // Only apply if all packages are being shipped via local pickup
         $chosen_shipping_methods = array_unique(WC()->session->get('chosen_shipping_methods'));
         $check_method = false;
         if (is_page(wc_get_page_id('checkout')) && !empty($wp->query_vars['order-pay'])) {
             $order_id = absint($wp->query_vars['order-pay']);
             $order = new WC_Order($order_id);
             if ($order->shipping_method) {
                 $check_method = $order->shipping_method;
             }
         } elseif (empty($chosen_shipping_methods) || sizeof($chosen_shipping_methods) > 1) {
             $check_method = false;
         } elseif (sizeof($chosen_shipping_methods) == 1) {
             $check_method = $chosen_shipping_methods[0];
         }
         if (!$check_method) {
             return false;
         }
         $found = false;
         foreach ($this->enable_for_methods as $method_id) {
             if (strpos($check_method, $method_id) === 0) {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             return false;
         }
     }
     return parent::is_available();
 }
 public function login_url($url)
 {
     if (!class_exists('WooCommerce')) {
         return $url;
     }
     return get_permalink(wc_get_page_id('myaccount'));
 }
Esempio n. 11
0
 /**
  * Correct the shop page to display products from currrent language only.
  *
  * @param \WP $wp wordpress instance
  *
  * @return bool false if the current language is the same as default
  *              language or if the "pagename" var is empty
  */
 public function correctShopPage(\WP $wp)
 {
     global $polylang;
     $shopID = wc_get_page_id('shop');
     $shopOnFront = 'page' === get_option('show_on_front') && in_array(get_option('page_on_front'), PLL()->model->post->get_translations($shopID));
     $vars = array('pagename', 'page', 'name');
     foreach ($vars as $var) {
         if (isset($wp->query_vars[$var])) {
             $shopOnFront = false;
             break;
         }
     }
     if (!$shopOnFront) {
         if (!empty($wp->query_vars['pagename'])) {
             $shopPage = get_post($shopID);
             /* Explode by / for children page */
             $page = explode('/', $wp->query_vars['pagename']);
             if (isset($shopPage->post_name) && $shopPage->post_name == $page[count($page) - 1]) {
                 unset($wp->query_vars['page']);
                 unset($wp->query_vars['pagename']);
                 $wp->query_vars['post_type'] = 'product';
             }
         }
     } else {
         $wp->query_vars['post_type'] = 'product';
     }
 }
Esempio n. 12
0
 function create_the_view_all($post_type, $tag = '')
 {
     // Test for WooCommerce as well here...
     if ('product' == $post_type && class_exists('WooCommerce')) {
         $shop_page_id = wc_get_page_id('shop');
         $url = get_permalink($shop_page_id);
         $title = get_option('woocommerce_shop_page_title') ? get_option('woocommerce_shop_page_title') : get_the_title($shop_page_id);
         // No shop set up
         if (-1 == $shop_page_id) {
             $url = home_url('/');
             $title = 'Home';
         }
     } elseif ('post' == $post_type) {
         $blog_id = get_option('page_for_posts');
         $url = get_permalink($blog_id);
         $title = get_the_title($blog_id);
     } else {
         return;
         // Don't generate a link at all
     }
     // Deal with the tag
     $allowed_html = array('h1', 'h2', 'h3', 'h4', 'span', 'div', 'i', 'b', 'strong');
     if ($tag) {
         $tag_open = '<' . wp_kses($tag, $allowed_html) . '>';
         $tag_close = '</' . wp_kses($tag, $allowed_html) . '>';
     } else {
         $tag_open = '';
         $tag_close = '';
     }
     printf('<a href="%1$s" alt="%2$s" class="button">%3$s%4$s%5$s</a>', esc_url($url), esc_attr($title), $tag_open, __('View All', 'create'), $tag_close);
 }
/**
 * Returns a URL including required parameters for an authenticated user to renew a subscription
 *
 * @param  int | WC_Subscription $subscription Post ID of a 'shop_subscription' post, or instance of a WC_Subscription object
 * @return string
 * @since  2.0
 */
function wcs_get_users_resubscribe_link($subscription)
{
    $subscription_id = is_object($subscription) ? $subscription->id : $subscription;
    $resubscribe_link = add_query_arg(array('resubscribe' => $subscription_id), get_permalink(wc_get_page_id('myaccount')));
    $resubscribe_link = wp_nonce_url($resubscribe_link, $subscription_id);
    return apply_filters('wcs_users_resubscribe_link', $resubscribe_link, $subscription_id);
}
 /**
  * [is_available description]
  * @return boolean [description]
  */
 public function is_available()
 {
     $order = null;
     if (!$this->enable_for_virtual) {
         if (WC()->cart && !WC()->cart->needs_shipping()) {
             return false;
         }
         if (is_page(wc_get_page_id('checkout')) && 0 < get_query_var('order-pay')) {
             $order_id = absint(get_query_var('order-pay'));
             $order = wc_get_order($order_id);
             $needs_shipping = false;
             if (0 < sizeof($order->get_items())) {
                 foreach ($order->get_items() as $item) {
                     $_product = $order->get_product_from_item($item);
                     if ($_product->needs_shipping()) {
                         $needs_shipping = true;
                         break;
                     }
                 }
             }
             $needs_shipping = apply_filters('woocommerce_cart_needs_shipping', $needs_shipping);
             if ($needs_shipping) {
                 return false;
             }
         }
     }
     if (!empty($this->enable_for_methods)) {
         $chosen_shipping_methods_session = WC()->session->get('chosen_shipping_methods');
         if (isset($chosen_shipping_methods_session)) {
             $chosen_shipping_methods = array_unique($chosen_shipping_methods_session);
         } else {
             $chosen_shipping_methods = array();
         }
         $check_method = false;
         if (is_object($order)) {
             if ($order->shipping_method) {
                 $check_method = $order->shipping_method;
             }
         } elseif (empty($chosen_shipping_methods) || sizeof($chosen_shipping_methods) > 1) {
             $check_method = false;
         } elseif (sizeof($chosen_shipping_methods) == 1) {
             $check_method = $chosen_shipping_methods[0];
         }
         if (!$check_method) {
             return false;
         }
         $found = false;
         foreach ($this->enable_for_methods as $method_id) {
             if (strpos($check_method, $method_id) === 0) {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             return false;
         }
     }
     return parent::is_available();
 }
Esempio n. 15
0
 function members_only_price($price)
 {
     if (is_user_logged_in()) {
         return $price;
     } else {
         return '<p style="color:' . get_option('yith_hide_price_change_color') . '"><a style="display:inline; color:' . get_option('yith_hide_price_change_color') . '" href="' . get_permalink(function_exists('wc_get_page_id') ? wc_get_page_id('myaccount') : woocommerce_get_page_id('myaccount')) . '">' . get_option('yith_hide_price_link_text') . '</a> ' . get_option('yith_hide_price_text') . '</p>';
     }
 }
Esempio n. 16
0
function thb_breadcrumb()
{
    global $post, $wp_query;
    $id = $wp_query->get_queried_object_id();
    echo '<aside class="breadcrumb">';
    if (!is_front_page()) {
        echo '<a href="';
        echo home_url();
        echo '">' . __('Home', THB_THEME_NAME);
        echo "</a>";
    }
    if (is_singular('portfolio')) {
        $portfolio_main = get_post_meta($post->ID, 'portfolio_main', TRUE);
        if ($portfolio_main) {
            $portfolio_link = get_permalink($portfolio_main);
        } else {
            $portfolio_link = get_portfolio_page_link(get_the_ID());
        }
        echo '<span>/</span> <a href="' . $portfolio_link . '">' . __('Portfolio', THB_THEME_NAME) . '</a>';
        echo '<span>/</span>' . get_the_title();
    }
    if (is_home()) {
        echo '<span>/</span>' . __('Blog', THB_THEME_NAME);
    }
    if (is_page() && !is_front_page()) {
        $parents = array();
        $parent_id = $post->post_parent;
        while ($parent_id) {
            $page = get_page($parent_id);
            $parents[] = '<span>/</span><a href="' . get_permalink($page->ID) . '" title="' . get_the_title($page->ID) . '">' . get_the_title($page->ID) . '</a>';
            $parent_id = $page->post_parent;
        }
        $parents = array_reverse($parents);
        echo join(' ', $parents);
        echo '<span>/</span>' . get_the_title();
    }
    if (is_single() && !is_singular('portfolio')) {
        $categories = get_the_category();
        if ($categories) {
            foreach ($categories as $cat) {
                $cats[] = '<a href="' . get_category_link($cat->term_id) . '" title="' . $cat->name . '">' . $cat->name . '</a>';
            }
            echo '<span>/</span>' . join(', ', $cats);
        }
        echo '<span>/</span>' . ShortenText(get_the_title(), 40);
    }
    if (is_archive()) {
        if (class_exists('woocommerce') && is_woocommerce() && is_shop()) {
            echo '<span>/</span>' . get_the_title(wc_get_page_id('shop'));
        } else {
            echo '<span>/</span>' . thb_which_archive();
        }
    }
    if (is_search()) {
        echo '<span>/</span>' . thb_which_archive();
    }
    echo '</aside>';
}
 /**
  * Get the page permalink
  *
  * Backports wc_page_page_permalink to WC 2.3.3 and lower
  *
  * @link https://github.com/woothemes/woocommerce/pull/7438
  *
  * @since 4.0.0
  * @param string $page page - myaccount, edit_address, shop, cart, checkout, pay, view_order, terms
  * @return string
  */
 public static function wc_get_page_permalink($page)
 {
     if (self::is_wc_version_gt('2.3.3')) {
         return wc_get_page_permalink($page);
     } else {
         $permalink = get_permalink(wc_get_page_id($page));
         return apply_filters('woocommerce_get_' . $page . '_page_permalink', $permalink);
     }
 }
Esempio n. 18
0
 /**
  * Test get_remove_url
  *
  * @since 2.3
  */
 public function test_get_remove_url()
 {
     // Get the cart page id
     $cart_page_id = wc_get_page_id('cart');
     // Test cart item key
     $cart_item_key = 'test';
     // Do the check
     $this->assertEquals(apply_filters('woocommerce_get_remove_url', $cart_page_id ? wp_nonce_url(add_query_arg('remove_item', $cart_item_key, get_permalink($cart_page_id)), 'woocommerce-cart') : ''), WC()->cart->get_remove_url($cart_item_key));
 }
 /**
  * Get the page name/id for a WC page
  * @param  string $wc_page
  * @return array
  */
 private static function get_page_uris($wc_page)
 {
     $wc_page_uris = array();
     if (($page_id = wc_get_page_id($wc_page)) && $page_id > 0 && ($page = get_post($page_id))) {
         $wc_page_uris[] = 'p=' . $page_id;
         $wc_page_uris[] = '/' . $page->post_name;
     }
     return $wc_page_uris;
 }
Esempio n. 20
0
 function lpd_product_archive_description()
 {
     $shop_page = get_post(wc_get_page_id('shop'));
     if ($shop_page) {
         $description = apply_filters('the_content', $shop_page->post_content);
         if ($description) {
             echo '<div class="page-description">' . $description . '</div>';
         }
     }
 }
Esempio n. 21
0
 public function init_legal_page_metabox($post)
 {
     $legal_pages = array(wc_get_page_id('revocation'), wc_get_page_id('data_security'), wc_get_page_id('imprint'), wc_get_page_id('terms'));
     if (!in_array($post->ID, $legal_pages)) {
         echo '<style type="text/css">#wc-gzd-legal-page-email-content { display: none; }</style>';
         return;
     }
     echo '<p class="small">' . __('Add content which will be replacing default page content within emails.', 'woocommerce-germanized') . '</p>';
     wp_editor(htmlspecialchars_decode(get_post_meta($post->ID, '_legal_text', true)), 'legal_page_email_content', array('textarea_name' => '_legal_text', 'textarea_rows' => 5));
 }
Esempio n. 22
0
 /**
  * Allow developers to extend and overwrite the default actions we add
  *
  * @since 1.7.8
  */
 public function init()
 {
     add_action('init', array($this, 'maybe_flush_rewrites'), 999998);
     add_action('init', array($this, 'rewrites'), 999999);
     if (function_exists('wc_get_page_id') && get_option('page_on_front') == wc_get_page_id('shop')) {
         add_action('pre_get_posts', array($this, 'unset_query_arg'), -1);
     } else {
         add_action('pre_get_posts', array($this, 'unset_query_arg'), 999999);
     }
     add_action('redirect_canonical', array($this, 'prevent_canonical_redirect'), 0, 2);
 }
 /**
  * Get current page URL for layered nav items.
  *
  * @return string
  */
 protected function get_page_base_url()
 {
     if (defined('SHOP_IS_ON_FRONT')) {
         $link = home_url();
     } elseif (is_post_type_archive('product') || is_page(wc_get_page_id('shop'))) {
         $link = get_post_type_archive_link('product');
     } elseif (is_product_category()) {
         $link = get_term_link(get_query_var('product_cat'), 'product_cat');
     } elseif (is_product_tag()) {
         $link = get_term_link(get_query_var('product_tag'), 'product_tag');
     } else {
         $queried_object = get_queried_object();
         $link = get_term_link($queried_object->slug, $queried_object->taxonomy);
     }
     // Min/Max
     if (isset($_GET['min_price'])) {
         $link = add_query_arg('min_price', wc_clean($_GET['min_price']), $link);
     }
     if (isset($_GET['max_price'])) {
         $link = add_query_arg('max_price', wc_clean($_GET['max_price']), $link);
     }
     // Orderby
     if (isset($_GET['orderby'])) {
         $link = add_query_arg('orderby', wc_clean($_GET['orderby']), $link);
     }
     /**
      * Search Arg.
      * To support quote characters, first they are decoded from &quot; entities, then URL encoded.
      */
     if (get_search_query()) {
         $link = add_query_arg('s', rawurlencode(htmlspecialchars_decode(get_search_query())), $link);
     }
     // Post Type Arg
     if (isset($_GET['post_type'])) {
         $link = add_query_arg('post_type', wc_clean($_GET['post_type']), $link);
     }
     // Min Rating Arg
     if (isset($_GET['min_rating'])) {
         $link = add_query_arg('min_rating', wc_clean($_GET['min_rating']), $link);
     }
     // All current filters
     if ($_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes()) {
         foreach ($_chosen_attributes as $name => $data) {
             $filter_name = sanitize_title(str_replace('pa_', '', $name));
             if (!empty($data['terms'])) {
                 $link = add_query_arg('filter_' . $filter_name, implode(',', $data['terms']), $link);
             }
             if ('or' == $data['query_type']) {
                 $link = add_query_arg('query_type_' . $filter_name, 'or', $link);
             }
         }
     }
     return $link;
 }
Esempio n. 24
0
 /**
  * Get the return url (thank you page)
  *
  * @access public
  * @param string $order (default: '')
  * @return string
  */
 public function get_return_url($order = '')
 {
     if ($order) {
         $return_url = $order->get_checkout_order_received_url();
     } else {
         $return_url = wc_get_endpoint_url('order-received', '', get_permalink(wc_get_page_id('checkout')));
     }
     if (is_ssl() || get_option('woocommerce_force_ssl_checkout') == 'yes') {
         $return_url = str_replace('http:', 'https:', $return_url);
     }
     return apply_filters('woocommerce_get_return_url', $return_url);
 }
Esempio n. 25
0
 /**
  * Prevent any user who cannot 'edit_posts' (subscribers, customers etc) from accessing admin
  */
 public function prevent_admin_access()
 {
     $prevent_access = false;
     if ('yes' == get_option('woocommerce_lock_down_admin') && !is_ajax() && !(current_user_can('edit_posts') || current_user_can('manage_woocommerce')) && basename($_SERVER["SCRIPT_FILENAME"]) !== 'admin-post.php') {
         $prevent_access = true;
     }
     $prevent_access = apply_filters('woocommerce_prevent_admin_access', $prevent_access);
     if ($prevent_access) {
         wp_safe_redirect(get_permalink(wc_get_page_id('myaccount')));
         exit;
     }
 }
Esempio n. 26
0
function mk_woocommerce_product_archive_description()
{
    if (is_post_type_archive('product')) {
        $shop_page = get_post(wc_get_page_id('shop'));
        if ($shop_page) {
            $description = apply_filters('the_content', $shop_page->post_content);
            if ($description) {
                echo $description;
            }
        }
    }
}
    /**
     * Check if current frontend user owns subscription and return it
     * 
     * @access public
     * @param int $subscription_id
     * @return object|bool
     */
    public static function get_subscription($subscription_id)
    {
        $user_id = get_current_user_id();
        $subscription = Subscriptio_Subscription::get_by_id($subscription_id);

        if (!$user_id || !$subscription || $subscription->user_id != $user_id) {
            echo '<div class="woocommerce-error">' . __('Invalid subscription.', 'subscriptio') . ' <a href="' . get_permalink(wc_get_page_id('myaccount')).'" class="wc-forward">'. __('My Account', 'subscriptio') .'</a>' . '</div>';
            return false;
        }

        return $subscription;
    }
Esempio n. 28
0
 /**
  * Show a shop page description on product archives.
  *
  * @subpackage	Archives
  */
 function woocommerce_product_archive_description()
 {
     if (is_post_type_archive('product') && 0 === absint(get_query_var('paged'))) {
         $shop_page = get_post(wc_get_page_id('shop'));
         if ($shop_page) {
             $description = wc_format_content($shop_page->post_content);
             if ($description) {
                 echo '<div class="page-description">' . $description . '</div>';
             }
         }
     }
 }
 /**
  * Get current page URL for layered nav items.
  * @return string
  */
 protected function get_page_base_url()
 {
     if (defined('SHOP_IS_ON_FRONT')) {
         $link = home_url();
     } elseif (is_post_type_archive('product') || is_page(wc_get_page_id('shop'))) {
         $link = get_post_type_archive_link('product');
     } else {
         $link = get_term_link(get_query_var('term'), get_query_var('taxonomy'));
     }
     // Min/Max
     if (isset($_GET['min_price'])) {
         $link = add_query_arg('min_price', wc_clean($_GET['min_price']), $link);
     }
     if (isset($_GET['max_price'])) {
         $link = add_query_arg('max_price', wc_clean($_GET['max_price']), $link);
     }
     // Orderby
     if (isset($_GET['orderby'])) {
         $link = add_query_arg('orderby', wc_clean($_GET['orderby']), $link);
     }
     // Search Arg
     if (get_search_query()) {
         $link = add_query_arg('s', get_search_query(), $link);
     }
     // Post Type Arg
     if (isset($_GET['post_type'])) {
         $link = add_query_arg('post_type', wc_clean($_GET['post_type']), $link);
     }
     return $link;
 }
Esempio n. 30
-1
 /**
  * Load a template.
  *
  * Handles template usage so that we can use our own templates instead of the themes.
  *
  * Templates are in the 'templates' folder. woocommerce looks for theme
  * overrides in /theme/woocommerce/ by default
  *
  * For beginners, it also looks for a woocommerce.php template first. If the user adds
  * this to the theme (containing a woocommerce() inside) this will be used for all
  * woocommerce templates.
  *
  * @param mixed $template
  * @return string
  */
 public static function template_loader($template)
 {
     $find = array('woocommerce.php');
     $file = '';
     if (is_single() && get_post_type() == 'product') {
         $file = 'single-product.php';
         $find[] = $file;
         $find[] = WC()->template_path() . $file;
     } elseif (is_product_taxonomy()) {
         $term = get_queried_object();
         if (is_tax('product_cat') || is_tax('product_tag')) {
             $file = 'taxonomy-' . $term->taxonomy . '.php';
         } else {
             $file = 'archive-product.php';
         }
         $find[] = 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
         $find[] = WC()->template_path() . 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
         $find[] = 'taxonomy-' . $term->taxonomy . '.php';
         $find[] = WC()->template_path() . 'taxonomy-' . $term->taxonomy . '.php';
         $find[] = $file;
         $find[] = WC()->template_path() . $file;
     } elseif (is_post_type_archive('product') || is_page(wc_get_page_id('shop'))) {
         $file = 'archive-product.php';
         $find[] = $file;
         $find[] = WC()->template_path() . $file;
     }
     if ($file) {
         $template = locate_template(array_unique($find));
         if (!$template || WC_TEMPLATE_DEBUG_MODE) {
             $template = WC()->plugin_path() . '/templates/' . $file;
         }
     }
     return $template;
 }