59 lines
1.4 KiB
PHP
59 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Actions;
|
|
|
|
use ofc\RadAction;
|
|
|
|
class WooCommerceBeforeAddToCartButtonAction extends RadAction
|
|
{
|
|
/**
|
|
* @var string WordPress hook to attach to.
|
|
*/
|
|
protected string $hookName = 'woocommerce_before_add_to_cart_button';
|
|
|
|
/**
|
|
* @var int Hook priority.
|
|
*/
|
|
protected int $priority = 10;
|
|
|
|
/**
|
|
* Your action callback.
|
|
*/
|
|
public function callback()
|
|
{
|
|
global $product;
|
|
|
|
if (!$product || !is_a($product, 'WC_Product')) {
|
|
return;
|
|
}
|
|
|
|
$attributes = $product->get_attributes();
|
|
$rentalRates = [];
|
|
|
|
foreach ($attributes as $attribute) {
|
|
$name = $attribute->get_name();
|
|
if (!is_array($attribute->get_options())) {
|
|
continue;
|
|
}
|
|
|
|
if (count($attribute->get_options()) < 1) {
|
|
continue;
|
|
}
|
|
|
|
if ($name === "Rental Rate (Daily)") {
|
|
$rentalRates["daily"] = $attribute->get_options()[0];
|
|
}
|
|
if ($name === "Rental Rate (Weekly)") {
|
|
$rentalRates["weekly"] = $attribute->get_options()[0];
|
|
}
|
|
if ($name === "Rental Rate (Monthly)") {
|
|
$rentalRates["monthly"] = $attribute->get_options()[0];
|
|
}
|
|
}
|
|
|
|
if (count($rentalRates)) {
|
|
echo site()->render("product_rental_rates", $rentalRates);
|
|
}
|
|
}
|
|
}
|