Skip to content

Commit

Permalink
Merge pull request #27 from skyverge/2.5.1-dev
Browse files Browse the repository at this point in the history
Version 2.5.1
  • Loading branch information
bekarice authored Aug 23, 2017
2 parents c4645dc + 6c00ee9 commit 4a5d8a1
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 72 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "woocommerce-customizer",
"version": "2.4.0",
"version": "2.5.1-dev",
"author": "SkyVerge",
"homepage": "http://www.skyverge.com",
"repository": {
Expand All @@ -19,7 +19,7 @@
"grunt-contrib-copy": "~0.5.0",
"grunt-newer": "~0.7.0",
"grunt-notify": "~0.3.0",
"grunt-wp-deploy": "~1.1.0",
"grunt-wp-deploy": "~1.2.1",
"grunt-wp-i18n": "~0.4.5",
"load-grunt-tasks": "~0.6.0",
"time-grunt": "~0.4.0",
Expand Down
9 changes: 6 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Contributors: SkyVerge, maxrice, tamarazuk, chasewiseman, nekojira, beka.rice
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&[email protected]&item_name=Donation+for+WooCommerce+Customizer
Tags: woocommerce, woocommerce shop, woocommerce filters, woocommerce text
Requires at least: 4.1
Tested up to: 4.7.4
Tested up to: 4.8
WC requires at least: 2.5.5
WC tested up to: 3.0.7
Stable tag: 2.5.0
WC tested up to: 3.1.1
Stable tag: 2.5.1-dev
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -73,6 +73,9 @@ Of course! Please fork the [GitHub](https://github.com/skyverge/woocommerce-cust

== Changelog ==

= 2.5.1-dev =
* Tweak - Hook customizations later to be more aggressive about using WC Customizer values rather than filters from other plugins or themes

= 2.5.0 =
* Feature - Added sales badge text customization

Expand Down
125 changes: 58 additions & 67 deletions woocommerce-customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Customize WooCommerce without code! Easily change add to cart button text and more.
* Author: SkyVerge
* Author URI: http://www.skyverge.com
* Version: 2.5.0
* Version: 2.5.1-dev
* Text Domain: woocommerce-customizer
* Domain Path: /i18n/languages/
*
Expand All @@ -25,57 +25,17 @@

// Check if WooCommerce is active
if ( ! WC_Customizer::is_woocommerce_active() ) {
add_action( 'admin_notices', 'wc_customizer_render_wc_inactive_notice' );
add_action( 'admin_notices', array( 'WC_Customizer', 'render_wc_inactive_notice' ) );
return;
}

// WC version check
if ( version_compare( get_option( 'woocommerce_db_version' ), '2.5.5', '<' ) ) {
add_action( 'admin_notices', 'wc_customizer_render_outdated_wc_version_notice' );
add_action( 'admin_notices', array( 'WC_Customizer', 'render_outdated_wc_version_notice' ) );
return;
}


/**
* Renders a notice when WooCommerce version is outdated
*
* @since 2.3.1
*/
function wc_customizer_render_outdated_wc_version_notice() {

$message = sprintf(
/* translators: %1$s and %2$s are <strong> tags. %3$s and %4$s are <a> tags */
__( '%1$sWooCommerce Customizer is inactive.%2$s This version requires WooCommerce 2.5.5 or newer. Please %3$supdate WooCommerce to version 2.5.5 or newer%4$s', 'woocommerce-customizer' ),
'<strong>',
'</strong>',
'<a href="' . admin_url( 'plugins.php' ) . '">',
'&nbsp;&raquo;</a>'
);

printf( '<div class="error"><p>%s</p></div>', $message );
}


/**
* Renders a notice when WooCommerce version is outdated
*
* @since 2.3.1
*/
function wc_customizer_render_wc_inactive_notice() {

$message = sprintf(
/* translators: %1$s and %2$s are <strong> tags. %3$s and %4$s are <a> tags */
__( '%1$sWooCommerce Customizer is inactive%2$s as it requires WooCommerce. Please %3$sactivate WooCommerce version 2.5.5 or newer%4$s', 'woocommerce-customizer' ),
'<strong>',
'</strong>',
'<a href="' . admin_url( 'plugins.php' ) . '">',
'&nbsp;&raquo;</a>'
);

printf( '<div class="error"><p>%s</p></div>', $message );
}


/**
* # WooCommerce Customizer Main Plugin Class
*
Expand Down Expand Up @@ -111,7 +71,7 @@ class WC_Customizer {


/** plugin version number */
const VERSION = '2.5.0';
const VERSION = '2.5.1-dev';

/** @var \WC_Customizer single instance of this plugin */
protected static $instance;
Expand Down Expand Up @@ -208,18 +168,18 @@ public function load_customizations() {

if ( $filter_name == 'single_add_to_cart_text' ) {

add_filter( 'woocommerce_product_single_add_to_cart_text', array( $this, 'customize_single_add_to_cart_text' ) );
add_filter( 'woocommerce_product_single_add_to_cart_text', array( $this, 'customize_single_add_to_cart_text' ), 50 );

} else {

add_filter( 'woocommerce_product_add_to_cart_text', array( $this, 'customize_add_to_cart_text' ), 10, 2 );
add_filter( 'woocommerce_product_add_to_cart_text', array( $this, 'customize_add_to_cart_text' ), 50, 2 );
}

} elseif ( 'woocommerce_placeholder_img_src' === $filter_name ) {

// only filter placeholder images on the frontend
if ( ! is_admin() ) {
add_filter( $filter_name, array( $this, 'customize' ) );
add_filter( $filter_name, array( $this, 'customize' ), 50 );
}

} elseif ( 'loop_sale_flash_text' === $filter_name || 'single_sale_flash_text' === $filter_name ) {
Expand All @@ -228,7 +188,7 @@ public function load_customizations() {

} else {

add_filter( $filter_name, array( $this, 'customize' ) );
add_filter( $filter_name, array( $this, 'customize' ), 50 );
}
}
}
Expand Down Expand Up @@ -265,6 +225,47 @@ public static function is_woocommerce_active() {
}


/**
* Renders a notice when WooCommerce version is outdated
*
* @since 2.3.1
*/
public static function render_wc_inactive_notice() {

$message = sprintf(
/* translators: %1$s and %2$s are <strong> tags. %3$s and %4$s are <a> tags */
__( '%1$sWooCommerce Customizer is inactive%2$s as it requires WooCommerce. Please %3$sactivate WooCommerce version 2.5.5 or newer%4$s', 'woocommerce-customizer' ),
'<strong>',
'</strong>',
'<a href="' . admin_url( 'plugins.php' ) . '">',
'&nbsp;&raquo;</a>'
);

printf( '<div class="error"><p>%s</p></div>', $message );
}


/**
* Renders a notice when WooCommerce version is outdated
*
* @since 2.3.1
*/
public static function render_outdated_wc_version_notice() {

$message = sprintf(
/* translators: Placeholders: %1$s <strong>, %2$s - </strong>, %3$s and %5$s - <a> tags, %4$s - </a> */
__( '%1$sWooCommerce Customizer is inactive.%2$s This plugin requires WooCommerce 2.5.5 or newer. Please %3$supdate WooCommerce%4$s or %5$srun the WooCommerce database upgrade%4$s.', 'woocommerce-customizer' ),
'<strong>',
'</strong>',
'<a href="' . admin_url( 'plugins.php' ) . '">',
'</a>',
'<a href="' . admin_url( 'plugins.php?do_update_woocommerce=true' ) . '">'
);

printf( '<div class="error"><p>%s</p></div>', $message );
}


/** Frontend methods ******************************************************/


Expand Down Expand Up @@ -359,36 +360,26 @@ public function customize_add_to_cart_text( $text, $product ) {
*/
public function customize_woocommerce_sale_flash( $html, $_, $product ) {

$text = '';

if ( is_product() && isset( $this->filters['single_sale_flash_text'] ) ) {

$text = $this->filters['single_sale_flash_text'];

// only get sales percentages when we should be replacing text
// check "false" specifically since the position could be 0
if ( false !== strpos( $text, '{percent}' ) ) {

$percent = $this->get_sale_percentage( $product );
$text = str_replace( '{percent}', "{$percent}%", $text );
}

$html = "<span class='onsale'>{$text}</span>";

} elseif ( ! is_product() && isset( $this->filters['loop_sale_flash_text'] ) ) {

$text = $this->filters['loop_sale_flash_text'];
}

// only check for sales percentages when we should be replacing text
// check "false" specifically since the position could be 0
if ( false !== strpos( $text, '{percent}' ) ) {

$percent = $this->get_sale_percentage( $product );
$text = str_replace( '{percent}', "{$percent}%", $text );
}
// only get sales percentages when we should be replacing text
// check "false" specifically since the position could be 0
if ( false !== strpos( $text, '{percent}' ) ) {

$html = "<span class='onsale'>{$text}</span>";
$percent = $this->get_sale_percentage( $product );
$text = str_replace( '{percent}', "{$percent}%", $text );
}

return $html;
return ! empty( $text ) ? "<span class='onsale'>{$text}</span>" : $html;
}


Expand Down

0 comments on commit 4a5d8a1

Please sign in to comment.