Dump coupon helper and add new functions. Closes #3353.
This commit is contained in:
parent
c9f051dee2
commit
d0b6483037
|
@ -85,7 +85,7 @@ function woocommerce_custom_coupon_columns( $column ) {
|
|||
|
||||
break;
|
||||
case "type" :
|
||||
echo esc_html( $woocommerce->get_helper( 'coupon' )->get_coupon_discount_type( get_post_meta( $post->ID, 'discount_type', true ) ) );
|
||||
echo esc_html( wc_get_coupon_type( get_post_meta( $post->ID, 'discount_type', true ) ) );
|
||||
break;
|
||||
case "amount" :
|
||||
echo esc_html( get_post_meta( $post->ID, 'coupon_amount', true ) );
|
||||
|
@ -148,7 +148,7 @@ function woocommerce_restrict_manage_coupons() {
|
|||
<select name='coupon_type' id='dropdown_shop_coupon_type'>
|
||||
<option value=""><?php _e( 'Show all types', 'woocommerce' ); ?></option>
|
||||
<?php
|
||||
$types = $woocommerce->get_helper( 'coupon' )->get_coupon_discount_types();
|
||||
$types = wc_get_coupon_types();
|
||||
|
||||
foreach ( $types as $name => $type ) {
|
||||
echo '<option value="' . esc_attr( $name ) . '"';
|
||||
|
|
|
@ -39,7 +39,7 @@ function woocommerce_coupon_data_meta_box( $post ) {
|
|||
echo '</div><div class="options_group">';
|
||||
|
||||
// Type
|
||||
woocommerce_wp_select( array( 'id' => 'discount_type', 'label' => __( 'Discount type', 'woocommerce' ), 'options' => $woocommerce->get_helper( 'coupon' )->get_coupon_discount_types() ) );
|
||||
woocommerce_wp_select( array( 'id' => 'discount_type', 'label' => __( 'Discount type', 'woocommerce' ), 'options' => wc_get_coupon_types() ) );
|
||||
|
||||
// Amount
|
||||
woocommerce_wp_text_input( array( 'id' => 'coupon_amount', 'label' => __( 'Coupon amount', 'woocommerce' ), 'placeholder' => '0.00', 'description' => __( 'Value of the coupon.', 'woocommerce' ), 'type' => 'number', 'custom_attributes' => array(
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
class WC_Coupon_Helper extends WC_Helper {
|
||||
/**
|
||||
* Get coupon types.
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function get_coupon_discount_types() {
|
||||
if ( ! isset( $this->coupon_discount_types ) ) {
|
||||
$this->coupon_discount_types = apply_filters( 'woocommerce_coupon_discount_types', array(
|
||||
'fixed_cart' => __( 'Cart Discount', 'woocommerce' ),
|
||||
'percent' => __( 'Cart % Discount', 'woocommerce' ),
|
||||
'fixed_product' => __( 'Product Discount', 'woocommerce' ),
|
||||
'percent_product' => __( 'Product % Discount', 'woocommerce' )
|
||||
) );
|
||||
}
|
||||
return $this->coupon_discount_types;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a coupon type's name.
|
||||
*
|
||||
* @access public
|
||||
* @param string $type (default: '')
|
||||
* @return string
|
||||
*/
|
||||
public function get_coupon_discount_type( $type = '' ) {
|
||||
$types = (array) $this->get_coupon_discount_types();
|
||||
if ( isset( $types[$type] ) ) return $types[$type];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* WooCommerce Coupons Functions
|
||||
*
|
||||
* Functions for coupon specific things.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category Core
|
||||
* @package WooCommerce/Functions
|
||||
* @version 2.1.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
/**
|
||||
* Get coupon types.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function wc_get_coupon_types() {
|
||||
return (array) apply_filters( 'woocommerce_coupon_discount_types', array(
|
||||
'fixed_cart' => __( 'Cart Discount', 'woocommerce' ),
|
||||
'percent' => __( 'Cart % Discount', 'woocommerce' ),
|
||||
'fixed_product' => __( 'Product Discount', 'woocommerce' ),
|
||||
'percent_product' => __( 'Product % Discount', 'woocommerce' )
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a coupon type's name.
|
||||
*
|
||||
* @param string $type (default: '')
|
||||
* @return string
|
||||
*/
|
||||
function wc_get_coupon_type( $type = '' ) {
|
||||
$types = wc_get_coupon_types();
|
||||
if ( isset( $types[ $type ] ) )
|
||||
return $types[ $type ];
|
||||
}
|
|
@ -315,6 +315,7 @@ final class WooCommerce {
|
|||
|
||||
include( 'includes/wc-deprecated-functions.php' );
|
||||
include( 'includes/wc-message-functions.php' );
|
||||
include( 'includes/wc-coupon-functions.php' );
|
||||
|
||||
|
||||
|
||||
|
@ -990,16 +991,16 @@ final class WooCommerce {
|
|||
return $this->get_helper( 'attribute' )->get_attribute_taxonomy_names();
|
||||
}
|
||||
|
||||
// Deprecated 2.1.0 Access via the WC_Coupon_Helper helper
|
||||
// Deprecated 2.1.0
|
||||
public function get_coupon_discount_types() {
|
||||
_deprecated_function( 'Woocommerce->get_coupon_discount_types', '2.1', 'WC_Coupon_Helper->get_coupon_discount_types' );
|
||||
return $this->get_helper( 'coupon' )->get_coupon_discount_types();
|
||||
_deprecated_function( 'Woocommerce->get_coupon_discount_types', '2.1', 'wc_get_coupon_types' );
|
||||
return wc_get_coupon_types();
|
||||
}
|
||||
|
||||
// Deprecated 2.1.0 Access via the WC_Coupon_Helper helper
|
||||
// Deprecated 2.1.0
|
||||
public function get_coupon_discount_type( $type = '' ) {
|
||||
_deprecated_function( 'Woocommerce->get_coupon_discount_type', '2.1', 'WC_Coupon_Helper->get_coupon_discount_type' );
|
||||
return $this->get_helper( 'coupon' )->get_coupon_discount_type( $type );
|
||||
_deprecated_function( 'Woocommerce->get_coupon_discount_type', '2.1', 'wc_get_coupon_type' );
|
||||
return wc_get_coupon_type( $type );
|
||||
}
|
||||
|
||||
// Deprecated 2.1.0 Access via the WC_Post_Class_Helper helper
|
||||
|
|
Loading…
Reference in New Issue