|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* WooCommerce Discontinued Products Template Functions |
|
4
|
|
|
* |
|
5
|
|
|
* @package woocommerce |
|
6
|
|
|
* @since 1.0.0 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
if ( ! function_exists( 'dp_is_discontinued' ) ) { |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Is discontiued. |
|
13
|
|
|
* Check if product is discontinued. |
|
14
|
|
|
* |
|
15
|
|
|
* @since 1.0.0 |
|
16
|
|
|
* @param int|null $product_id Optional. ID of the product to check. |
|
17
|
|
|
*/ |
|
18
|
|
|
function dp_is_discontinued( $product_id = null ) { |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
global $post; |
|
|
|
|
|
|
21
|
|
|
if ( $post || $product_id !== null ) { |
|
22
|
|
|
$product_id = $product_id !== null ? $product_id : $post->ID; |
|
|
|
|
|
|
23
|
|
|
$is_discontinued = get_post_meta( $product_id, '_is_discontinued', true ); |
|
24
|
|
|
return $is_discontinued === 'yes'; |
|
25
|
|
|
} |
|
26
|
|
|
return false; |
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
if ( ! function_exists( 'dp_alt_products' ) ) { |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Alternative Products. |
|
34
|
|
|
* Output buttons to alternative products. |
|
35
|
|
|
* |
|
36
|
|
|
* @since 1.0.0 |
|
37
|
|
|
*/ |
|
38
|
|
|
function dp_alt_products() { |
|
39
|
|
|
|
|
40
|
|
|
global $post; |
|
|
|
|
|
|
41
|
|
|
$alt_products = get_post_meta( $post->ID, '_alt_products', true ); |
|
42
|
|
|
$alt_products = is_array( $alt_products ) ? $alt_products : array(); |
|
43
|
|
|
$notice = dp_alt_products_notice( $post->ID, empty( $alt_products ) ); |
|
44
|
|
|
?> |
|
45
|
|
|
<h4><?php echo esc_html( $notice ); ?></h4> |
|
46
|
|
|
<?php |
|
47
|
|
|
foreach ( $alt_products as $alt_product ) { |
|
48
|
|
|
?> |
|
49
|
|
|
<a href="<?php echo esc_url( get_permalink( $alt_product ) ); ?>" class="button"><?php echo get_the_title( $alt_product ); ?></a> |
|
50
|
|
|
<?php |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
if ( ! function_exists( 'dp_alt_products_notice' ) ) { |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Alternative Products Notice. |
|
59
|
|
|
* Determin notice output for discontinued products based on settings. |
|
60
|
|
|
* |
|
61
|
|
|
* @since 1.1.0 |
|
62
|
|
|
* @param int $product_id ID of the product to check. |
|
63
|
|
|
* @param boolean $no_alt true or false if there are no alternative products. |
|
64
|
|
|
*/ |
|
65
|
|
|
function dp_alt_products_notice( $product_id, $no_alt ) { |
|
66
|
|
|
|
|
67
|
|
|
$prod_text_option = get_post_meta( $product_id, '_discontinued_product_text', true ); |
|
68
|
|
|
$prod_alt_option = get_post_meta( $product_id, '_alt_product_text', true ); |
|
|
|
|
|
|
69
|
|
|
$text_option = get_option( 'dc_discontinued_text' ); |
|
|
|
|
|
|
70
|
|
|
$alt_option = get_option( 'dc_alt_text' ); |
|
|
|
|
|
|
71
|
|
|
$text = dp_alt_products_text( $prod_text_option, $text_option, _( 'This product has been discontinued.' ) ); |
|
|
|
|
|
|
72
|
|
|
$alt = dp_alt_products_text( $prod_alt_option, $alt_option, _( 'You may be interested in:' ) ); |
|
|
|
|
|
|
73
|
|
|
$notice = $no_alt ? $text : $text . ' ' . $alt; |
|
|
|
|
|
|
74
|
|
|
return $notice; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if ( ! function_exists( 'dp_alt_products_text' ) ) { |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Alternative Products Text. |
|
82
|
|
|
* Determin text for discontinued products based on settings. |
|
83
|
|
|
* |
|
84
|
|
|
* @since 1.1.0 |
|
85
|
|
|
* @param string $product_text product meta text. |
|
86
|
|
|
* @param string $option_text options settings text. |
|
87
|
|
|
* @param string $default_text default text. |
|
88
|
|
|
*/ |
|
89
|
|
|
function dp_alt_products_text( $product_text, $option_text, $default_text ) { |
|
90
|
|
|
|
|
91
|
|
|
$text = $product_text ? $product_text : ( $option_text ? $option_text : $default_text ); |
|
92
|
|
|
return $text; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.