diff --git a/client-mu-plugins/goodbids/README.md b/client-mu-plugins/goodbids/README.md index c32597e92..78f547192 100644 --- a/client-mu-plugins/goodbids/README.md +++ b/client-mu-plugins/goodbids/README.md @@ -35,7 +35,10 @@ Renders an admin field based on the given field array. The `$prefix` and `$data` ### Auction Functions `goodbids()->auctions->get_post_type()` -Returns the auction post type slug. +Returns the Auction post type slug. + +`goodbids()->auctions->get_auction_id()` +Returns the current Auction ID (if valid). `goodbids()->auctions->get_setting( string $setting, int $auction_id )` Returns a setting value for an auction. If `$auction_id` is not provided, the current post ID will be used. diff --git a/client-mu-plugins/goodbids/acf-json/group_6570c1fa76181.json b/client-mu-plugins/goodbids/acf-json/group_6570c1fa76181.json index 805ec0b56..a0184fce7 100644 --- a/client-mu-plugins/goodbids/acf-json/group_6570c1fa76181.json +++ b/client-mu-plugins/goodbids/acf-json/group_6570c1fa76181.json @@ -43,7 +43,7 @@ "taxonomy": [ "product_cat:rewards" ], - "return_format": "object", + "return_format": "id", "multiple": 0, "allow_null": 0, "bidirectional": 0, @@ -179,6 +179,6 @@ "active": true, "description": "", "show_in_rest": 0, - "modified": 1702493167, + "modified": 1702659886, "private": true } diff --git a/client-mu-plugins/goodbids/blocks/bid-now/block.json b/client-mu-plugins/goodbids/blocks/bid-now/block.json new file mode 100644 index 000000000..9d44c7053 --- /dev/null +++ b/client-mu-plugins/goodbids/blocks/bid-now/block.json @@ -0,0 +1,14 @@ +{ + "name": "bid-now", + "title": "Bid Now Button", + "description": "Displays a bid now button for the current Auction.", + "icon": "money-alt", + "category": "goodbids", + "keywords": ["bid", "purchase", "donate", "button", "submit", "cart"], + "acf": { + "mode": "preview" + }, + "supports": { + "jsx": false + } +} diff --git a/client-mu-plugins/goodbids/blocks/bid-now/render.php b/client-mu-plugins/goodbids/blocks/bid-now/render.php new file mode 100644 index 000000000..8b8b57292 --- /dev/null +++ b/client-mu-plugins/goodbids/blocks/bid-now/render.php @@ -0,0 +1,28 @@ +auctions->get_post_type() !== get_post_type() ) : + // Bail early if we're not inside an Auction post type. + return; +endif; + +$auction_id = goodbids()->auctions->get_auction_id(); +$bid_product_id = goodbids()->auctions->get_bid_product_id( $auction_id ); + +$classes = 'wp-block-buttons is-vertical is-content-justification-center is-layout-flex wp-block-buttons-is-layout-flex'; +$button_url = $bid_product_id && ! is_admin() ? add_query_arg( 'add-to-cart', $bid_product_id, wc_get_checkout_url() ) : '#'; +?> +
> +
+ + + +
+
diff --git a/client-mu-plugins/goodbids/src/classes/Auctions/Auctions.php b/client-mu-plugins/goodbids/src/classes/Auctions/Auctions.php index fb5185c2e..417b00856 100644 --- a/client-mu-plugins/goodbids/src/classes/Auctions/Auctions.php +++ b/client-mu-plugins/goodbids/src/classes/Auctions/Auctions.php @@ -127,6 +127,7 @@ function () { 'capability_type' => 'page', 'show_in_rest' => true, 'rest_base' => self::SINGULAR_SLUG, + 'template' => $this->get_template(), ]; register_post_type( self::POST_TYPE, $args ); @@ -134,6 +135,24 @@ function () { ); } + /** + * Get the default template for Auctions. + * + * @since 1.0.0 + * + * @return array + */ + private function get_template(): array { + return apply_filters( + 'woocommerce_auction_default_template', + [ + [ + 'acf/bid-now', + ], + ] + ); + } + /** * Initialize Rewards Category * @@ -161,6 +180,27 @@ public function get_post_type(): string { return self::POST_TYPE; } + /** + * Returns the current Auction post ID. + * + * @since 1.0.0 + * + * @return ?int + */ + public function get_auction_id() : ?int { + $auction_id = is_singular( $this->get_post_type() ) ? get_queried_object_id() : get_the_ID(); + + if ( ! $auction_id && is_admin() && ! empty( $_GET['post'] ) ) { + $auction_id = intval( sanitize_text_field( $_GET['post'] ) ); + } + + if ( $this->get_post_type() !== get_post_type( $auction_id ) ) { + return null; + } + + return $auction_id; + } + /** * Retrieve the Rewards category ID, or create it if it doesn't exist. * diff --git a/client-mu-plugins/goodbids/src/classes/Plugins/ACF/Blocks.php b/client-mu-plugins/goodbids/src/classes/Plugins/ACF/Blocks.php index 69ab66740..8e342482e 100644 --- a/client-mu-plugins/goodbids/src/classes/Plugins/ACF/Blocks.php +++ b/client-mu-plugins/goodbids/src/classes/Plugins/ACF/Blocks.php @@ -76,7 +76,7 @@ public function get_all_blocks() : array { $group = glob( trailingslashit( $location ) . '**/block.json' ); foreach ( $group as $block_path ) { - $block = json_decode( wpcom_vip_file_get_contents( $block_path ), true ); + $block = json_decode( file_get_contents( $block_path ), true ); // phpcs:ignore // Add path as a property. $block['path'] = dirname( $block_path ); diff --git a/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce.php b/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce.php index 5b1abe30e..c881f8e8d 100644 --- a/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce.php +++ b/client-mu-plugins/goodbids/src/classes/Plugins/WooCommerce.php @@ -271,4 +271,5 @@ function () { 2 ); } + }