1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
<?php
namespace SIW\WooCommerce\Frontend;
use SIW\WooCommerce\Import\Product as Import_Product;
use SIW\WooCommerce\Frontend\Product_Tabs;
class Product {
public static function init() {
$self = new self();
Product_Tabs::init();
add_filter( 'woocommerce_is_purchasable', [ $self, 'set_product_is_purchasable'], 10, 2 );
add_filter( 'woocommerce_available_variation', [ $self, 'set_variation_description'] );
add_filter( 'woocommerce_sale_flash', [ $self, 'set_sales_flash_text' ] );
add_filter( 'woocommerce_product_get_attributes', [ $self, 'order_product_attributes'] );
add_filter( 'woocommerce_related_products_args', [ $self, 'set_related_products_number'], PHP_INT_MAX );
add_action( 'woocommerce_after_add_to_cart_form', [ $self, 'show_local_fee'] );
add_filter( 'woocommerce_reset_variations_link', '__return_false' );
add_filter( 'woocommerce_price_trim_zeros', '__return_true' );
add_filter( 'woocommerce_product_description_heading', '__return_false' );
add_filter( 'woocommerce_product_additional_information_heading', '__return_false' );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash', 10 );
add_filter( 'woocommerce_show_variation_price', '__return_true' );
}
public function set_product_is_purchasable( bool $is_purchasable, \WC_Product $product ) {
$is_purchasable = $product->is_visible();
$status = $product->get_status();
if ( ! $is_purchasable || Import_Product::REVIEW_STATUS == $status ) {
remove_action( 'woocommerce_single_variation', 'kt_woocommerce_single_variation', 10 );
remove_action( 'woocommerce_single_variation', 'kt_woocommerce_single_variation_add_to_cart_button', 20 );
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
add_filter( 'woocommerce_variation_is_visible', '__return_false');
}
return $is_purchasable;
}
public function set_variation_description( $variations ) {
if ( 'student' == $variations['attributes']['attribute_pa_tarief'] ) {
$variations['variation_description'] = __( 'Je komt in aanmerking voor het studententarief als je 17 jaar of jonger bent of als je een bewijs van inschrijving kunt laten zien.', 'siw' );
}
return $variations;
}
public function set_sales_flash_text() {
return '<span class="onsale">' . __( 'Korting', 'siw' ) . '</span>';
}
public function order_product_attributes( $attributes ) {
$order = [
'projectnaam',
'projectcode',
'pa_land',
'pa_soort-werk',
'startdatum',
'einddatum',
'aantal-vrijwilligers',
'leeftijd',
'lokale-bijdrage',
'pa_taal',
'pa_doelgroep',
];
uksort( $attributes, function( $key1, $key2 ) use ( $order ) {
return ( array_search( $key1, $order ) > array_search( $key2, $order ) );
} );
return $attributes;
}
public function set_related_products_number( $args ) {
$args['posts_per_page'] = 4;
return $args;
}
public function show_local_fee() {
global $product;
$participation_fee = $product->get_meta( 'participation_fee' );
$participation_fee_currency = $product->get_meta( 'participation_fee_currency' );
if ( ! empty( $participation_fee_currency ) && $participation_fee > 0 ) {
$currency = siw_get_currency( $participation_fee_currency );
$symbol = $participation_fee_currency;
if ( false !== $currency ) {
$symbol = $currency->get_symbol();
if ( 'EUR' != $participation_fee_currency ) {
$amount_in_euro = $currency->convert_to_euro( $participation_fee );
}
}
?>
<div class="local-fee">
<?php printf( esc_html__( 'Let op: naast het inschrijfgeld betaal je ter plekke nog een lokale bijdrage van %s %s.', 'siw' ), $symbol, $participation_fee );?>
<?php if ( isset( $amount_in_euro ) ):?>
<?php printf ( esc_html__( '(Ca. € %s)', 'siw' ), $amount_in_euro ); ?>
<?php endif ?>
</div>
<?php
}
}
}