|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
/** |
|
3
|
|
|
* Product settings |
|
4
|
|
|
* |
|
5
|
|
|
* @package PrintCenter\Admin\Settings\Product |
|
6
|
|
|
* @since 1.0.0 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
// Exit if accessed directly |
|
11
|
|
|
if( ! defined( 'ABSPATH' ) ) { |
|
12
|
|
|
exit; |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Add SSI fields to product details box |
|
18
|
|
|
* |
|
19
|
|
|
* @since 1.0.0 |
|
20
|
|
|
* @return void |
|
21
|
|
|
*/ |
|
22
|
|
|
function printcenter_ssi_data_fields() { |
|
23
|
|
|
global $woocommerce, $post; |
|
|
|
|
|
|
24
|
|
|
?> |
|
25
|
|
|
<div class="options_group"> |
|
26
|
|
|
<?php |
|
27
|
|
|
woocommerce_wp_select( array( |
|
28
|
|
|
'id' => '_ssi_sku', |
|
29
|
|
|
'label' => __( 'Shirt', 'printcenter' ), |
|
30
|
|
|
'description' => __( 'Choose the type of shirt this design is available for.', 'printcenter' ), |
|
31
|
|
|
'options' => printcenter_get_shirts(), |
|
32
|
|
|
) ); |
|
33
|
|
|
?> |
|
34
|
|
|
</div> |
|
35
|
|
|
<div class="options_group"> |
|
36
|
|
|
<?php |
|
37
|
|
|
woocommerce_wp_select( array( |
|
38
|
|
|
'id' => '_ssi_location', |
|
39
|
|
|
'label' => __( 'Design Location', 'printcenter' ), |
|
40
|
|
|
'description' => __( 'Select where on the shirt the design will be printed.', 'printcenter' ), |
|
41
|
|
|
'options' => array( |
|
42
|
|
|
'front' => __( 'Full Front', 'printcenter' ), |
|
43
|
|
|
'back' => __( 'Full Back', 'printcenter' ), |
|
44
|
|
|
'left' => __( 'Left Chest', 'printcenter' ) |
|
45
|
|
|
), |
|
46
|
|
|
) ); |
|
47
|
|
|
woocommerce_wp_select( array( |
|
48
|
|
|
'id' => '_ssi_sizing', |
|
49
|
|
|
'label' => __( 'Design Category', 'printcenter' ), |
|
50
|
|
|
'description' => __( 'Specify design size.', 'printcenter' ), |
|
51
|
|
|
'options' => array( |
|
52
|
|
|
'SM' => __( 'Small', 'printcenter' ), |
|
53
|
|
|
'REG' => __( 'Regular', 'printcenter' ), |
|
54
|
|
|
'LG' => __( 'Large', 'printcenter' ) |
|
55
|
|
|
), |
|
56
|
|
|
) ); |
|
57
|
|
|
woocommerce_wp_text_input( array( |
|
58
|
|
|
'id' => '_ssi_art', |
|
59
|
|
|
'label' => __( 'Design Art', 'printcenter' ), |
|
60
|
|
|
'description' => __( 'Enter the URL to the printable design file.', 'printcenter' ), |
|
61
|
|
|
) ); |
|
62
|
|
|
?> |
|
63
|
|
|
</div> |
|
64
|
|
|
<?php |
|
65
|
|
|
} |
|
66
|
|
|
add_action( 'woocommerce_product_options_general_product_data', 'printcenter_ssi_data_fields' ); |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Add our custom fields to the product meta save process |
|
71
|
|
|
* |
|
72
|
|
|
* @since 1.0.0 |
|
73
|
|
|
* @param int $post_id The ID of the product we are editing |
|
74
|
|
|
* @param object $post The WordPress post object for this product |
|
75
|
|
|
* @return void |
|
76
|
|
|
*/ |
|
77
|
|
|
function printcenter_ssi_data_save( $post_id, $post ) { |
|
|
|
|
|
|
78
|
|
|
$art = isset( $_POST['_ssi_art'] ) ? $_POST['_ssi_art'] : ''; |
|
79
|
|
|
|
|
80
|
|
|
update_post_meta( $post_id, '_ssi_sku', $_POST['_ssi_sku'] ); |
|
81
|
|
|
update_post_meta( $post_id, '_ssi_location', $_POST['_ssi_location'] ); |
|
82
|
|
|
update_post_meta( $post_id, '_ssi_sizing', $_POST['_ssi_sizing'] ); |
|
83
|
|
|
update_post_meta( $post_id, '_ssi_art', $art ); |
|
84
|
|
|
} |
|
85
|
|
|
add_action( 'woocommerce_process_product_meta', 'printcenter_ssi_data_save', 10, 2 ); |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.