- Renamed plugin to avoid WordPress.org naming conflict causing false update notifications - Added /downloads static route to serve plugin zip file - Updated all CSS classes from dutchie- to crawlsy- prefix - Added plugin zip to backend/public/downloads for hosting - Plugin available at: https://dispos.crawlsy.com/downloads/crawlsy-menus-1.3.0.zip 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
326 lines
12 KiB
PHP
326 lines
12 KiB
PHP
<?php
|
|
/**
|
|
* Elementor Single Product Widget
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class Crawlsy_Menus_Single_Product_Widget extends \Elementor\Widget_Base {
|
|
|
|
public function get_name() {
|
|
return 'crawlsy_single_product';
|
|
}
|
|
|
|
public function get_title() {
|
|
return __('Crawlsy Single Product', 'crawlsy-menus');
|
|
}
|
|
|
|
public function get_icon() {
|
|
return 'eicon-single-product';
|
|
}
|
|
|
|
public function get_categories() {
|
|
return ['general'];
|
|
}
|
|
|
|
protected function register_controls() {
|
|
|
|
// Content Section
|
|
$this->start_controls_section(
|
|
'content_section',
|
|
[
|
|
'label' => __('Content', 'crawlsy-menus'),
|
|
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'product_id',
|
|
[
|
|
'label' => __('Product ID', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::NUMBER,
|
|
'default' => '',
|
|
'description' => __('Enter the product ID to display', 'crawlsy-menus'),
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'layout',
|
|
[
|
|
'label' => __('Layout', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SELECT,
|
|
'default' => 'horizontal',
|
|
'options' => [
|
|
'horizontal' => __('Horizontal', 'crawlsy-menus'),
|
|
'vertical' => __('Vertical', 'crawlsy-menus'),
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->end_controls_section();
|
|
|
|
// Display Options Section
|
|
$this->start_controls_section(
|
|
'display_section',
|
|
[
|
|
'label' => __('Display Options', 'crawlsy-menus'),
|
|
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_image',
|
|
[
|
|
'label' => __('Show Image', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'crawlsy-menus'),
|
|
'label_off' => __('No', 'crawlsy-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_price',
|
|
[
|
|
'label' => __('Show Price', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'crawlsy-menus'),
|
|
'label_off' => __('No', 'crawlsy-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_description',
|
|
[
|
|
'label' => __('Show Description', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'crawlsy-menus'),
|
|
'label_off' => __('No', 'crawlsy-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_thc',
|
|
[
|
|
'label' => __('Show THC', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'crawlsy-menus'),
|
|
'label_off' => __('No', 'crawlsy-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_cbd',
|
|
[
|
|
'label' => __('Show CBD', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'crawlsy-menus'),
|
|
'label_off' => __('No', 'crawlsy-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_terpenes',
|
|
[
|
|
'label' => __('Show Terpenes', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'crawlsy-menus'),
|
|
'label_off' => __('No', 'crawlsy-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_effects',
|
|
[
|
|
'label' => __('Show Effects', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'crawlsy-menus'),
|
|
'label_off' => __('No', 'crawlsy-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_brand',
|
|
[
|
|
'label' => __('Show Brand', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'crawlsy-menus'),
|
|
'label_off' => __('No', 'crawlsy-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
|
|
$this->end_controls_section();
|
|
|
|
// Style Section
|
|
$this->start_controls_section(
|
|
'style_section',
|
|
[
|
|
'label' => __('Style', 'crawlsy-menus'),
|
|
'tab' => \Elementor\Controls_Manager::TAB_STYLE,
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'background_color',
|
|
[
|
|
'label' => __('Background Color', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#ffffff',
|
|
'selectors' => [
|
|
'{{WRAPPER}} .crawlsy-single-product' => 'background-color: {{VALUE}};',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'border_radius',
|
|
[
|
|
'label' => __('Border Radius', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::SLIDER,
|
|
'size_units' => ['px'],
|
|
'range' => [
|
|
'px' => [
|
|
'min' => 0,
|
|
'max' => 50,
|
|
],
|
|
],
|
|
'default' => [
|
|
'size' => 8,
|
|
],
|
|
'selectors' => [
|
|
'{{WRAPPER}} .crawlsy-single-product' => 'border-radius: {{SIZE}}{{UNIT}};',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'text_color',
|
|
[
|
|
'label' => __('Text Color', 'crawlsy-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#333333',
|
|
'selectors' => [
|
|
'{{WRAPPER}} .crawlsy-single-product' => 'color: {{VALUE}};',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->end_controls_section();
|
|
}
|
|
|
|
protected function render() {
|
|
$settings = $this->get_settings_for_display();
|
|
|
|
if (empty($settings['product_id'])) {
|
|
echo '<p>' . __('Please enter a product ID.', 'crawlsy-menus') . '</p>';
|
|
return;
|
|
}
|
|
|
|
$plugin = Crawlsy_Menus_Plugin::instance();
|
|
$product = $plugin->fetch_product($settings['product_id']);
|
|
|
|
if (!$product) {
|
|
echo '<p>' . __('Product not found.', 'crawlsy-menus') . '</p>';
|
|
return;
|
|
}
|
|
|
|
$layout = $settings['layout'];
|
|
?>
|
|
<div class="crawlsy-single-product crawlsy-layout-<?php echo esc_attr($layout); ?>">
|
|
<?php if ($settings['show_image'] === 'yes' && !empty($product['image_url_full'])): ?>
|
|
<div class="crawlsy-single-product-image">
|
|
<img src="<?php echo esc_url($product['image_url_full']); ?>"
|
|
alt="<?php echo esc_attr($product['name']); ?>" />
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="crawlsy-single-product-details">
|
|
<h2 class="crawlsy-single-product-title">
|
|
<?php echo esc_html($product['name']); ?>
|
|
</h2>
|
|
|
|
<?php if ($settings['show_brand'] === 'yes' && !empty($product['brand'])): ?>
|
|
<div class="crawlsy-single-product-brand">
|
|
<strong><?php _e('Brand:', 'crawlsy-menus'); ?></strong>
|
|
<?php echo esc_html($product['brand']); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($settings['show_description'] === 'yes' && !empty($product['description'])): ?>
|
|
<div class="crawlsy-single-product-description">
|
|
<?php echo wp_kses_post(nl2br($product['description'])); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="crawlsy-single-product-info">
|
|
<?php if ($settings['show_thc'] === 'yes' && !empty($product['metadata']['thc'])): ?>
|
|
<div class="crawlsy-info-item">
|
|
<strong><?php _e('THC:', 'crawlsy-menus'); ?></strong>
|
|
<span><?php echo esc_html($product['metadata']['thc']); ?></span>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($settings['show_cbd'] === 'yes' && !empty($product['metadata']['cbd'])): ?>
|
|
<div class="crawlsy-info-item">
|
|
<strong><?php _e('CBD:', 'crawlsy-menus'); ?></strong>
|
|
<span><?php echo esc_html($product['metadata']['cbd']); ?></span>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($settings['show_terpenes'] === 'yes' && !empty($product['metadata']['terpenes'])): ?>
|
|
<div class="crawlsy-info-item crawlsy-terpenes">
|
|
<strong><?php _e('Terpenes:', 'crawlsy-menus'); ?></strong>
|
|
<?php if (is_array($product['metadata']['terpenes'])): ?>
|
|
<span><?php echo esc_html(implode(', ', $product['metadata']['terpenes'])); ?></span>
|
|
<?php else: ?>
|
|
<span><?php echo esc_html($product['metadata']['terpenes']); ?></span>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($settings['show_effects'] === 'yes' && !empty($product['metadata']['effects'])): ?>
|
|
<div class="crawlsy-info-item crawlsy-effects">
|
|
<strong><?php _e('Effects:', 'crawlsy-menus'); ?></strong>
|
|
<?php if (is_array($product['metadata']['effects'])): ?>
|
|
<span><?php echo esc_html(implode(', ', $product['metadata']['effects'])); ?></span>
|
|
<?php else: ?>
|
|
<span><?php echo esc_html($product['metadata']['effects']); ?></span>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php if ($settings['show_price'] === 'yes' && isset($product['price'])): ?>
|
|
<div class="crawlsy-single-product-price">
|
|
$<?php echo number_format($product['price'], 2); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!$product['in_stock']): ?>
|
|
<div class="crawlsy-out-of-stock">
|
|
<?php _e('Out of Stock', 'crawlsy-menus'); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|