| 1 |
<?php |
| 2 |
|
| 3 |
namespace MakeCommerce\Shipping; |
| 4 |
|
| 5 |
/** |
| 6 |
* All functionality that has to do with shipping and products |
| 7 |
* |
| 8 |
* @since 3.0.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
class Product extends \MakeCommerce\Shipping { |
| 12 |
|
| 13 |
private $loader; |
| 14 |
|
| 15 |
/** |
| 16 |
* Constructs Label class, defines loader and hooks |
| 17 |
* |
| 18 |
* @since 3.0.0 |
| 19 |
*/ |
| 20 |
public function __construct( \MakeCommerce\Loader $loader ) { |
| 21 |
|
| 22 |
$this->loader = $loader; |
| 23 |
|
| 24 |
$this->define_hooks(); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Define all wordpress hooks needed for printing stuff and creating labels |
| 29 |
* |
| 30 |
* @since 3.0.0 |
| 31 |
*/ |
| 32 |
public function define_hooks() { |
| 33 |
|
| 34 |
$this->loader->add_filter( 'woocommerce_product_options_shipping', $this, 'option_fields' ); |
| 35 |
$this->loader->add_filter( 'woocommerce_process_product_meta', $this, 'save' ); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Save product fields |
| 40 |
* |
| 41 |
* @since 3.0.0 |
| 42 |
*/ |
| 43 |
public function save( $post_id ) { |
| 44 |
|
| 45 |
$no_parcel_machine = isset($_POST['_no_parcel_machine']) ? 'yes' : 'no'; |
| 46 |
update_post_meta($post_id, '_no_parcel_machine', $no_parcel_machine); |
| 47 |
|
| 48 |
$no_shipping_cost = isset($_POST['_no_shipping_cost']) ? 'yes' : 'no'; |
| 49 |
update_post_meta($post_id, '_no_shipping_cost', $no_shipping_cost); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Add options to product page |
| 54 |
* |
| 55 |
* @since 3.0.0 |
| 56 |
*/ |
| 57 |
public function option_fields( $fields ) { |
| 58 |
|
| 59 |
echo '<div class="options_group">'; |
| 60 |
|
| 61 |
woocommerce_wp_checkbox( |
| 62 |
array( |
| 63 |
'id' => '_no_parcel_machine', |
| 64 |
'label' => __('Does not fit parcel machine', 'wc_makecommerce_domain'), |
| 65 |
'description' => __('When this is checked, parcel machine shipping option is not available for a cart with this product', 'wc_makecommerce_domain') |
| 66 |
) |
| 67 |
); |
| 68 |
|
| 69 |
woocommerce_wp_checkbox( |
| 70 |
array( |
| 71 |
'id' => '_no_shipping_cost', |
| 72 |
'label' => __('Free parcel machine', 'wc_makecommerce_domain'), |
| 73 |
'description' => __('When this is checked, parcel machine is free for this product', 'wc_makecommerce_domain') |
| 74 |
) |
| 75 |
); |
| 76 |
|
| 77 |
echo '</div>'; |
| 78 |
} |
| 79 |
} |