| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- if (!defined('WPINC')) {
- die;
- }
- class Studiou_WC_FPP_Shortcode {
- public function __construct() {
- add_shortcode('studiou_free_photo_product', array($this, 'render_shortcode'));
- }
- public function render_shortcode($atts) {
- $atts = shortcode_atts(array(
- 'id' => 0,
- ), $atts, 'studiou_free_photo_product');
- $product_id = absint($atts['id']);
- if (!$product_id) {
- return '<p class="studiou-fpp-error">' . esc_html__('Product ID is required.', 'studiou-wc-free-photo-product') . '</p>';
- }
- $product = wc_get_product($product_id);
- if (!$product) {
- return '<p class="studiou-fpp-error">' . esc_html__('Product not found.', 'studiou-wc-free-photo-product') . '</p>';
- }
- if (!Studiou_WC_FPP_Product::is_fpp_product($product_id)) {
- return '<p class="studiou-fpp-error">' . esc_html__('This product does not support photo upload.', 'studiou-wc-free-photo-product') . '</p>';
- }
- if (!$product->is_type('variable')) {
- return '<p class="studiou-fpp-error">' . esc_html__('This product must be a variable product.', 'studiou-wc-free-photo-product') . '</p>';
- }
- // Enqueue assets
- wp_enqueue_style('studiou-wcfpp-frontend');
- wp_enqueue_script('studiou-wcfpp-frontend');
- // Get variations
- $variations = $product->get_available_variations();
- $attributes = $product->get_variation_attributes();
- $max_file_size = Studiou_WC_FPP_Product::get_product_max_file_size($product_id);
- ob_start();
- include STUDIOU_WCFPP_PLUGIN_DIR . 'views/frontend-product.php';
- return ob_get_clean();
- }
- }
|